Added utility function to retrieve the names of all hosts with a hypervisor. 73/48973/1
authorspisarski <s.pisarski@cablelabs.com>
Thu, 14 Dec 2017 15:25:17 +0000 (08:25 -0700)
committerspisarski <s.pisarski@cablelabs.com>
Thu, 14 Dec 2017 15:25:17 +0000 (08:25 -0700)
Change-Id: I25b91c6eee78ebf35785c4884dded7c9ab2cc412
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
snaps/openstack/utils/nova_utils.py
snaps/openstack/utils/tests/nova_utils_tests.py

index 2d569e6..8297db9 100644 (file)
@@ -475,6 +475,21 @@ def get_availability_zone_hosts(nova, zone_name='nova'):
     return out
 
 
+def get_hypervisor_hosts(nova):
+    """
+    Returns the host names of all nova nodes with active hypervisors
+    :param nova: the Nova client
+    :return: a list of hypervisor host names
+    """
+    out = list()
+    hypervisors = nova.hypervisors.list()
+    for hypervisor in hypervisors:
+        if hypervisor.state == "up":
+            out.append(hypervisor.hypervisor_hostname)
+
+    return out
+
+
 def delete_vm_instance(nova, vm_inst):
     """
     Deletes a VM instance
index c4bc9cb..c7be5ef 100644 (file)
@@ -53,6 +53,16 @@ class NovaSmokeTests(OSComponentTestCase):
         # This should not throw an exception
         nova.flavors.list()
 
+    def test_nova_get_hypervisor_hosts(self):
+        """
+        Tests to ensure that get_hypervisors() function works.
+        """
+        nova = nova_utils.nova_client(self.os_creds)
+
+        hosts = nova_utils.get_hypervisor_hosts(nova)
+        # This should not throw an exception
+        self.assertGreaterEqual(len(hosts), 1)
+
     def test_nova_connect_fail(self):
         """
         Tests to ensure that the improper credentials cannot connect.