test: replace kitchen to molecule

This commit is contained in:
Adrien Waksberg 2021-08-20 18:44:19 +02:00
parent 795b2a0b97
commit e930a7c4f1
12 changed files with 110 additions and 123 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
.kitchen/* .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-9
driver_config:
image: "nishiki/debian9:ansible-<%= ENV['ANSIBLE_VERSION'] ? ENV['ANSIBLE_VERSION'] : '2.7' %>"
command: /bin/systemd
volume:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
security_opt: seccomp=unconfined
suites:
- name: default

View file

@ -1,38 +0,0 @@
---
AllCops:
Exclude:
- db/**/*
- config/**/*
- Vagrantfile
TargetRubyVersion: 2.4
Naming/AccessorMethodName:
Enabled: false
Lint/RescueWithoutErrorClass:
Enabled: false
Metrics/LineLength:
Max: 120
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Style/NumericLiteralPrefix:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/CommandLiteral:
Enabled: true
EnforcedStyle: percent_x
Style/Documentation:
Enabled: false

View file

@ -11,6 +11,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
### Added ### Added
- test: add suport debian 10 and 11
- feat: add bsd-mailx package - feat: add bsd-mailx package
- feat: add transport map - feat: add transport map
- feat: add aliases - feat: add aliases
@ -18,6 +19,11 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
### Changed ### Changed
- chore: use FQCN for module name - chore: use FQCN for module name
- test: replace kitchen to molecule
### Removed
- test: remove support debian 9
## v1.0.0 - 2019-03-07 ## v1.0.0 - 2019-03-07

View file

@ -7,8 +7,10 @@ Install and configure an simple mta with postfix
## Requirements ## Requirements
* Ansible >= 2.7 * Ansible >= 2.9
* Debian Stretch * Debian
* Buster
* Bullseye
## Role variables ## Role variables
@ -56,17 +58,12 @@ Install and configure an simple mta with postfix
## Development ## Development
### Test syntax with yamllint ### Test with molecule and docker
* install `python` and `python-pip` * install [docker](https://docs.docker.com/engine/installation/)
* install yamllint `pip install yamllint` * install `python3` and `python3-pip`
* run `yamllint .` * install molecule and dependencies `pip3 install molecule molecule-docker docker ansible-lint pytest-testinfra yamllint`
* run `molecule test`
### Test syntax with ansible-lint
* install `python` and `python-pip`
* install yamllint `pip install ansible-lint`
* run `ansible-lint .`
### Tests with docker ### Tests with docker

View file

@ -1,16 +1,17 @@
--- ---
galaxy_info: galaxy_info:
role_name: postfix-mta role_name: postfix_mta
author: Adrien Waksberg author: Adrien Waksberg
company: Adrien Waksberg company: Adrien Waksberg
description: Install and configure a simple mta with postfix description: Install and configure a simple mta with postfix
license: Apache2 license: Apache2
min_ansible_version: 2.7 min_ansible_version: 2.9
platforms: platforms:
- name: Debian - name: Debian
versions: versions:
- stretch - buster
- bullseye
galaxy_tags: galaxy_tags:
- postfix - postfix

View file

@ -0,0 +1,22 @@
---
- name: Converge
hosts: all
roles:
- ansible-role-postfix_mta
vars:
postfix_config:
inet_protocols: ipv4
transport_maps: hash:/etc/postfix/transport
aliases_maps: hash:/etc/postfix/aliases
postfix_transports:
google.com: smtp:127.0.0.1
postfix_aliases:
root:
- admin
- abuse
admin: admin@localhost.loc
pre_tasks:
- name: update apt cache
ansible.builtin.apt:
update_cache: true

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,42 @@
import testinfra.utils.ansible_runner
def test_packages(host):
for package_name in ['postfix', 'bsd-mailx']:
package = host.package(package_name)
assert package.is_installed
def test_config_file(host):
path = host.file('/etc/postfix/main.cf')
assert path.exists
assert path.is_file
assert path.user == 'root'
assert path.group == 'root'
assert path.mode == 0o644
assert path.contains('inet_protocols = ipv4')
def test_transport_file(host):
path = host.file('/etc/postfix/transport')
assert path.exists
assert path.is_file
assert path.user == 'root'
assert path.group == 'root'
assert path.mode == 0o644
assert path.contains('google.com smtp:127.0.0.1')
def test_aliases_file(host):
path = host.file('/etc/postfix/aliases')
assert path.exists
assert path.is_file
assert path.user == 'root'
assert path.group == 'root'
assert path.mode == 0o644
assert path.contains('root: admin,abuse')
def test_service(host):
service = host.service('postfix')
assert service.is_running
assert service.is_enabled
def test_socket(host):
socket = host.socket('tcp://127.0.0.1:25')
assert socket.is_listening

View file

@ -1,8 +0,0 @@
---
- hosts: default
connection: local
vars:
postfix_protocols: ipv4
roles:
- ansible-role-postfix-mta

View file

@ -1,32 +0,0 @@
require 'serverspec'
set :backend, :exec
puts
puts '================================'
puts %x(ansible --version)
puts '================================'
%w[postfix bsd-mailx].each do |name|
describe package(name) do
it { should be_installed }
end
end
describe file('/etc/postfix/main.cf') 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 'protocols = ipv4' }
end
describe service('postfix') do
it { should be_enabled }
it { should be_running }
it { should be_running.under('systemd') }
end
describe port(25) do
it { should be_listening }
end

View file

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