Merge changes from topic "OOM-1810"
authorPetr OspalĂ˝ <p.ospaly@partner.samsung.com>
Fri, 14 Jun 2019 09:08:34 +0000 (09:08 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 14 Jun 2019 09:08:34 +0000 (09:08 +0000)
* changes:
  Add verification tests for 'chrony' role
  Setup 'cluster_ip' fact for infra host in 'chrony' role tests

ansible/roles/chrony/molecule/default/playbook.yml
ansible/roles/chrony/molecule/default/tests/test_default.py [new file with mode: 0644]
ansible/roles/chrony/molecule/ubuntu/molecule.yml

index 7dccfc3..717d0f3 100644 (file)
@@ -1,6 +1,10 @@
 ---
 - name: Converge infrastructure hosts
   hosts: infrastructure
+  tasks:
+    - name: Set cluster_ip fact
+      set_fact:
+        cluster_ip: "{{ ansible_default_ipv4.address }}"
   roles:
     - chrony
 
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 (file)
index 0000000..08f85d3
--- /dev/null
@@ -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
index dd2b965..e7ede8c 100644 (file)
@@ -37,3 +37,6 @@ verifier:
   name: testinfra
   lint:
     name: flake8
+  options:
+    v: 1
+  directory: ../default/tests/