Make xenapi capabilities['enabled'] use service enabled
filters.compute_filter is enabled by default along with libvirt, but the capabilities['enabled'] section of it is only supported by XenAPI. This used to work by adding a parameter to capabilities, but since the capabilities RPC is being removed, use conductor.service_update to tell the scheduler which host is disabled. service_update is already the way to tell the scheduler about other disabled hosts, so to keep backwards compatibility keep host_enabled but use service_update underneath. Part of bp no-compute-fanout-to-scheduler Change-Id: Ica1919cfe9a2402b2107c557c10d47e01a6c430b
This commit is contained in:
parent
431de91573
commit
241829b3ef
@ -36,7 +36,6 @@ class ComputeFilter(filters.BaseHostFilter):
|
||||
|
||||
def host_passes(self, host_state, filter_properties):
|
||||
"""Returns True for only active compute nodes."""
|
||||
capabilities = host_state.capabilities
|
||||
service = host_state.service
|
||||
|
||||
alive = self.servicegroup_api.service_is_up(service)
|
||||
@ -44,8 +43,4 @@ class ComputeFilter(filters.BaseHostFilter):
|
||||
LOG.debug(_("%(host_state)s is disabled or has not been "
|
||||
"heard from in a while"), {'host_state': host_state})
|
||||
return False
|
||||
if not capabilities.get("enabled", True):
|
||||
LOG.debug(_("%(host_state)s is disabled via capabilities"),
|
||||
{'host_state': host_state})
|
||||
return False
|
||||
return True
|
||||
|
@ -671,17 +671,6 @@ class HostFiltersTestCase(test.NoDBTestCase):
|
||||
'service': service})
|
||||
self.assertFalse(filt_cls.host_passes(host, filter_properties))
|
||||
|
||||
def test_compute_filter_fails_on_capability_disabled(self):
|
||||
self._stub_service_is_up(True)
|
||||
filt_cls = self.class_map['ComputeFilter']()
|
||||
filter_properties = {'instance_type': {'memory_mb': 1024}}
|
||||
capabilities = {'enabled': False}
|
||||
service = {'disabled': False}
|
||||
host = fakes.FakeHostState('host1', 'node1',
|
||||
{'free_ram_mb': 1024, 'capabilities': capabilities,
|
||||
'service': service})
|
||||
self.assertFalse(filt_cls.host_passes(host, filter_properties))
|
||||
|
||||
def test_image_properties_filter_passes_same_inst_props(self):
|
||||
self._stub_service_is_up(True)
|
||||
filt_cls = self.class_map['ImagePropertiesFilter']()
|
||||
|
@ -1959,6 +1959,8 @@ class XenAPIHostTestCase(stubs.XenAPITestBase):
|
||||
self.flags(xenapi_connection_url='test_url',
|
||||
xenapi_connection_password='test_pass')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
self.context = context.get_admin_context()
|
||||
self.flags(use_local=True, group='conductor')
|
||||
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
|
||||
def test_host_state(self):
|
||||
@ -2004,10 +2006,18 @@ class XenAPIHostTestCase(stubs.XenAPITestBase):
|
||||
False, 'off_maintenance')
|
||||
|
||||
def test_set_enable_host_enable(self):
|
||||
values = _create_service_entries(self.context, values={'nova':
|
||||
['host']})
|
||||
self._test_host_action(self.conn.set_host_enabled, True, 'enabled')
|
||||
service = db.service_get_by_args(self.context, 'host', 'nova-compute')
|
||||
self.assertEquals(service.disabled, False)
|
||||
|
||||
def test_set_enable_host_disable(self):
|
||||
values = _create_service_entries(self.context, values={'nova':
|
||||
['host']})
|
||||
self._test_host_action(self.conn.set_host_enabled, False, 'disabled')
|
||||
service = db.service_get_by_args(self.context, 'host', 'nova-compute')
|
||||
self.assertEquals(service.disabled, True)
|
||||
|
||||
def test_get_host_uptime(self):
|
||||
result = self.conn.get_host_uptime('host')
|
||||
|
@ -21,6 +21,7 @@ Management class for host-related functions (start, reboot, etc).
|
||||
|
||||
from nova.compute import task_states
|
||||
from nova.compute import vm_states
|
||||
from nova import conductor
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova.objects import instance as instance_obj
|
||||
@ -40,6 +41,7 @@ class Host(object):
|
||||
def __init__(self, session, virtapi):
|
||||
self._session = session
|
||||
self._virtapi = virtapi
|
||||
self._conductor_api = conductor.API()
|
||||
|
||||
def host_power_action(self, _host, action):
|
||||
"""Reboots or shuts down the host."""
|
||||
@ -112,8 +114,23 @@ class Host(object):
|
||||
raise exception.NoValidHost(reason='Unable to find suitable '
|
||||
'host for VMs evacuation')
|
||||
|
||||
def set_host_enabled(self, _host, enabled):
|
||||
def set_host_enabled(self, host, enabled):
|
||||
"""Sets the specified host's ability to accept new instances."""
|
||||
# Since capabilities are gone, use service table to disable a node
|
||||
# in scheduler
|
||||
status = {'disabled': not enabled,
|
||||
'disabled_reason': 'set by xenapi host_state'
|
||||
}
|
||||
cntxt = context.get_admin_context()
|
||||
service = self._conductor_api.service_get_by_args(
|
||||
cntxt,
|
||||
host,
|
||||
'nova-compute')
|
||||
self._conductor_api.service_update(
|
||||
cntxt,
|
||||
service,
|
||||
status)
|
||||
|
||||
args = {"enabled": jsonutils.dumps(enabled)}
|
||||
response = call_xenhost(self._session, "set_host_enabled", args)
|
||||
return response.get("status", response)
|
||||
|
Loading…
Reference in New Issue
Block a user