Merge "Add get_compute_node_by_uuid"

This commit is contained in:
Zuul
2019-07-13 08:42:07 +00:00
committed by Gerrit Code Review
2 changed files with 20 additions and 0 deletions

View File

@@ -86,6 +86,14 @@ class NovaHelper(object):
LOG.exception(exc)
raise exception.ComputeNodeNotFound(name=node_hostname)
def get_compute_node_by_uuid(self, node_uuid):
"""Get compute node by uuid
:param node_uuid: hypervisor id as uuid after microversion 2.53
:returns: novaclient.v2.hypervisors.Hypervisor object if found
"""
return self.nova.hypervisors.get(node_uuid)
def get_instance_list(self, filters=None, marker=None, limit=-1):
"""List servers for all tenants with details.

View File

@@ -162,6 +162,18 @@ class TestNovaHelper(base.TestCase):
result = nova_util.get_compute_node_by_hostname(name)
self.assertIs(nodes[index], result)
def test_get_compute_node_by_uuid(
self, mock_glance, mock_cinder, mock_neutron, mock_nova):
nova_util = nova_helper.NovaHelper()
hypervisor_id = utils.generate_uuid()
hypervisor_name = "fake_hypervisor_1"
hypervisor = self.fake_hypervisor(hypervisor_id, hypervisor_name)
nova_util.nova.hypervisors.get.return_value = hypervisor
# verify that the compute node can be obtained normally by id
self.assertEqual(
nova_util.get_compute_node_by_uuid(hypervisor_id),
hypervisor)
def test_get_instance_list(self, *args):
nova_util = nova_helper.NovaHelper()
# Call it once with no filters.