test: replace kitchen to molecule
This commit is contained in:
parent
e947d74e13
commit
d753376dda
12 changed files with 92 additions and 271 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
.kitchen/*
|
.kitchen/*
|
||||||
|
*.pyc
|
||||||
|
|
27
.kitchen.yml
27
.kitchen.yml
|
@ -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
|
|
||||||
driver_config:
|
|
||||||
image: "nishiki/debian<%= ENV['DEBIAN_VERSION'] ? ENV['DEBIAN_VERSION'] : '10' %>: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
|
|
28
.travis.yml
28
.travis.yml
|
@ -1,29 +1,29 @@
|
||||||
---
|
---
|
||||||
sudo: required
|
sudo: required
|
||||||
language: ruby
|
dist: bionic
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- python3
|
||||||
|
- python3-pip
|
||||||
|
- python3-setuptools
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- DEBIAN_VERSION=9 ANSIBLE_VERSION=2.8
|
- ANSIBLE_VERSION=2.7.16
|
||||||
- DEBIAN_VERSION=9 ANSIBLE_VERSION=2.9
|
- ANSIBLE_VERSION=2.8.8
|
||||||
- DEBIAN_VERSION=10 ANSIBLE_VERSION=2.8
|
- ANSIBLE_VERSION=2.9.4
|
||||||
- DEBIAN_VERSION=10 ANSIBLE_VERSION=2.9
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- bundle install
|
- sudo pip3 install ansible==${ANSIBLE_VERSION}
|
||||||
- sudo pip install --upgrade pip
|
- sudo pip3 install molecule 'molecule[docker]' docker testinfra ansible-lint yamllint
|
||||||
- sudo pip install yamllint
|
|
||||||
- sudo pip install ansible-lint
|
|
||||||
- git clone https://github.com/ansible/galaxy-lint-rules.git
|
- git clone https://github.com/ansible/galaxy-lint-rules.git
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- kitchen conv
|
- ansible --version
|
||||||
- kitchen conv | grep changed=0
|
- molecule test
|
||||||
- kitchen verify
|
|
||||||
- ansible-lint -r galaxy-lint-rules/rules .
|
|
||||||
- yamllint .
|
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||||
|
|
|
@ -5,6 +5,10 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- test: replace kitchen to molecule
|
||||||
|
|
||||||
## [v2.0.0] - 2019-06-05
|
## [v2.0.0] - 2019-06-05
|
||||||
|
|
||||||
- breaking: remove support for ansible < 2.8
|
- breaking: remove support for ansible < 2.8
|
||||||
|
|
8
Gemfile
8
Gemfile
|
@ -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
|
|
133
Gemfile.lock
133
Gemfile.lock
|
@ -1,133 +0,0 @@
|
||||||
GEM
|
|
||||||
remote: https://rubygems.org/
|
|
||||||
specs:
|
|
||||||
ast (2.4.0)
|
|
||||||
bcrypt_pbkdf (1.0.1)
|
|
||||||
builder (3.2.3)
|
|
||||||
ed25519 (1.2.4)
|
|
||||||
equatable (0.5.0)
|
|
||||||
erubis (2.7.0)
|
|
||||||
ffi (1.11.1)
|
|
||||||
gssapi (1.3.0)
|
|
||||||
ffi (>= 1.0.1)
|
|
||||||
gyoku (1.3.1)
|
|
||||||
builder (>= 2.1.2)
|
|
||||||
httpclient (2.8.3)
|
|
||||||
kitchen-ansible (0.50.0)
|
|
||||||
net-ssh (>= 3)
|
|
||||||
test-kitchen (>= 1.4)
|
|
||||||
kitchen-docker_cli (0.19.0)
|
|
||||||
test-kitchen (>= 1.3)
|
|
||||||
license-acceptance (1.0.12)
|
|
||||||
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.18)
|
|
||||||
mixlib-shellout
|
|
||||||
mixlib-versioning
|
|
||||||
thor
|
|
||||||
mixlib-shellout (2.4.4)
|
|
||||||
mixlib-versioning (1.2.7)
|
|
||||||
multi_json (1.13.1)
|
|
||||||
necromancer (0.4.0)
|
|
||||||
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.17.0)
|
|
||||||
parser (2.6.3.0)
|
|
||||||
ast (~> 2.4.0)
|
|
||||||
pastel (0.7.2)
|
|
||||||
equatable (~> 0.5.0)
|
|
||||||
tty-color (~> 0.4.0)
|
|
||||||
powerpack (0.1.2)
|
|
||||||
rainbow (2.2.2)
|
|
||||||
rake
|
|
||||||
rake (12.3.2)
|
|
||||||
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 (1.2.3)
|
|
||||||
strings (0.1.5)
|
|
||||||
strings-ansi (~> 0.1)
|
|
||||||
unicode-display_width (~> 1.5)
|
|
||||||
unicode_utils (~> 1.4)
|
|
||||||
strings-ansi (0.1.0)
|
|
||||||
test-kitchen (2.2.5)
|
|
||||||
bcrypt_pbkdf (~> 1.0)
|
|
||||||
ed25519 (~> 1.2)
|
|
||||||
license-acceptance (~> 1.0, >= 1.0.11)
|
|
||||||
mixlib-install (~> 3.6)
|
|
||||||
mixlib-shellout (>= 1.2, < 3.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)
|
|
||||||
timers (4.3.0)
|
|
||||||
tomlrb (1.2.8)
|
|
||||||
tty-box (0.3.0)
|
|
||||||
pastel (~> 0.7.2)
|
|
||||||
strings (~> 0.1.4)
|
|
||||||
tty-cursor (~> 0.6.0)
|
|
||||||
tty-color (0.4.3)
|
|
||||||
tty-cursor (0.6.1)
|
|
||||||
tty-prompt (0.18.1)
|
|
||||||
necromancer (~> 0.4.0)
|
|
||||||
pastel (~> 0.7.0)
|
|
||||||
timers (~> 4.0)
|
|
||||||
tty-cursor (~> 0.6.0)
|
|
||||||
tty-reader (~> 0.5.0)
|
|
||||||
tty-reader (0.5.0)
|
|
||||||
tty-cursor (~> 0.6.0)
|
|
||||||
tty-screen (~> 0.6.4)
|
|
||||||
wisper (~> 2.0.0)
|
|
||||||
tty-screen (0.6.5)
|
|
||||||
unicode-display_width (1.6.0)
|
|
||||||
unicode_utils (1.4.0)
|
|
||||||
winrm (2.3.2)
|
|
||||||
builder (>= 2.1.2)
|
|
||||||
erubis (~> 2.7)
|
|
||||||
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.1.1)
|
|
||||||
winrm (~> 2.0)
|
|
||||||
winrm-fs (~> 1.0)
|
|
||||||
winrm-fs (1.3.2)
|
|
||||||
erubis (~> 2.7)
|
|
||||||
logging (>= 1.6.1, < 3.0)
|
|
||||||
rubyzip (~> 1.1)
|
|
||||||
winrm (~> 2.0)
|
|
||||||
wisper (2.0.0)
|
|
||||||
|
|
||||||
PLATFORMS
|
|
||||||
ruby
|
|
||||||
|
|
||||||
DEPENDENCIES
|
|
||||||
kitchen-ansible
|
|
||||||
kitchen-docker_cli
|
|
||||||
rubocop (= 0.50.0)
|
|
||||||
test-kitchen
|
|
||||||
|
|
||||||
BUNDLED WITH
|
|
||||||
1.16.0
|
|
21
README.md
21
README.md
|
@ -54,25 +54,12 @@ Install and configure MariaDB
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Test syntax with yamllint
|
### Test with molecule and docker
|
||||||
|
|
||||||
* 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
|
|
||||||
|
|
||||||
* install [docker](https://docs.docker.com/engine/installation/)
|
* install [docker](https://docs.docker.com/engine/installation/)
|
||||||
* install ruby
|
* install `python3` and `python3-pip`
|
||||||
* install bundler `gem install bundler`
|
* install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
||||||
* install dependencies `bundle install`
|
* run `molecule test`
|
||||||
* run the tests `kitchen test`
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
- hosts: localhost
|
- name: Converge
|
||||||
connection: local
|
hosts: all
|
||||||
vars:
|
vars:
|
||||||
mariadb_autorestart: yes
|
mariadb_autorestart: yes
|
||||||
mariadb_master: yes
|
mariadb_master: yes
|
||||||
|
@ -18,6 +18,5 @@
|
||||||
password: test
|
password: test
|
||||||
privileges:
|
privileges:
|
||||||
- 'test.*:ALL'
|
- 'test.*:ALL'
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- ansible-role-mariadb
|
- ansible-role-mariadb
|
18
molecule/default/molecule.yml
Normal file
18
molecule/default/molecule.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
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
|
||||||
|
lint: |
|
||||||
|
set -e
|
||||||
|
yamllint .
|
||||||
|
ansible-lint
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
49
molecule/default/tests/test_default.py
Normal file
49
molecule/default/tests/test_default.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import os, re
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
def test_packages(host):
|
||||||
|
for package_name in ['mariadb-server', 'python-mysqldb']:
|
||||||
|
package = host.package(package_name)
|
||||||
|
assert package.is_installed
|
||||||
|
|
||||||
|
def test_config_file(host):
|
||||||
|
config = host.file('/etc/mysql/my.cnf')
|
||||||
|
assert config.exists
|
||||||
|
assert config.is_file
|
||||||
|
assert config.user == 'root'
|
||||||
|
assert config.group == 'root'
|
||||||
|
assert config.mode == 0o644
|
||||||
|
assert config.contains('server-id = 5')
|
||||||
|
|
||||||
|
def test_data_directory(host):
|
||||||
|
config = host.file('/opt/mariadb')
|
||||||
|
assert config.exists
|
||||||
|
assert config.is_directory
|
||||||
|
assert config.user == 'mysql'
|
||||||
|
assert config.group == 'root'
|
||||||
|
assert config.mode == 0o750
|
||||||
|
|
||||||
|
def test_service(host):
|
||||||
|
service = host.service('mysql')
|
||||||
|
assert service.is_running
|
||||||
|
assert service.is_enabled
|
||||||
|
|
||||||
|
def test_socket(host):
|
||||||
|
socket = host.socket('tcp://127.0.0.1:3306')
|
||||||
|
assert socket.is_listening
|
||||||
|
|
||||||
|
def test_user_exists(host):
|
||||||
|
result = host.check_output('mysql -uroot -psecret -e "show grants for toto@\'%\'"')
|
||||||
|
assert re.search('toto.*%', result)
|
||||||
|
|
||||||
|
def test_root_user(host):
|
||||||
|
result = host.check_output('mysql -uroot -psecret -e "select count(*) from mysql.user where user=\'root\'"')
|
||||||
|
assert '1' in result
|
||||||
|
|
||||||
|
def test_grant_access(host):
|
||||||
|
result = host.check_output('mysql -uroot -psecret -e "show grants for toto@\'%\'"')
|
||||||
|
assert "GRANT ALL PRIVILEGES ON `test`.* TO 'toto'@'%'" in result
|
||||||
|
|
||||||
|
def test_logbin_enabled(host):
|
||||||
|
result = host.check_output('mysql -uroot -psecret -e "show variables where variable_name = \'log_bin\'"')
|
||||||
|
assert 'ON' in result
|
|
@ -1,68 +0,0 @@
|
||||||
require 'serverspec'
|
|
||||||
|
|
||||||
set :backend, :exec
|
|
||||||
|
|
||||||
puts
|
|
||||||
puts '================================'
|
|
||||||
puts %x(ansible --version)
|
|
||||||
puts '================================'
|
|
||||||
|
|
||||||
%w[
|
|
||||||
mariadb-server
|
|
||||||
python-mysqldb
|
|
||||||
].each do |name|
|
|
||||||
describe package(name) do
|
|
||||||
it { should be_installed }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe file('/opt/mariadb') do
|
|
||||||
it { should be_directory }
|
|
||||||
it { should be_mode 750 }
|
|
||||||
it { should be_owned_by 'mysql' }
|
|
||||||
it { should be_grouped_into 'root' }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe file('/etc/mysql/my.cnf') 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 'server-id = 5' }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe service('mysql') do
|
|
||||||
it { should be_enabled }
|
|
||||||
it { should be_running.under('systemd') }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe port(3306) do
|
|
||||||
it { should be_listening }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('mysql -uroot -psecret -e "show databases"') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should contain 'test' }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('mysql -uroot -psecret -e "select user, host, password from mysql.user"') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should contain(/toto.*%/) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('mysql -uroot -psecret -e "select count(*) from mysql.user where user=\'root\'"') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should contain('1') }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('mysql -uroot -psecret -e "show grants for toto@\'%\'"') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) do
|
|
||||||
should contain "GRANT ALL PRIVILEGES ON `test`.* TO 'toto'@'%'"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe command('mysql -uroot -psecret -e "show variables where variable_name = \'log_bin\'"') do
|
|
||||||
its(:exit_status) { should eq 0 }
|
|
||||||
its(:stdout) { should contain 'ON' }
|
|
||||||
end
|
|
|
@ -1 +0,0 @@
|
||||||
localhost
|
|
Loading…
Reference in a new issue