summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--heat/engine/clients/os/nova.py19
-rw-r--r--heat/tests/clients/test_nova_client.py33
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):