diff options
author | David J Peacock <david.j.peacock@gmail.com> | 2019-09-13 10:08:02 -0400 |
---|---|---|
committer | Balazs Gibizer <balazs.gibizer@est.tech> | 2021-09-10 09:49:42 +0000 |
commit | 40a3494c86c36fb4987f8b9a7c296f9411d1263b (patch) | |
tree | ba31f3959b8987485a9d8eb487669192bb75cf1f | |
parent | d5d8f74e6d9642c1df6a48dadb6ab828cf2ffe05 (diff) | |
download | heat-40a3494c86c36fb4987f8b9a7c296f9411d1263b.tar.gz |
Update get_hosts to use available API
os-hosts was deprecated in nova quite some time ago. This patch updates
get_hosts to use the available os-hypervisors functions.
Change-Id: I36421e9859a266f0278c1b5f2acb4ebbacbfca82
Story: 2006584
Task: 36708
bz: 1740567
(cherry picked from commit aab68ced6a84c9fa39adb2cb9bb19165e699ff3a)
-rw-r--r-- | heat/engine/clients/os/nova.py | 19 | ||||
-rw-r--r-- | heat/tests/clients/test_nova_client.py | 33 |
2 files changed, 22 insertions, 30 deletions
diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index c0f280bbf..e4b9e4904 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -281,20 +281,15 @@ class NovaClientPlugin(microversion_mixin.MicroversionMixin, return flavor - def get_host(self, host_name): - """Get the host id specified by name. + def get_host(self, hypervisor_hostname): + """Gets list of matching hypervisors by specified name. - :param host_name: the name of host to find - :returns: the list of match hosts - :raises exception.EntityNotFound: + :param hypervisor_hostname: the name of host to find + :returns: list of matching hypervisor hosts + :raises nova client exceptions.NotFound: """ - host_list = self.client().hosts.list() - for host in host_list: - if host.host_name == host_name and host.service == self.COMPUTE: - return host - - raise exception.EntityNotFound(entity='Host', name=host_name) + return self.client().hypervisors.search(hypervisor_hostname) def get_keypair(self, key_name): """Get the public key specified by :key_name: @@ -872,4 +867,6 @@ class FlavorConstraint(NovaBaseConstraint): class HostConstraint(NovaBaseConstraint): + expected_exceptions = (exceptions.NotFound,) + resource_getter_name = 'get_host' diff --git a/heat/tests/clients/test_nova_client.py b/heat/tests/clients/test_nova_client.py index 35e37cc61..e78f82667 100644 --- a/heat/tests/clients/test_nova_client.py +++ b/heat/tests/clients/test_nova_client.py @@ -118,28 +118,21 @@ class NovaClientPluginTest(NovaClientPluginTestCase): def test_get_host(self): """Tests the get_host function.""" - my_host_name = 'myhost' + my_hypervisor_hostname = 'myhost' my_host = mock.MagicMock() - my_host.host_name = my_host_name - my_host.service = 'compute' - - wrong_host = mock.MagicMock() - wrong_host.host_name = 'wrong_host' - wrong_host.service = 'compute' - self.nova_client.hosts.list.side_effect = [ - [my_host], - [wrong_host], - exception.EntityNotFound(entity='Host', name='nohost') + my_host.hypervisor_hostname = my_hypervisor_hostname + + self.nova_client.hypervisors.search.side_effect = [ + my_host, nova_exceptions.NotFound(404) ] - self.assertEqual(my_host, self.nova_plugin.get_host(my_host_name)) - self.assertRaises(exception.EntityNotFound, - self.nova_plugin.get_host, my_host_name) - self.assertRaises(exception.EntityNotFound, + self.assertEqual(my_host, + self.nova_plugin.get_host(my_hypervisor_hostname)) + self.assertRaises(nova_exceptions.NotFound, self.nova_plugin.get_host, 'nohost') - self.assertEqual(3, self.nova_client.hosts.list.call_count) - calls = [mock.call(), mock.call(), mock.call()] + self.assertEqual(2, self.nova_client.hypervisors.search.call_count) + calls = [mock.call('myhost'), mock.call('nohost')] self.assertEqual(calls, - self.nova_client.hosts.list.call_args_list) + self.nova_client.hypervisors.search.call_args_list) def test_get_keypair(self): """Tests the get_keypair function.""" @@ -558,7 +551,9 @@ class HostConstraintTest(common.HeatTestCase): def test_validation_error(self): self.mock_get_host.side_effect = exception.EntityNotFound( entity='Host', name='bar') - self.assertFalse(self.constraint.validate("bar", self.ctx)) + self.assertRaises( + exception.EntityNotFound, + self.constraint.validate, "bar", self.ctx) class KeypairConstraintTest(common.HeatTestCase): |