From d9f255b19a37d5c6d6f983b238603f2aa674f7e1 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Sun, 22 Aug 2021 12:55:18 +0200 Subject: [PATCH] test: replace kitchen to molecule --- .gitignore | 1 + .kitchen.yml | 27 ---- CHANGELOG.md | 6 + Gemfile | 8 -- Gemfile.lock | 131 ------------------ README.md | 27 ++-- meta/main.yml | 6 +- molecule/default/converge.yml | 23 +++ molecule/default/molecule.yml | 26 ++++ molecule/default/tests/test_default.py | 41 ++++++ test/integration/default/default.yml | 15 -- .../default/serverspec/default_spec.rb | 44 ------ test/integration/inventory | 1 - 13 files changed, 108 insertions(+), 248 deletions(-) delete mode 100644 .kitchen.yml delete mode 100644 Gemfile delete mode 100644 Gemfile.lock create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/tests/test_default.py delete mode 100644 test/integration/default/default.yml delete mode 100644 test/integration/default/serverspec/default_spec.rb delete mode 100644 test/integration/inventory diff --git a/.gitignore b/.gitignore index 79776e8..1331d18 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .kitchen/* +*.pyc diff --git a/.kitchen.yml b/.kitchen.yml deleted file mode 100644 index 3cdce5f..0000000 --- a/.kitchen.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -driver: - name: docker_cli - -transport: - name: docker_cli - -provisioner: - name: ansible_playbook - hosts: localhost - require_ansible_repo: false - require_ansible_omnibus: false - require_chef_for_busser: true - ansible_verbose: false - ansible_inventory: ./test/integration/inventory - -platforms: - - name: debian-10 - driver_config: - image: "nishiki/debian10:ansible-<%= ENV['ANSIBLE_VERSION'] ? ENV['ANSIBLE_VERSION'] : '2.9' %>" - command: /bin/systemd - volume: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: cap-add=SYS_ADMIN - -suites: - - name: default diff --git a/CHANGELOG.md b/CHANGELOG.md index 39ada70..bd3fe20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,16 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/) ### Added - feat: install unofficial plugins +- test: add support debian 11 ### Changed - chore: use FQCN for module name +- test: replace kitchen to molecule + +### Removed + +- test: remove support debian 9 ## 1.0.1 - 2019-08-17 diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 0d96441..0000000 --- a/Gemfile +++ /dev/null @@ -1,8 +0,0 @@ -source 'https://rubygems.org' - -group :development do - gem 'kitchen-ansible' - gem 'kitchen-docker_cli' - gem 'rubocop', '0.50.0' - gem 'test-kitchen' -end diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 1dd4e2c..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,131 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - ast (2.4.0) - bcrypt_pbkdf (1.0.1) - builder (3.2.4) - ed25519 (1.2.4) - equatable (0.6.1) - erubi (1.9.0) - ffi (1.12.2) - gssapi (1.3.0) - ffi (>= 1.0.1) - gyoku (1.3.1) - builder (>= 2.1.2) - httpclient (2.8.3) - kitchen-ansible (0.50.1) - net-ssh (>= 3) - test-kitchen (>= 1.4) - kitchen-docker_cli (0.19.0) - test-kitchen (>= 1.3) - license-acceptance (1.0.13) - pastel (~> 0.7) - tomlrb (~> 1.2) - tty-box (~> 0.3) - tty-prompt (~> 0.18) - little-plugger (1.1.4) - logging (2.2.2) - little-plugger (~> 1.1) - multi_json (~> 1.10) - mixlib-install (3.11.26) - mixlib-shellout - mixlib-versioning - thor - mixlib-shellout (3.0.9) - mixlib-versioning (1.2.12) - multi_json (1.14.1) - necromancer (0.5.1) - net-scp (2.0.0) - net-ssh (>= 2.6.5, < 6.0.0) - net-ssh (5.2.0) - net-ssh-gateway (2.0.0) - net-ssh (>= 4.0.0) - nori (2.6.0) - parallel (1.19.1) - parser (2.7.0.2) - ast (~> 2.4.0) - pastel (0.7.3) - equatable (~> 0.6) - tty-color (~> 0.5) - powerpack (0.1.2) - rainbow (2.2.2) - rake - rake (13.0.1) - rubocop (0.50.0) - parallel (~> 1.10) - parser (>= 2.3.3.1, < 3.0) - powerpack (~> 0.1) - rainbow (>= 2.2.2, < 3.0) - ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.10.1) - rubyntlm (0.6.2) - rubyzip (2.2.0) - strings (0.1.8) - strings-ansi (~> 0.1) - unicode-display_width (~> 1.5) - unicode_utils (~> 1.4) - strings-ansi (0.2.0) - test-kitchen (2.3.4) - bcrypt_pbkdf (~> 1.0) - ed25519 (~> 1.2) - license-acceptance (~> 1.0, >= 1.0.11) - mixlib-install (~> 3.6) - mixlib-shellout (>= 1.2, < 4.0) - net-scp (>= 1.1, < 3.0) - net-ssh (>= 2.9, < 6.0) - net-ssh-gateway (>= 1.2, < 3.0) - thor (~> 0.19) - winrm (~> 2.0) - winrm-elevated (~> 1.0) - winrm-fs (~> 1.1) - thor (0.20.3) - tomlrb (1.2.9) - tty-box (0.5.0) - pastel (~> 0.7.2) - strings (~> 0.1.6) - tty-cursor (~> 0.7) - tty-color (0.5.1) - tty-cursor (0.7.1) - tty-prompt (0.20.0) - necromancer (~> 0.5.0) - pastel (~> 0.7.0) - tty-reader (~> 0.7.0) - tty-reader (0.7.0) - tty-cursor (~> 0.7) - tty-screen (~> 0.7) - wisper (~> 2.0.0) - tty-screen (0.7.1) - unicode-display_width (1.6.1) - unicode_utils (1.4.0) - winrm (2.3.4) - builder (>= 2.1.2) - erubi (~> 1.8) - gssapi (~> 1.2) - gyoku (~> 1.0) - httpclient (~> 2.2, >= 2.2.0.2) - logging (>= 1.6.1, < 3.0) - nori (~> 2.0) - rubyntlm (~> 0.6.0, >= 0.6.1) - winrm-elevated (1.2.1) - erubi (~> 1.8) - winrm (~> 2.0) - winrm-fs (~> 1.0) - winrm-fs (1.3.4) - erubi (~> 1.8) - logging (>= 1.6.1, < 3.0) - rubyzip (~> 2.0) - winrm (~> 2.0) - wisper (2.0.1) - -PLATFORMS - ruby - -DEPENDENCIES - kitchen-ansible - kitchen-docker_cli - rubocop (= 0.50.0) - test-kitchen - -BUNDLED WITH - 1.17.3 diff --git a/README.md b/README.md index 9171e74..007b0d2 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,10 @@ Install and configure Grafana ## Requirements -* Ansible >= 2.7 -* Debian Stretch and Buster +* Ansible >= 2.9 +* Debian + * Buster + * Bullseye ## Role variables @@ -43,25 +45,12 @@ Install and configure Grafana ## Development -### Test syntax with yamllint - -* install `python` and `python-pip` -* install yamllint `pip install yamllint` -* run `yamllint .` - -### Test syntax with ansible-lint - -* install `python` and `python-pip` -* install yamllint `pip install ansible-lint` -* run `ansible-lint .` - -### Tests with docker +### Test with molecule and docker * install [docker](https://docs.docker.com/engine/installation/) -* install ruby -* install bundler `gem install bundler` -* install dependencies `bundle install` -* run the tests `kitchen test` +* install `python3` and `python3-pip` +* install molecule and dependencies `pip3 install molecule molecule-docker docker ansible-lint pytest-testinfra yamllint` +* run `molecule test` ## License diff --git a/meta/main.yml b/meta/main.yml index d9fc61c..6a836a7 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,17 +1,17 @@ --- galaxy_info: - role_name: Grafana + role_name: grafana author: Adrien Waksberg company: Adrien Waksberg description: Install and configure Grafana license: Apache2 - min_ansible_version: 2.7 + min_ansible_version: 2.9 platforms: - name: Debian versions: - - stretch - buster + - bullseye galaxy_tags: - dashboard diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..19235e3 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,23 @@ +--- +- name: Converge + hosts: all + roles: + - ansible-role-grafana + vars: + grafana_plugins: + - name: grafana-piechart-panel + - name: sensu-sensugo-datasource + version: 1.0.3 + url: > + https://github.com/sensu/grafana-sensu-go-datasource/releases/download/1.0.3/sensu-sensugo-datasource-1.0.3.zip + grafana_config: + default: + instance_name: '${HOSTNAME}' + security: + admin_user: sysadmin + admin_password: secret + + pre_tasks: + - name: update apt cache + ansible.builtin.apt: + update_cache: true diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..0507c53 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,26 @@ +--- +driver: + name: docker +platforms: + - name: debian10 + image: nishiki/debian10:molecule + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + command: /bin/systemd + capabilities: + - SYS_ADMIN + - name: debian11 + image: nishiki/debian11:molecule + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + command: /bin/systemd + capabilities: + - SYS_ADMIN +lint: | + set -e + yamllint . + ansible-lint . +verifier: + name: testinfra diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py new file mode 100644 index 0000000..dbad8f0 --- /dev/null +++ b/molecule/default/tests/test_default.py @@ -0,0 +1,41 @@ +import testinfra.utils.ansible_runner + +def test_packages(host): + package = host.package('grafana') + assert package.is_installed + +def test_config_file(host): + path = host.file('/etc/grafana/grafana.ini') + assert path.exists + assert path.is_file + assert path.user == 'root' + assert path.group == 'grafana' + assert path.mode == 0o640 + assert not path.contains('default') + assert path.contains('instance_name = "${HOSTNAME}"') + assert path.contains('[security]') + assert path.contains('admin_user = "sysadmin"') + +def test_ldap_config_file(host): + path = host.file('/etc/grafana/ldap.toml') + assert path.exists + assert path.is_file + assert path.user == 'root' + assert path.group == 'grafana' + assert path.mode == 0o640 + +def test_plugins_install(host): + for plugin_name in ['grafana-piechart-panel', 'sensu-sensugo-datasource']: + path = host.file('/var/lib/grafana/plugins/%s' % plugin_name) + assert path.exists + assert path.is_directory + assert path.user == 'root' + +def test_service(host): + service = host.service('grafana-server') + assert service.is_running + assert service.is_enabled + +def test_socket(host): + socket = host.socket('tcp://0.0.0.0:3000') + assert socket.is_listening diff --git a/test/integration/default/default.yml b/test/integration/default/default.yml deleted file mode 100644 index a7e9962..0000000 --- a/test/integration/default/default.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- hosts: localhost - connection: local - vars: - grafana_plugins: - - name: grafana-piechart-panel - grafana_config: - default: - instance_name: '${HOSTNAME}' - security: - admin_user: sysadmin - admin_password: secret - - roles: - - ansible-role-grafana diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb deleted file mode 100644 index e520ae8..0000000 --- a/test/integration/default/serverspec/default_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'serverspec' - -set :backend, :exec - -puts -puts '================================' -puts %x(ansible --version) -puts '================================' - -describe package('grafana') do - it { should be_installed } -end - -describe file('/etc/grafana/grafana.ini') do - it { should be_file } - it { should be_mode 640 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'grafana' } - it { should_not contain 'default' } - it { should contain 'instance_name = "${HOSTNAME}"' } - it { should contain '[security]' } - it { should contain 'admin_user = "sysadmin"' } -end - -describe file('/etc/grafana/ldap.toml') do - it { should be_file } - it { should be_mode 640 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'grafana' } -end - -describe file('/var/lib/grafana/plugins/grafana-piechart-panel') do - it { should be_directory } - it { should be_owned_by 'root' } -end - -describe service('grafana-server') do - it { should be_enabled } - it { should be_running.under('systemd') } -end - -describe port(3000) do - it { should be_listening.with('tcp6') } -end diff --git a/test/integration/inventory b/test/integration/inventory deleted file mode 100644 index 2fbb50c..0000000 --- a/test/integration/inventory +++ /dev/null @@ -1 +0,0 @@ -localhost