test: replace kitchen to molecule

This commit is contained in:
Adrien Waksberg 2021-11-22 11:27:46 +01:00
parent 839324e191
commit 5d8e273810
10 changed files with 64 additions and 203 deletions

2
.gitignore vendored
View file

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

View file

@ -1,23 +0,0 @@
---
driver:
name: vagrant
provider: virtualbox
box: bento/debian-10.0
provisioner:
name: ansible_playbook
hosts: localhost
require_ansible_repo: false
require_ansible_omnibus: true
require_chef_for_busser: true
ansible_verbose: false
ansible_inventory: ./test/integration/inventory
platforms:
- name: debian-9
provisioner:
extra_vars:
ansible_python_interpreter: python3
suites:
- name: default

View file

@ -1,8 +0,0 @@
source 'https://rubygems.org'
group :development do
gem 'kitchen-ansible'
gem 'kitchen-vagrant'
gem 'rubocop', '0.50.0'
gem 'test-kitchen'
end

View file

@ -1,130 +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.6.1)
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.1)
net-ssh (>= 3)
test-kitchen (>= 1.4)
kitchen-vagrant (1.6.0)
test-kitchen (>= 1.4, < 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.18)
mixlib-shellout
mixlib-versioning
thor
mixlib-shellout (2.4.4)
mixlib-versioning (1.2.7)
multi_json (1.13.1)
necromancer (0.5.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.3)
equatable (~> 0.6)
tty-color (~> 0.5)
powerpack (0.1.2)
rainbow (2.2.2)
rake
rake (12.3.3)
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)
tomlrb (1.2.8)
tty-box (0.4.0)
pastel (~> 0.7.2)
strings (~> 0.1.5)
tty-cursor (~> 0.7)
tty-color (0.5.0)
tty-cursor (0.7.0)
tty-prompt (0.19.0)
necromancer (~> 0.5.0)
pastel (~> 0.7.0)
tty-reader (~> 0.6.0)
tty-reader (0.6.0)
tty-cursor (~> 0.7)
tty-screen (~> 0.7)
wisper (~> 2.0.0)
tty-screen (0.7.0)
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-vagrant
rubocop (= 0.50.0)
test-kitchen
BUNDLED WITH
1.17.3

View file

@ -1,8 +1,9 @@
---
galaxy_info:
role_name: docker
role_name: swarm
namespace: mylegitech
author: Adrien Waksberg
company: Artifaille
company: MyLegiTech
description: Install docker and configure docker swarm
license: Apache2
min_ansible_version: 2.10

View file

@ -1,14 +1,13 @@
---
- hosts: default
connection: local
- name: Converge
hosts: all
roles:
- swarm
vars:
docker_swarm_manager: true
docker_advertise_addr: 127.0.0.1
docker_networks:
- name: proxy
config:
- gateway: 172.45.0.1
subnet: 172.45.0.0/16
docker_services:
- name: traefik
image: traefik:1.7
@ -20,6 +19,7 @@
publish:
- published_port: 80
target_port: 80
mode: host
mounts:
- source: /var/run/docker.sock
target: /var/run/docker.sock
@ -33,5 +33,7 @@
traefik.frontend.rule: 'Host:whoami'
traefik.port: '8000'
roles:
- ansible-role-docker
pre_tasks:
- name: update apt cache
ansible.builtin.apt:
update_cache: true

View file

@ -0,0 +1,18 @@
---
driver:
name: docker
platforms:
- 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,33 @@
import testinfra.utils.ansible_runner
import time
time.sleep(60)
def test_packages(host):
package = host.package('docker.io')
assert package.is_installed
def test_service(host):
service = host.service('docker')
assert service.is_running
assert service.is_enabled
def test_sockets(host):
socket = host.socket('tcp://0.0.0.0:80')
assert socket.is_listening
def test_docker_network(host):
cmd = host.run('docker network list')
assert cmd.succeeded
assert 'proxy' in cmd.stdout
def test_docker_container(host):
cmd = host.run('docker ps')
assert cmd.succeeded
assert 'whoami' in cmd.stdout
assert 'traefik' in cmd.stdout
def test_databases(host):
cmd = host.run('curl -H "Host: whoami" http://127.0.0.1')
assert cmd.succeeded
assert "I'm " in cmd.stdout

View file

@ -1,30 +0,0 @@
require 'serverspec'
set :backend, :exec
puts
puts '================================'
puts %x(ansible --version)
puts '================================'
sleep 60
describe package('docker-ce') do
it { should be_installed }
end
describe command('docker network list') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match 'proxy' }
end
describe command('docker ps') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match 'whoami' }
its(:stdout) { should match 'traefik' }
end
describe command('curl -H "Host: whoami" http://127.0.0.1') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match "I'm " }
end

View file

@ -1,2 +0,0 @@
[default]
localhost