first tests implementation
This commit is contained in:
parent
9f85f58ac4
commit
cc72967a75
@ -3,8 +3,20 @@
|
||||
|
||||
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_python_pip_packages_installed(host):
|
||||
"""Validate python3 and pip are installed"""
|
||||
apt_package_python3 = host.package("python3")
|
||||
apt_package_pip = host.package("python3-pip")
|
||||
assert apt_package_python3.is_installed
|
||||
assert apt_package_pip.is_installed
|
||||
|
||||
def test_packages_not_installed(host):
|
||||
"""Validate vim is installed"""
|
||||
pip_packages_list = host.pip_package.get_packages(pip_path='pip')
|
||||
print(pip_packages_list)
|
||||
assert True == False
|
||||
|
7
molecule/with_custom_packages/converge.yml
Normal file
7
molecule/with_custom_packages/converge.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: "Include ednxzu.manage_pip_packages"
|
||||
ansible.builtin.include_role:
|
||||
name: "ednxzu.manage_pip_packages"
|
12
molecule/with_custom_packages/group_vars/all.yml
Normal file
12
molecule/with_custom_packages/group_vars/all.yml
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
manage_pip_packages_install_prereqs: true
|
||||
manage_pip_packages_list:
|
||||
- name: docker
|
||||
version_constraint: latest
|
||||
state: present
|
||||
- name: yamllint
|
||||
version_constraint: '==1.24'
|
||||
state: present
|
||||
- name: vault-cli
|
||||
version_constraint: '<3.1.0'
|
||||
state: present
|
41
molecule/with_custom_packages/molecule.yml
Normal file
41
molecule/with_custom_packages/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_packages
|
||||
test_sequence:
|
||||
- dependency
|
||||
- lint
|
||||
- cleanup
|
||||
- destroy
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
4
molecule/with_custom_packages/requirements.yml
Normal file
4
molecule/with_custom_packages/requirements.yml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
# requirements file for molecule
|
||||
roles:
|
||||
- name: ednxzu.manage_apt_packages
|
22
molecule/with_custom_packages/tests/conftest.py
Normal file
22
molecule/with_custom_packages/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
|
||||
)
|
25
molecule/with_custom_packages/tests/test_default.py
Normal file
25
molecule/with_custom_packages/tests/test_default.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""Role testing files using testinfra."""
|
||||
import json
|
||||
|
||||
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_python_pip_packages_installed(host):
|
||||
"""Validate python3 and pip are installed"""
|
||||
apt_package_python3 = host.package("python3")
|
||||
apt_package_pip = host.package("python3-pip")
|
||||
assert apt_package_python3.is_installed
|
||||
assert apt_package_pip.is_installed
|
||||
|
||||
def test_packages_not_installed(host):
|
||||
"""Validate vim is installed"""
|
||||
pip_packages_list = host.pip_package.get_packages(pip_path='pip')
|
||||
assert pip_packages_list['pip']
|
||||
assert pip_packages_list['docker']
|
||||
assert pip_packages_list['zeubi']
|
||||
print(pip_packages_list)
|
||||
|
Loading…
Reference in New Issue
Block a user