diff --git a/.gitignore b/.gitignore index 865abedb26e6ad3f413b9097bb3334aedca28457..54188670ac6d750b80381e326c09780aaefa0559 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .idea/ virtualenv/ venv/ -molecule/default/.molecule/ -molecule/default/.pytest_cache/ -molecule/default/pytestdebug.log +molecule/*/.molecule/ +molecule/*/.pytest_cache/ +molecule/*/pytestdebug.log diff --git a/molecule/db-mariadb/molecule.yml b/molecule/db-mariadb/molecule.yml index f2f746292a27b22a896d92e0b9244dd5a46d7400..a12df238735d9711510d85efc16aeecefc07201c 100644 --- a/molecule/db-mariadb/molecule.yml +++ b/molecule/db-mariadb/molecule.yml @@ -49,8 +49,8 @@ provisioner: verifier: name: testinfra - directory: tests - enabled: False + directory: ../default/tests + enabled: True lint: name: flake8 enabled: True diff --git a/molecule/db-mariadb/tests/test_default.py b/molecule/db-mariadb/tests/test_default.py deleted file mode 100644 index eedd64a1d3d5c5f97f055b53c500cee079b02711..0000000000000000000000000000000000000000 --- a/molecule/db-mariadb/tests/test_default.py +++ /dev/null @@ -1,14 +0,0 @@ -import os - -import testinfra.utils.ansible_runner - -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') - - -def test_hosts_file(host): - f = host.file('/etc/hosts') - - assert f.exists - assert f.user == 'root' - assert f.group == 'root' diff --git a/molecule/db-postgresql/molecule.yml b/molecule/db-postgresql/molecule.yml index 0ff1c62447a8b5cff6727bf8464850ac88dc92f1..5edc7f5d669c64a89235fef378c227c1030d9c28 100644 --- a/molecule/db-postgresql/molecule.yml +++ b/molecule/db-postgresql/molecule.yml @@ -49,8 +49,8 @@ provisioner: verifier: name: testinfra - directory: tests - enabled: False + directory: ../default/tests + enabled: True lint: name: flake8 enabled: True diff --git a/molecule/db-postgresql/tests/test_default.py b/molecule/db-postgresql/tests/test_default.py deleted file mode 100644 index eedd64a1d3d5c5f97f055b53c500cee079b02711..0000000000000000000000000000000000000000 --- a/molecule/db-postgresql/tests/test_default.py +++ /dev/null @@ -1,14 +0,0 @@ -import os - -import testinfra.utils.ansible_runner - -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') - - -def test_hosts_file(host): - f = host.file('/etc/hosts') - - assert f.exists - assert f.user == 'root' - assert f.group == 'root' diff --git a/molecule/default/tests/test_icinga.py b/molecule/default/tests/test_icinga2.py similarity index 51% rename from molecule/default/tests/test_icinga.py rename to molecule/default/tests/test_icinga2.py index c009ae0bc2bba751e52390b8df0d94bbeee94329..09c8cebdb9f02a7e36c43d616a5541e05d4ed95b 100644 --- a/molecule/default/tests/test_icinga.py +++ b/molecule/default/tests/test_icinga2.py @@ -1,6 +1,11 @@ def test_icinga2_is_installed(host): - package = host.package("icinga2") - assert package.is_installed + for item in [ + 'icinga2', + 'monitoring-plugins', + 'vim-icinga2' + ]: + package = host.package(item) + assert package.is_installed def test_icinga2_running_and_enabled(host): diff --git a/molecule/default/tests/test_igincaweb2.py b/molecule/default/tests/test_igincaweb2.py new file mode 100644 index 0000000000000000000000000000000000000000..fb471d2e761af68e26fea06263fd95649c01142f --- /dev/null +++ b/molecule/default/tests/test_igincaweb2.py @@ -0,0 +1,35 @@ +def test_icingaweb2_is_installed(host): + for item in [ + 'icingaweb2', + 'nginx-full', + 'icingacli', + 'php-gd', + 'php-fpm', + 'php-ldap', + 'php-imagick', + 'php-intl' + ]: + package = host.package(item) + assert package.is_installed + + +def test_nginx_running_and_enabled(host): + service = host.service("nginx") + assert service.is_running + assert service.is_enabled + + +def test_phpfpm_running_and_enabled(host): + service = host.service("php7.0-fpm") + assert service.is_running + assert service.is_enabled + + +def test_icingaweb2_is_listening_http(host): + socket = host.socket("tcp://127.0.0.1:80") + assert socket.is_listening + + +def test_icingaweb2_is_listening_https(host): + socket = host.socket("tcp://127.0.0.1:443") + assert socket.is_listening diff --git a/molecule/default/tests/test_sslcerts.py b/molecule/default/tests/test_sslcerts.py new file mode 100644 index 0000000000000000000000000000000000000000..646c693e6d2187de88f57a4903e1a27196e6c14c --- /dev/null +++ b/molecule/default/tests/test_sslcerts.py @@ -0,0 +1,28 @@ +import pytest + + +@pytest.mark.parametrize("file,user,group,mode", [ + ("ca.crt", "nagios", "nagios", 0o400), + ("molecule_debian9.crt", "nagios", "nagios", 0o400), + ("molecule_debian9.key", "nagios", "nagios", 0o400), +]) +def test_sslcerts_icinga2_files(host, file, user, group, mode): + file = host.file("/var/lib/icinga2/certs/" + file) + assert file.exists + assert file.is_file + assert file.user == user + assert file.group == group + assert file.mode == mode + + +@pytest.mark.parametrize("file,user,group,mode", [ + ("/etc/ssl/private/icinga-test-molecule-host.key", "root", "root", 0o640), + ("/etc/ssl/certs/icinga-test-molecule-host.crt", "root", "root", 0o644), +]) +def test_sslcerts_icingaweb2_files(host, file, user, group, mode): + file = host.file(file) + assert file.exists + assert file.is_file + assert file.user == user + assert file.group == group + assert file.mode == mode diff --git a/tasks/install-icinga-web.yml b/tasks/install-icinga-web.yml index 0d453d45f4442614bc4b75abcb24313caf911cd2..4d4582b6a38751e4839e562d7b72969116e4e828 100644 --- a/tasks/install-icinga-web.yml +++ b/tasks/install-icinga-web.yml @@ -2,7 +2,7 @@ - name: "Installing Icinga web packages" become: yes apt: - name: ['icingaweb2', 'nginx-full', 'icingacli', 'php-gd', 'php-fpm', 'php-ldap', 'php-mysql', 'php-pgsql', 'php-imagick', 'php-intl'] + name: ['icingaweb2', 'nginx-full', 'icingacli', 'php-gd', 'php-fpm', 'php-ldap', 'php-imagick', 'php-intl'] state: present update_cache: yes install_recommends: no