added custom scenario, and some unit tests
This commit is contained in:
parent
bb56fab49c
commit
95467d081d
@ -4,7 +4,7 @@ manage_netplan_config_file: /etc/netplan/ansible-config.yaml # this MUST be .yam
|
||||
manage_netplan_renderer: networkd # supported value is 'NetworkManager' or 'networkd'
|
||||
manage_netplan_remove_existing: false
|
||||
manage_netplan_search_domain: example.org
|
||||
manage_netplan_install: false
|
||||
manage_netplan_install: true
|
||||
manage_netplan_apply: false
|
||||
manage_netplan_configuration: {}
|
||||
# network:
|
||||
|
3
molecule/default/requirements.yml
Normal file
3
molecule/default/requirements.yml
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
# requirements file for molecule
|
||||
roles: []
|
@ -3,8 +3,16 @@
|
||||
|
||||
def test_hosts_file(host):
|
||||
"""Validate /etc/hosts file."""
|
||||
f = host.file("/etc/hosts")
|
||||
etc_hosts = host.file("/etc/hosts")
|
||||
assert etc_hosts.exists
|
||||
assert etc_hosts.user == "root"
|
||||
assert etc_hosts.group == "root"
|
||||
|
||||
assert f.exists
|
||||
assert f.user == "root"
|
||||
assert f.group == "root"
|
||||
def test_netplan_storage(host):
|
||||
"""Validate /etc/netplan directory."""
|
||||
etc_netplan = host.file("/etc/netplan")
|
||||
assert etc_netplan.exists
|
||||
assert etc_netplan.is_directory
|
||||
assert etc_netplan.user == "root"
|
||||
assert etc_netplan.group =="root"
|
||||
assert etc_netplan.mode == 0o755
|
||||
|
7
molecule/with_custom_config/converge.yml
Normal file
7
molecule/with_custom_config/converge.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: "Include ednxzu.manage_netplan"
|
||||
ansible.builtin.include_role:
|
||||
name: "ednxzu.manage_netplan"
|
@ -10,14 +10,10 @@ manage_netplan_configuration:
|
||||
version: 2
|
||||
ethernets:
|
||||
eth1:
|
||||
match:
|
||||
macaddress: 0c:c4:7a:4d:50:a2
|
||||
dhcp4: false
|
||||
link-local: []
|
||||
set-name: eth1
|
||||
eth2:
|
||||
match:
|
||||
macaddress: 0c:c4:7a:4d:50:a3
|
||||
dhcp4: true
|
||||
mtu: 1500
|
||||
link-local: []
|
41
molecule/with_custom_config/molecule.yml
Normal file
41
molecule/with_custom_config/molecule.yml
Normal file
@ -0,0 +1,41 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
options:
|
||||
requirements-file: ./requirements.yml
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: instance
|
||||
image: geerlingguy/docker-${MOLECULE_TEST_OS}-ansible
|
||||
command: ""
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup
|
||||
cgroupns_mode: host
|
||||
privileged: true
|
||||
pre_build_image: true
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
remote_tmp: /tmp/.ansible
|
||||
verifier:
|
||||
name: testinfra
|
||||
lint: |
|
||||
yamllint -c .yamllint .
|
||||
ansible-lint
|
||||
scenario:
|
||||
name: with_custom_config
|
||||
test_sequence:
|
||||
- dependency
|
||||
- lint
|
||||
- cleanup
|
||||
- destroy
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
3
molecule/with_custom_config/requirements.yml
Normal file
3
molecule/with_custom_config/requirements.yml
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
# requirements file for molecule
|
||||
roles: []
|
22
molecule/with_custom_config/tests/conftest.py
Normal file
22
molecule/with_custom_config/tests/conftest.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""PyTest Fixtures."""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_runtest_setup(item):
|
||||
"""Run tests only when under molecule with testinfra installed."""
|
||||
try:
|
||||
import testinfra
|
||||
except ImportError:
|
||||
pytest.skip("Test requires testinfra", allow_module_level=True)
|
||||
if "MOLECULE_INVENTORY_FILE" in os.environ:
|
||||
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ["MOLECULE_INVENTORY_FILE"]
|
||||
).get_hosts("all")
|
||||
else:
|
||||
pytest.skip(
|
||||
"Test should run only from inside molecule.", allow_module_level=True
|
||||
)
|
18
molecule/with_custom_config/tests/test_default.py
Normal file
18
molecule/with_custom_config/tests/test_default.py
Normal file
@ -0,0 +1,18 @@
|
||||
"""Role testing files using testinfra."""
|
||||
|
||||
|
||||
def test_hosts_file(host):
|
||||
"""Validate /etc/hosts file."""
|
||||
etc_hosts = host.file("/etc/hosts")
|
||||
assert etc_hosts.exists
|
||||
assert etc_hosts.user == "root"
|
||||
assert etc_hosts.group == "root"
|
||||
|
||||
def test_netplan_storage(host):
|
||||
"""Validate /etc/netplan directory."""
|
||||
etc_netplan = host.file("/etc/netplan")
|
||||
assert etc_netplan.exists
|
||||
assert etc_netplan.is_directory
|
||||
assert etc_netplan.user == "root"
|
||||
assert etc_netplan.group =="root"
|
||||
assert etc_netplan.mode == 0o755
|
Loading…
Reference in New Issue
Block a user