Browse Source

Use novaclient API instead of CLI for services check

Use novaclient API instead of CLI for services check
Closes-bug: #1615766

Change-Id: I691b434a54298b6ebeffa27470ed0fd354e06013
Alexey Stepanov 2 years ago
parent
commit
a993603408
2 changed files with 25 additions and 17 deletions
  1. 2
    2
      fuel_health/nmanager.py
  2. 23
    15
      fuel_health/tests/sanity/test_sanity_infrastructure.py

+ 2
- 2
fuel_health/nmanager.py View File

@@ -1261,8 +1261,8 @@ class SanityChecksTest(OfficialClientTest):
1261 1261
         limits = client.limits.get()
1262 1262
         return limits
1263 1263
 
1264
-    def _list_services(self, client):
1265
-        services = client.services.list()
1264
+    def _list_services(self, client, host=None, binary=None):
1265
+        services = client.services.list(host=host, binary=binary)
1266 1266
         return services
1267 1267
 
1268 1268
     def _list_users(self, client):

+ 23
- 15
fuel_health/tests/sanity/test_sanity_infrastructure.py View File

@@ -58,32 +58,40 @@ class SanityInfrastructureTest(nmanager.SanityChecksTest):
58 58
         Duration: 180 s.
59 59
         """
60 60
         downstate = u'down'
61
-        cmd = "source /root/openrc"
62
-        for controller in self.controller_names:
63
-            cmd += '; nova service-list --host {0}'.format(controller)
61
+
62
+        def get_controllers_down_states():
63
+            states = {}
64
+            for controller in self.controller_names:
65
+                svc = self._list_services(self.compute_client, host=controller)
66
+                down = [True for service in svc if service.state == downstate]
67
+                if any(down):
68
+                    states[controller] = True
69
+            return states
64 70
 
65 71
         if not self.controllers:
66 72
             self.skipTest('Step 1 failed: there are no controller nodes.')
67
-        ssh_client = SSHClient(self.controllers[0],
68
-                               self.usr, self.pwd,
69
-                               key_filename=self.key,
70
-                               timeout=self.timeout)
71
-        output = self.verify(50, ssh_client.exec_command, 1,
72
-                             "'nova service-list' command execution failed. ",
73
-                             "'nova service-list' command execution",
74
-                             cmd)
73
+
74
+        output = self.verify(
75
+            50, get_controllers_down_states, 1,
76
+            "'nova service-list' command execution failed. ",
77
+            "'nova service-list' command execution",
78
+        )
79
+
75 80
         LOG.debug(output)
76 81
         try:
77 82
             self.verify_response_true(
78
-                downstate not in output, 'Step 2 failed: Some nova services '
79
-                'have not been started.')
83
+                len(output) == 0,
84
+                'Step 2 failed: Some nova services have not been started.')
80 85
         except Exception:
81 86
             LOG.info("Will sleep for 120 seconds and try again")
82 87
             LOG.exception()
83 88
             time.sleep(120)
89
+            # Re-collect data silently
90
+            output = get_controllers_down_states()
91
+            LOG.debug(output)
84 92
             self.verify_response_true(
85
-                downstate not in output, 'Step 2 failed: Some nova services '
86
-                'have not been started.')
93
+                len(output) == 0,
94
+                'Step 2 failed: Some nova services have not been started.')
87 95
 
88 96
     def test_002_internet_connectivity_from_compute(self):
89 97
         """Check internet connectivity from a compute

Loading…
Cancel
Save