summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2019-06-12 12:49:25 +0200
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2019-06-12 12:49:25 +0200
commit3e0d6de04fb148e3409bf37615aa8ded631ed2f2 (patch)
tree20e9fceacbbf53858e31cbf434a8eef36b9c67e3
parent0d4f60a5e1125e308311ad675b4f60a385569a2e (diff)
Add verification tests for 'chrony' role
Testinfra tests are added for Molecule verifier. Change-Id: Id044cdc5535af97ce3ac48da034a9a6a1ca8cbd3 Issue-ID: OOM-1810 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
-rw-r--r--ansible/roles/chrony/molecule/default/tests/test_default.py42
-rw-r--r--ansible/roles/chrony/molecule/ubuntu/molecule.yml3
2 files changed, 45 insertions, 0 deletions
diff --git a/ansible/roles/chrony/molecule/default/tests/test_default.py b/ansible/roles/chrony/molecule/default/tests/test_default.py
new file mode 100644
index 00000000..08f85d37
--- /dev/null
+++ b/ansible/roles/chrony/molecule/default/tests/test_default.py
@@ -0,0 +1,42 @@
+import os
+import pytest
+
+import testinfra.utils.ansible_runner
+
+testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
+ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
+
+
+@pytest.fixture
+def chrony_conf_file(host, os_family):
+ conf = host.ansible('include_vars', 'file=../../defaults/main.yml')[
+ 'ansible_facts']['chrony']['conf'][os_family]['config_file']
+ return conf
+
+
+@pytest.fixture
+def os_family(host):
+ osf = host.ansible("setup")['ansible_facts']['ansible_os_family']
+ return osf
+
+
+def test_chrony_conf_file_exists(host, chrony_conf_file):
+ assert host.file(chrony_conf_file).exists, 'Config file not found!'
+
+
+def test_chrony_service_running_enabled(host):
+ assert host.service('chronyd').is_running, \
+ 'Chronyd service is not running!'
+ assert host.service('chronyd').is_enabled, \
+ 'Chronyd service is not enabled!'
+
+
+def test_ntp_synchronized(host, chrony_conf_file):
+ assert host.file(chrony_conf_file).exists, 'Config file not found!'
+ if host.file(chrony_conf_file).contains("server "):
+ out = host.check_output('systemctl status chronyd')
+ assert 'Selected source' in out, \
+ 'Chronyd did not synchronize with NTP server.'
+ else:
+ # Host acts as a time source
+ pass
diff --git a/ansible/roles/chrony/molecule/ubuntu/molecule.yml b/ansible/roles/chrony/molecule/ubuntu/molecule.yml
index dd2b9655..e7ede8c7 100644
--- a/ansible/roles/chrony/molecule/ubuntu/molecule.yml
+++ b/ansible/roles/chrony/molecule/ubuntu/molecule.yml
@@ -37,3 +37,6 @@ verifier:
name: testinfra
lint:
name: flake8
+ options:
+ v: 1
+ directory: ../default/tests/