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 aab68ced6a
)
This commit is contained in:
parent
d5d8f74e6d
commit
40a3494c86
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
my_host.hypervisor_hostname = my_hypervisor_hostname
|
||||
|
||||
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')
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue