test: replace kitchen to molecule

This commit is contained in:
Adrien Waksberg 2021-08-18 14:38:32 +02:00
parent e3c806f89b
commit 85c60f40eb
14 changed files with 105 additions and 263 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.kitchen/*
*.pyc

View file

@ -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
security_opt: seccomp=unconfined
suites:
- name: default

View file

@ -5,10 +5,19 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
## [Unreleased]
# Added
### Added
- add support for debian 11
- add support for debian 10 and python3
### Changed
- test: replace kitchen to molecule
### Removed
- remove support for debian 9
## [1.0.0] 2019-04-12
- first version

View file

@ -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

View file

@ -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

View file

@ -7,8 +7,10 @@ Install and configure InfluxDB
## Requirements
* Ansible >= 2.7
* Debian Stretch and Buster
* Ansible >= 2.9
* Debian
* Buster
* Bullseye
## Role variables

View file

@ -5,13 +5,13 @@ galaxy_info:
company: Adrien Waksberg
description: Install and configure InfluxDB
license: Apache2
min_ansible_version: 2.7
min_ansible_version: 2.9
platforms:
- name: Debian
versions:
- stretch
- buster
- bullseye
galaxy_tags:
- database

View file

@ -1,20 +1,22 @@
---
- hosts: localhost
connection: local
- name: Converge
hosts: all
roles:
- ansible-role-influxdb
vars:
influxdb_users:
- name: paul
- name: admin
password: test
admin: yes
- name: adrien
- name: test
password: test2
- name: antoine
- name: user_absent
state: absent
influxdb_databases:
- new_database
- test_db
influxdb_privileges:
- user: adrien
database: new_database
- user: test
database: test_db
privilege: WRITE
influxdb_config:
'[collectd]':
@ -23,10 +25,13 @@
database: collectd
typesdb: /usr/share/collectd/types.db
roles:
- ansible-role-influxdb
pre_tasks:
- name: update apt cache
ansible.builtin.apt:
update_cache: true
- name: install collectd package
apt:
name: collectd-core
ansible.builtin.package:
name:
- collectd-core

View file

@ -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

View file

@ -0,0 +1,43 @@
import testinfra.utils.ansible_runner
import re
def test_packages(host):
package = host.package('influxdb')
assert package.is_installed
def test_config_file(host):
path = host.file('/etc/influxdb/influxdb.conf')
assert path.exists
assert path.is_file
assert path.user == 'root'
assert path.group == 'root'
assert path.mode == 0o644
assert path.contains('enabled = true')
def test_service(host):
service = host.service('influxdb')
assert service.is_running
assert service.is_enabled
def test_sockets(host):
socket = host.socket('tcp://0.0.0.0:8086')
assert socket.is_listening
socket = host.socket('udp://0.0.0.0:25826')
assert socket.is_listening
def test_users(host):
cmd = host.run('influx -execute "SHOW USERS"')
assert cmd.succeeded
assert re.search(r'admin\s+true', cmd.stdout)
assert re.search(r'user\s+false', cmd.stdout)
assert not re.search('user_absent', cmd.stdout)
def test_databases(host):
cmd = host.run('influx -execute "SHOW DATABASES"')
assert cmd.succeeded
assert 'test_db' in cmd.stdout
def test_grants(host):
cmd = host.run('influx -execute "SHOW GRANTS FOR test"')
assert cmd.succeeded
assert re.search(r'test_db\s+WRITE', cmd.stdout)

View file

@ -6,7 +6,7 @@
packages:
- apt-transport-https
- collectd-core
- python-pip
- python3-pip
register: result
until: result is succeeded
retries: 2
@ -36,6 +36,7 @@
- name: install python-influxdb
pip:
name: influxdb
executable: /usr/bin/pip3
register: result
until: result is succeeded
retries: 2

View file

@ -1,28 +0,0 @@
E, [2019-01-17T09:43:25.055727 #24689] ERROR -- Kitchen: ------Exception-------
E, [2019-01-17T09:43:25.055802 #24689] ERROR -- Kitchen: Class: Kitchen::UserError
E, [2019-01-17T09:43:25.055823 #24689] ERROR -- Kitchen: Message: Kitchen YAML file /home/awaksberg/git/ansible-role-influxdb/test/integration/default/.kitchen.yml does not exist.
E, [2019-01-17T09:43:25.055835 #24689] ERROR -- Kitchen: ----------------------
E, [2019-01-17T09:43:25.055845 #24689] ERROR -- Kitchen: ------Backtrace-------
E, [2019-01-17T09:43:25.055854 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/loader/yaml.rb:65:in `read'
E, [2019-01-17T09:43:25.055863 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/config.rb:152:in `data'
E, [2019-01-17T09:43:25.055872 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/config.rb:131:in `suites'
E, [2019-01-17T09:43:25.055881 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/config.rb:182:in `filter_instances'
E, [2019-01-17T09:43:25.055891 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/config.rb:141:in `build_instances'
E, [2019-01-17T09:43:25.055900 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/config.rb:117:in `instances'
E, [2019-01-17T09:43:25.055909 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/command.rb:112:in `filtered_instances'
E, [2019-01-17T09:43:25.055918 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/command.rb:142:in `parse_subcommand'
E, [2019-01-17T09:43:25.055927 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/command/list.rb:30:in `call'
E, [2019-01-17T09:43:25.055936 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/cli.rb:52:in `perform'
E, [2019-01-17T09:43:25.055947 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/cli.rb:120:in `list'
E, [2019-01-17T09:43:25.055957 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
E, [2019-01-17T09:43:25.055966 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
E, [2019-01-17T09:43:25.055975 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
E, [2019-01-17T09:43:25.055984 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
E, [2019-01-17T09:43:25.055993 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/bin/kitchen:13:in `block in <top (required)>'
E, [2019-01-17T09:43:25.056002 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/lib/kitchen/errors.rb:171:in `with_friendly_errors'
E, [2019-01-17T09:43:25.056011 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/gems/test-kitchen-1.23.5/bin/kitchen:13:in `<top (required)>'
E, [2019-01-17T09:43:25.056020 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/bin/kitchen:23:in `load'
E, [2019-01-17T09:43:25.056029 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/bin/kitchen:23:in `<main>'
E, [2019-01-17T09:43:25.056039 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
E, [2019-01-17T09:43:25.056048 #24689] ERROR -- Kitchen: /home/awaksberg/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
E, [2019-01-17T09:43:25.056057 #24689] ERROR -- Kitchen: ----End Backtrace-----

View file

@ -1,50 +0,0 @@
require 'serverspec'
set :backend, :exec
puts
puts '================================'
puts %x(ansible --version)
puts '================================'
describe package('influxdb') do
it { should be_installed }
end
describe file('/etc/influxdb/influxdb.conf') do
it { should be_file }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should contain 'enabled = true' }
end
describe service('influxdb') do
it { should be_enabled }
it { should be_running.under('systemd') }
end
describe port(8086) do
it { should be_listening.with('tcp6') }
end
describe port(25_826) do
it { should be_listening.with('udp6') }
end
describe command('influx -execute "SHOW USERS"') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/paul\s+true/) }
its(:stdout) { should match(/adrien\s+false/) }
its(:stdout) { should_not match 'antoine' }
end
describe command('influx -execute "SHOW DATABASES"') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match 'new_database' }
end
describe command('influx -execute "SHOW GRANTS FOR adrien"') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/new_database\s+WRITE/) }
end

View file

@ -1 +0,0 @@
localhost