diff --git a/nova/scheduler/filters/compute_filter.py b/nova/scheduler/filters/compute_filter.py index 523836d30962..643ce7221619 100644 --- a/nova/scheduler/filters/compute_filter.py +++ b/nova/scheduler/filters/compute_filter.py @@ -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 diff --git a/nova/tests/scheduler/test_host_filters.py b/nova/tests/scheduler/test_host_filters.py index dcfe75c2590a..9cc5ff46ab87 100644 --- a/nova/tests/scheduler/test_host_filters.py +++ b/nova/tests/scheduler/test_host_filters.py @@ -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']() diff --git a/nova/tests/virt/xenapi/test_xenapi.py b/nova/tests/virt/xenapi/test_xenapi.py index 655339b214d0..a4cffda9178d 100644 --- a/nova/tests/virt/xenapi/test_xenapi.py +++ b/nova/tests/virt/xenapi/test_xenapi.py @@ -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') diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index a6c74d19627c..4905697c1ec5 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -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)