From 4e44aa701cc894f498feda1cf874a2213385efa5 Mon Sep 17 00:00:00 2001 From: paulfantom Date: Sat, 13 Jan 2018 21:54:19 +0100 Subject: [PATCH 1/5] add more OSes --- .travis/images.sh | 7 +++++++ meta/main.yml | 8 ++++++++ molecule.yml | 35 +++++++++++++++++++++++++++++------ tests/playbook.yml | 44 +++----------------------------------------- 4 files changed, 47 insertions(+), 47 deletions(-) create mode 100755 .travis/images.sh diff --git a/.travis/images.sh b/.travis/images.sh new file mode 100755 index 0000000..20395a7 --- /dev/null +++ b/.travis/images.sh @@ -0,0 +1,7 @@ +#!/bin/bash +for i in ubuntu-molecule:16.04 debian-molecule:9 debian-molecule:8 centos-molecule:7 fedora-molecule:27 +do + docker pull paulfantom/$i & +done + +wait diff --git a/meta/main.yml b/meta/main.yml index 876f938..23e6994 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -11,12 +11,20 @@ galaxy_info: - name: Debian versions: - jessie + - stretch - name: EL versions: - 7 + - name: Fedora + versions: + - 27 galaxy_tags: - grafana - dashboard + - alerts + - alerting + - presentation + - monitoring - metrics dependencies: [] diff --git a/molecule.yml b/molecule.yml index b87cb5c..0c380b7 100644 --- a/molecule.yml +++ b/molecule.yml @@ -5,17 +5,40 @@ driver: name: docker verifier: name: testinfra +dependency: + name: shell + command: ./.travis/images.sh docker: + build_image: False containers: - name: xenial - image: solita/ubuntu-systemd + image: paulfantom/ubuntu-molecule image_version: 16.04 privileged: true - - name: debian-jessie - image: jrei/systemd-debian + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: stretch + image: paulfantom/debian-molecule + image_version: 9 + cap_add: SYS_ADMIN + privileged: true + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: jessie + image: paulfantom/debian-molecule image_version: 8 privileged: true - - name: centos - image: centos/systemd - image_version: latest + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: centos7 + image: paulfantom/centos-molecule + image_version: 7 privileged: true + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup:ro +# - name: fedora +# image: paulfantom/fedora-molecule +# image_version: 27 +# privileged: true +# volume_mounts: +# - /sys/fs/cgroup:/sys/fs/cgroup:ro diff --git a/tests/playbook.yml b/tests/playbook.yml index 053581b..ea4125c 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,46 +1,8 @@ --- -- hosts: all - tasks: - - name: install testing suite - package: - name: "{{ item }}" - state: present - with_items: - - iproute - - net-tools - - hosts: all any_errors_fatal: yes + pre_tasks: + - name: Include vars + include_vars: vars.yml roles: - ansible-grafana - vars: - grafana_security: - admin_user: admin - admin_password: "password" - grafana_address: "127.0.0.1" - grafana_auth: - disable_login_form: false - disable_signout_menu: false - anonymous: - org_name: "Main Organization" - org_role: Viewer - basic: True - grafana_plugins: - - raintank-worldping-app - grafana_dashboards: - - dashboard_id: '1860' - revision_id: '4' - datasource: 'Prometheus' - - dashboard_id: '358' - revision_id: '1' - datasource: 'Prometheus' - grafana_datasources: - - name: "Prometheus" - type: "prometheus" - access: "proxy" - url: "http://prometheus.mydomain" - basicAuth: true - basicAuthUser: "admin" - basicAuthPassword: "password" - isDefault: true - jsonData: '{"tlsAuth":false,"tlsAuthWithCACert":false,"tlsSkipVerify":true}' From 361ae70b43693c69f1ae83899b937ae983dbc3b9 Mon Sep 17 00:00:00 2001 From: paulfantom Date: Sat, 13 Jan 2018 21:54:56 +0100 Subject: [PATCH 2/5] static grafana user --- defaults/main.yml | 3 --- tasks/configure.yml | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 55999b2..3a66882 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,7 +1,4 @@ --- -grafana_system_user: grafana -grafana_system_group: grafana - grafana_version: 4.6.3 grafana_instance: "{{ ansible_fqdn | default(ansible_host) | default(inventory_hostname) }}" diff --git a/tasks/configure.yml b/tasks/configure.yml index bd64e7b..7955d1c 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -22,8 +22,8 @@ path: "{{ item }}" state: directory mode: 0755 - owner: "{{ grafana_system_user }}" - group: "{{ grafana_system_group }}" + owner: "grafana" + group: "grafana" with_items: - "{{ grafana_logs_dir }}" - "{{ grafana_data_dir }}" From 0802e83d4f060e663b09436fae3b6db2601c096a Mon Sep 17 00:00:00 2001 From: paulfantom Date: Sat, 13 Jan 2018 21:55:21 +0100 Subject: [PATCH 3/5] more meaningful names of preflight tasks --- tasks/preflight.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/preflight.yml b/tasks/preflight.yml index be32c64..70c9771 100644 --- a/tasks/preflight.yml +++ b/tasks/preflight.yml @@ -1,28 +1,28 @@ -- name: Check if system architecture is supported +- name: Fail on unsupported system architectures fail: msg: "Sorry grafana doesn't support {{ ansible_architecture }} on this OS family ({{ ansible_os_family }}). Exiting." when: - ansible_architecture != "x86_64" - not ( ansible_architecture in ['armv6l', 'armv7l'] and ansible_os_family == 'Debian' ) -- name: Check if datasources are configured when dashboards are set to be installed +- name: Fail when datasources aren't configured when dashboards are set to be installed fail: msg: "You need to specify datasources for dashboards!!!" when: grafana_dashboards != [] and grafana_datasources == [] -- name: Check if grafana admin password is set +- name: Fail when grafana admin password isn't set fail: msg: "Please specify grafana admin password (grafana_security.admin_password)" when: grafana_security.admin_password == '' -- name: Check if all variables in datasources definition have their correct type +- name: Fail on incorrect variable types in datasource definitions fail: msg: "Boolean variables in grafana_datasources shouldn't be passed as strings. Please remove unneeded apostrophes." when: ( item.isDefault is defined and item.isDefault is string ) or ( item.basicAuth is defined and item.basicAuth is string ) with_items: "{{ grafana_datasources }}" -- name: Check database configuration +- name: Fail on bad database configuration fail: msg: "Wrong database configuration. Please look at http://docs.grafana.org/installation/configuration/#database" when: ( grafana_database.type == "sqlite3" and grafana_database.url is defined ) or @@ -32,7 +32,7 @@ ( grafana_database.type == "sqlite3" and grafana_database.password is defined ) or ( grafana_database.type == "sqlite3" and grafana_database.server_cert_name is defined ) -- name: Check grafana domain configuration +- name: Fail when grafana domain isn't properly configured fail: msg: "Check server configuration. Please look at http://docs.grafana.org/installation/configuration/#server" when: From 98be5a0123991465e1c44bf04b2c17a6521ea63b Mon Sep 17 00:00:00 2001 From: paulfantom Date: Sat, 13 Jan 2018 21:55:32 +0100 Subject: [PATCH 4/5] refactor tests --- tests/test_default.py | 53 ++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/tests/test_default.py b/tests/test_default.py index 1cca55d..6483631 100644 --- a/tests/test_default.py +++ b/tests/test_default.py @@ -4,7 +4,7 @@ def test_directories(host): - present = [ + dirs = [ "/etc/grafana", "/var/log/grafana", "/var/lib/grafana", @@ -12,49 +12,30 @@ def test_directories(host): "/var/lib/grafana/plugins", "/var/lib/grafana/plugins/raintank-worldping-app" ] - if present: - for directory in present: - d = host.file(directory) - assert d.is_directory - assert d.exists - - -def test_files(host): - present = [ + files = [ "/etc/grafana/grafana.ini" ] - if present: - for file in present: - f = host.file(file) - assert f.exists - assert f.is_file + for directory in dirs: + d = host.file(directory) + assert d.is_directory + assert d.exists + for file in files: + f = host.file(file) + assert f.exists + assert f.is_file def test_service(host): - present = [ - "grafana-server" - ] - if present: - for service in present: - s = host.service(service) - assert s.is_enabled + s = host.service("grafana-server") + assert s.is_enabled + assert s.is_running def test_packages(host): - present = [ - "grafana" - ] - if present: - for package in present: - p = host.package(package) - assert p.is_installed + p = host.package("grafana") + assert p.is_installed + assert p.version == "4.6.3" def test_socket(host): - present = [ - # "tcp://0.0.0.0:3000" - "tcp://127.0.0.1:3000" - ] - for socket in present: - s = host.socket(socket) - assert s.is_listening + assert host.socket("tcp://127.0.0.1:3000").is_listening From 68d031fe2178846ed50c7809a310bb9a824e0af9 Mon Sep 17 00:00:00 2001 From: paulfantom Date: Sat, 13 Jan 2018 21:55:49 +0100 Subject: [PATCH 5/5] separate vars file for molecule tests --- tests/vars.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/vars.yml diff --git a/tests/vars.yml b/tests/vars.yml new file mode 100644 index 0000000..1741a46 --- /dev/null +++ b/tests/vars.yml @@ -0,0 +1,30 @@ +grafana_security: + admin_user: admin + admin_password: "password" +grafana_address: "127.0.0.1" +grafana_auth: + disable_login_form: false + disable_signout_menu: false + anonymous: + org_name: "Main Organization" + org_role: Viewer + basic: True +grafana_plugins: + - raintank-worldping-app +grafana_dashboards: + - dashboard_id: '1860' + revision_id: '4' + datasource: 'Prometheus' + - dashboard_id: '358' + revision_id: '1' + datasource: 'Prometheus' +grafana_datasources: + - name: "Prometheus" + type: "prometheus" + access: "proxy" + url: "http://prometheus.mydomain" + basicAuth: true + basicAuthUser: "admin" + basicAuthPassword: "password" + isDefault: true + jsonData: '{"tlsAuth":false,"tlsAuthWithCACert":false,"tlsSkipVerify":true}'