Repository: ManageIQ/integration_tests

Issue:
[1LP][RFR] Move convenience methods to use SystemdService plugin for appliance
{{ pytest: --long-running cfme/tests/ansible/test_embedded_ansible_crud.py  }}

There is some flaky behavior in the new tests checking for some EmbeddedAnsible process. @sbulage is going to address these test failures. I've changed the fixture name here, but that's unrelated to the process state changes that cause the test to fail.


Discussion:
LGTM at First sight.
good idea to turn those in services.  PR looks good but PRT failed due to sprout. I restarted PRT

Resolving patch:
diff --git a/cfme/utils/appliance/__init__.py b/cfme/utils/appliance/__init__.py
--- a/cfme/utils/appliance/__init__.py
+++ b/cfme/utils/appliance/__init__.py
@@ -1754,6 +1754,12 @@ def ansible_pod_name(self):
         else:
             return None
 
+    @property
+    def is_ansible_pod_stopped(self):
+        return self.ssh_client.run_command(
+            "oc get pods|grep ansible", ensure_host=True
+        ).failed
+
     @property
     def is_embedded_ansible_role_enabled(self):
         return self.server_roles.get("embedded_ansible", False)
diff --git a/cfme/utils/appliance/services.py b/cfme/utils/appliance/services.py
--- a/cfme/utils/appliance/services.py
+++ b/cfme/utils/appliance/services.py
@@ -51,7 +51,6 @@ def _run_service_command(
             else:
                 self.logger.error(msg)
             raise SystemdException(msg)
-
         return result
 
     def stop(self, log_callback=None):
@@ -86,6 +85,14 @@ def enable(self, log_callback=None):
     def enabled(self):
         return self._run_service_command('is-enabled').rc == 0
 
+    @property
+    def is_active(self):
+        result = self._run_service_command("status")
+        if 'inactive' in result.output:
+            return False
+        else:
+            return True
+
     @property
     def running(self):
         return self._run_service_command("status").rc == 0


Test patch:
diff --git a/cfme/tests/ansible/test_embedded_ansible_crud.py b/cfme/tests/ansible/test_embedded_ansible_crud.py
--- a/cfme/tests/ansible/test_embedded_ansible_crud.py
+++ b/cfme/tests/ansible/test_embedded_ansible_crud.py
@@ -3,17 +3,15 @@
 from cfme import test_requirements
 from cfme.utils.log import logger
 from cfme.utils.wait import wait_for
-from cfme.utils.wait import wait_for_decorator
 
 pytestmark = [
     pytest.mark.ignore_stream("upstream"),
-    test_requirements.ansible,
+    test_requirements.ansible
 ]
 
 
-@pytest.fixture(scope='module')
+@pytest.fixture(scope="function")
 def embedded_appliance(appliance):
-    """Enables embedded ansible role via UI"""
     appliance.enable_embedded_ansible_role()
     assert appliance.is_embedded_ansible_running
     yield appliance
@@ -32,13 +30,15 @@ def test_embedded_ansible_enable(embedded_appliance):
         tags: ansible_embed
     """
     assert wait_for(lambda: embedded_appliance.is_embedded_ansible_running, num_sec=30)
+    assert wait_for(lambda: embedded_appliance.supervisord.is_active, num_sec=30)
     assert wait_for(lambda: embedded_appliance.rabbitmq_server.running, num_sec=30)
     assert wait_for(lambda: embedded_appliance.nginx.running, num_sec=30)
     endpoint = "api" if embedded_appliance.is_pod else "ansibleapi"
 
     assert embedded_appliance.ssh_client.run_command(
         'curl -kL https://localhost/{endp} | grep "AWX REST API"'.format(endp=endpoint),
-        container=embedded_appliance.ansible_pod_name)
+        container=embedded_appliance.ansible_pod_name,
+    )
 
 
 @pytest.mark.tier(3)
@@ -57,21 +57,15 @@ def test_embedded_ansible_disable(embedded_appliance):
     embedded_appliance.disable_embedded_ansible_role()
 
     if not embedded_appliance.is_pod:
-        assert wait_for(lambda: embedded_appliance.supervisord.running,
-                        fail_cond=True,
-                        num_sec=180)
-        assert wait_for(lambda: embedded_appliance.rabbitmq_server.running,
-                        fail_cond=True,
-                        num_sec=60)
-        assert wait_for(lambda: embedded_appliance.nginx.running,
-                        fail_cond=True,
-                        num_sec=30)
+        assert wait_for(
+            lambda: not embedded_appliance.supervisord.is_active, num_sec=180
+        )
+        assert wait_for(
+            lambda: not embedded_appliance.rabbitmq_server.is_active, num_sec=80
+        )
+        assert wait_for(lambda: not embedded_appliance.nginx.is_active, num_sec=30)
     else:
-        @wait_for_decorator(num_sec=300)
-        def is_ansible_pod_stopped():
-            # todo: implement appropriate methods in appliance
-            return embedded_appliance.ssh_client.run_command(
-                'oc get pods|grep ansible', ensure_host=True).failed
+        assert wait_for(lambda: embedded_appliance.is_ansible_pod_stopped, num_sec=300)
 
 
 @pytest.mark.tier(1)
@@ -121,9 +115,7 @@ def test_embedded_ansible_logs(embedded_appliance):
     ]
 
     # Asserting log folder is present
-    tower_log_folder = embedded_appliance.ssh_client.run_command(
-        "ls /var/log/tower/"
-    )
+    tower_log_folder = embedded_appliance.ssh_client.run_command("ls /var/log/tower/")
     assert tower_log_folder.success
 
     logs = tower_log_folder.output.splitlines()