Count all active hypervisors 57/68557/1
authorCédric Ollivier <cedric.ollivier@orange.com>
Mon, 30 Sep 2019 15:26:05 +0000 (17:26 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Mon, 30 Sep 2019 15:28:01 +0000 (17:28 +0200)
Else tempest_slow fails if one hypervisor is down (detected in ONAP
Openlab). It also improves Shaker, Rally and Vmtp which count them.

Change-Id: Iee7c20e0357d9237501c5c451580d8f6409ac86b
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
functest/core/singlevm.py
functest/opnfv_tests/openstack/rally/rally.py
functest/opnfv_tests/openstack/shaker/shaker.py
functest/opnfv_tests/openstack/tempest/tempest.py
functest/opnfv_tests/openstack/vmtp/vmtp.py
functest/tests/unit/openstack/rally/test_rally.py

index 0473a21..734eb22 100644 (file)
@@ -256,6 +256,14 @@ class VmReady1(tenantnetwork.TenantNetwork1):
                     self.__logger.debug(
                         "Orphan security group %s in use", sec_group.id)
 
+    def count_active_hypervisors(self):
+        """Count all hypervisors which are up."""
+        compute_cnt = 0
+        for hypervisor in self.orig_cloud.list_hypervisors():
+            if hypervisor['state'] == 'up':
+                compute_cnt += 1
+        return compute_cnt
+
     def run(self, **kwargs):
         """Boot the new VM
 
index d9fb1fb..95447c0 100644 (file)
@@ -517,7 +517,7 @@ class RallyBase(singlevm.VmReady2):
         shutil.copytree(task_macro, macro_dir)
 
         self.update_keystone_default_role()
-        self.compute_cnt = len(self.cloud.list_hypervisors())
+        self.compute_cnt = self.count_active_hypervisors()
         self.network_extensions = self.cloud.get_network_extensions()
         self.flavor_alt = self.create_flavor_alt()
         self.services = [service.name for service in
index 46a44c7..9a31a8b 100644 (file)
@@ -48,7 +48,7 @@ class Shaker(singlevm.SingleVm2):
         self.role = None
 
     def check_requirements(self):
-        if len(self.orig_cloud.list_hypervisors()) < 2:
+        if self.count_active_hypervisors() < 2:
             self.__logger.warning("Shaker requires at least 2 hypervisors")
             self.is_skipped = True
             self.project.clean()
index a6ec568..6d13bd2 100644 (file)
@@ -567,8 +567,7 @@ class TempestCommon(singlevm.VmReady2):
         self.deployment_dir = self.get_verifier_deployment_dir(
             self.verifier_id, self.deployment_id)
 
-        compute_cnt = len(self.orig_cloud.list_hypervisors())
-
+        compute_cnt = self.count_active_hypervisors()
         self.image_alt = self.publish_image_alt()
         self.flavor_alt = self.create_flavor_alt()
         LOGGER.debug("flavor: %s", self.flavor_alt)
index d102f64..fa83c45 100644 (file)
@@ -60,7 +60,7 @@ class Vmtp(singlevm.VmReady2):
         (_, self.pubkey_filename) = tempfile.mkstemp()
 
     def check_requirements(self):
-        if len(self.orig_cloud.list_hypervisors()) < 2:
+        if self.count_active_hypervisors() < 2:
             self.__logger.warning("Vmtp requires at least 2 hypervisors")
             self.is_skipped = True
             self.project.clean()
index c5cd501..c430e97 100644 (file)
@@ -291,8 +291,8 @@ class OSRallyTesting(unittest.TestCase):
     def test_prepare_run_flavor_alt_creation_failed(self, *args):
         # pylint: disable=unused-argument
         self.rally_base.stests = ['test1', 'test2']
-        with mock.patch.object(self.rally_base.cloud,
-                               'list_hypervisors') as mock_list_hyperv, \
+        with mock.patch.object(self.rally_base, 'count_active_hypervisors') \
+            as mock_list_hyperv, \
             mock.patch.object(self.rally_base, 'create_flavor_alt',
                               side_effect=Exception) \
                 as mock_create_flavor: