Merge "Reduce Nova API calls in the host polling monitor"
This commit is contained in:
commit
79f8db688e
|
@ -696,19 +696,17 @@ class PhysicalHostMonitorPlugin(base.BaseMonitorPlugin,
|
|||
|
||||
:return: a list of failed hosts.
|
||||
"""
|
||||
failed_hosts = []
|
||||
hosts = db_api.reservable_host_get_all_by_queries([])
|
||||
for host in hosts:
|
||||
with trusts.create_ctx_from_trust(host['trust_id']):
|
||||
try:
|
||||
hv = self.nova.hypervisors.get(host['id'])
|
||||
LOG.debug('%s: state=%s, status=%s.',
|
||||
hv.hypervisor_hostname, hv.state, hv.status)
|
||||
if hv.state == 'down' or hv.status == 'disabled':
|
||||
failed_hosts.append(host)
|
||||
except Exception as e:
|
||||
LOG.exception('Skipping health check of host %s. %s',
|
||||
host['hypervisor_hostname'], str(e))
|
||||
reservable_hosts = db_api.reservable_host_get_all_by_queries([])
|
||||
|
||||
try:
|
||||
hvs = self.nova.hypervisors.list()
|
||||
failed_hv_ids = [str(hv.id) for hv in hvs
|
||||
if hv.state == 'down' or hv.status == 'disabled']
|
||||
failed_hosts = [host for host in reservable_hosts
|
||||
if host['id'] in failed_hv_ids]
|
||||
except Exception as e:
|
||||
LOG.exception('Skipping health check of host %s. %s',
|
||||
host['hypervisor_hostname'], str(e))
|
||||
|
||||
return failed_hosts
|
||||
|
||||
|
|
|
@ -1670,9 +1670,6 @@ class PhysicalHostMonitorPluginTestCase(tests.TestCase):
|
|||
def setUp(self):
|
||||
super(PhysicalHostMonitorPluginTestCase, self).setUp()
|
||||
self.patch(nova_client, 'Client')
|
||||
self.patch(base, 'url_for').return_value = 'http://foo.bar'
|
||||
self.patch(context, 'BlazarContext')
|
||||
self.patch(trusts, 'create_ctx_from_trust')
|
||||
self.host_monitor_plugin = host_plugin.PhysicalHostMonitorPlugin()
|
||||
|
||||
def test_notification_callback_disabled_true(self):
|
||||
|
@ -1751,10 +1748,11 @@ class PhysicalHostMonitorPluginTestCase(tests.TestCase):
|
|||
host_get_all = self.patch(db_api,
|
||||
'reservable_host_get_all_by_queries')
|
||||
host_get_all.return_value = hosts
|
||||
hypervisor_get = self.patch(self.host_monitor_plugin.nova.hypervisors,
|
||||
'get')
|
||||
hypervisor_get.return_value = mock.MagicMock(state='down',
|
||||
status='enabled')
|
||||
hypervisors_list = self.patch(
|
||||
self.host_monitor_plugin.nova.hypervisors, 'list')
|
||||
hypervisors_list.return_value = [
|
||||
mock.MagicMock(id=1, state='down', status='enabled'),
|
||||
mock.MagicMock(id=2, state='down', status='enabled')]
|
||||
|
||||
result = self.host_monitor_plugin._poll_resource_failures()
|
||||
self.assertEqual(hosts, result)
|
||||
|
@ -1772,10 +1770,11 @@ class PhysicalHostMonitorPluginTestCase(tests.TestCase):
|
|||
host_get_all = self.patch(db_api,
|
||||
'reservable_host_get_all_by_queries')
|
||||
host_get_all.return_value = hosts
|
||||
hypervisor_get = self.patch(self.host_monitor_plugin.nova.hypervisors,
|
||||
'get')
|
||||
hypervisor_get.return_value = mock.MagicMock(state='up',
|
||||
status='disabled')
|
||||
hypervisors_list = self.patch(
|
||||
self.host_monitor_plugin.nova.hypervisors, 'list')
|
||||
hypervisors_list.return_value = [
|
||||
mock.MagicMock(id=1, state='up', status='disabled'),
|
||||
mock.MagicMock(id=2, state='up', status='disabled')]
|
||||
|
||||
result = self.host_monitor_plugin._poll_resource_failures()
|
||||
self.assertEqual(hosts, result)
|
||||
|
@ -1793,10 +1792,11 @@ class PhysicalHostMonitorPluginTestCase(tests.TestCase):
|
|||
host_get_all = self.patch(db_api,
|
||||
'reservable_host_get_all_by_queries')
|
||||
host_get_all.return_value = hosts
|
||||
hypervisor_get = self.patch(self.host_monitor_plugin.nova.hypervisors,
|
||||
'get')
|
||||
hypervisor_get.return_value = mock.MagicMock(state='up',
|
||||
status='enabled')
|
||||
hypervisors_list = self.patch(
|
||||
self.host_monitor_plugin.nova.hypervisors, 'list')
|
||||
hypervisors_list.return_value = [
|
||||
mock.MagicMock(id=1, state='up', status='enabled'),
|
||||
mock.MagicMock(id=2, state='up', status='enabled')]
|
||||
|
||||
result = self.host_monitor_plugin._poll_resource_failures()
|
||||
self.assertEqual([], result)
|
||||
|
|
|
@ -57,9 +57,10 @@ class TestCNClient(tests.TestCase):
|
|||
user_domain = 'User_Domain'
|
||||
project_name = 'admin'
|
||||
project_domain = 'Project_Domain'
|
||||
auth_url = "%s://%s:%s/v3" % (CONF.os_auth_protocol,
|
||||
auth_url = "%s://%s:%s/%s" % (CONF.os_auth_protocol,
|
||||
CONF.os_auth_host,
|
||||
CONF.os_auth_port)
|
||||
CONF.os_auth_port,
|
||||
CONF.os_auth_prefix)
|
||||
|
||||
kwargs = {'version': self.version,
|
||||
'endpoint_override': endpoint,
|
||||
|
|
|
@ -126,9 +126,10 @@ class BlazarNovaClient(object):
|
|||
os_region_name=CONF.os_region_name)
|
||||
|
||||
if auth_url is None:
|
||||
auth_url = "%s://%s:%s/v3" % (CONF.os_auth_protocol,
|
||||
auth_url = "%s://%s:%s/%s" % (CONF.os_auth_protocol,
|
||||
CONF.os_auth_host,
|
||||
CONF.os_auth_port)
|
||||
CONF.os_auth_port,
|
||||
CONF.os_auth_prefix)
|
||||
|
||||
if username:
|
||||
kwargs.setdefault('username', username)
|
||||
|
@ -191,9 +192,7 @@ class NovaClientWrapper(object):
|
|||
|
||||
@property
|
||||
def nova(self):
|
||||
ctx = context.current()
|
||||
nova = BlazarNovaClient(ctx=ctx,
|
||||
username=self.username,
|
||||
nova = BlazarNovaClient(username=self.username,
|
||||
password=self.password,
|
||||
user_domain_name=self.user_domain_name,
|
||||
project_name=self.project_name,
|
||||
|
|
Loading…
Reference in New Issue