diff --git a/masakari/compute/nova.py b/masakari/compute/nova.py index a3310ed9..72ee7cd0 100644 --- a/masakari/compute/nova.py +++ b/masakari/compute/nova.py @@ -149,19 +149,19 @@ class API(object): @translate_nova_exception def enable_disable_service(self, context, host_name, enable=False, reason=None): - """Enable or disable the service specified by hostname and binary.""" + """Enable or disable the service specified by nova service id.""" nova = novaclient(context) + service = nova.services.list(host=host_name, binary='nova-compute')[0] if not enable: LOG.info('Disable nova-compute on %s', host_name) if reason: - nova.services.disable_log_reason(host_name, 'nova-compute', - reason) + nova.services.disable_log_reason(service.id, reason) else: - nova.services.disable(host_name, 'nova-compute') + nova.services.disable(service.id) else: LOG.info('Enable nova-compute on %s', host_name) - nova.services.enable(host_name, 'nova-compute') + nova.services.enable(service.id) @translate_nova_exception def is_service_down(self, context, host_name, binary): diff --git a/masakari/tests/unit/compute/test_nova.py b/masakari/tests/unit/compute/test_nova.py index 86eb48ee..3b5b50a1 100644 --- a/masakari/tests/unit/compute/test_nova.py +++ b/masakari/tests/unit/compute/test_nova.py @@ -182,31 +182,40 @@ class NovaApiTestCase(test.TestCase): host = 'fake' mock_services = mock.MagicMock() mock_novaclient.return_value = mock.MagicMock(services=mock_services) + mock_services.list.return_value = [mock.MagicMock(id='fake_id')] self.api.enable_disable_service(self.ctx, host, enable=True) mock_novaclient.assert_called_once_with(self.ctx) - mock_services.enable.assert_called_once_with(host, 'nova-compute') + mock_services.list.assert_called_once_with(binary='nova-compute', + host='fake') + mock_services.enable.assert_called_once_with('fake_id') @mock.patch('masakari.compute.nova.novaclient') def test_enable_disable_service_disable(self, mock_novaclient): host = 'fake' mock_services = mock.MagicMock() mock_novaclient.return_value = mock.MagicMock(services=mock_services) + mock_services.list.return_value = [mock.MagicMock(id='fake_id')] self.api.enable_disable_service(self.ctx, host) mock_novaclient.assert_called_once_with(self.ctx) - mock_services.disable.assert_called_once_with(host, 'nova-compute') + mock_services.list.assert_called_once_with(binary='nova-compute', + host='fake') + mock_services.disable.assert_called_once_with('fake_id') @mock.patch('masakari.compute.nova.novaclient') def test_enable_disable_service_disable_reason(self, mock_novaclient): host = 'fake' mock_services = mock.MagicMock() mock_novaclient.return_value = mock.MagicMock(services=mock_services) + mock_services.list.return_value = [mock.MagicMock(id='fake_id')] self.api.enable_disable_service(self.ctx, host, reason='fake_reason') mock_novaclient.assert_called_once_with(self.ctx) + mock_services.list.assert_called_once_with(binary='nova-compute', + host='fake') mock_services.disable_log_reason.assert_called_once_with( - host, 'nova-compute', 'fake_reason') + 'fake_id', 'fake_reason') @mock.patch('masakari.compute.nova.novaclient') def test_is_service_down(self, mock_novaclient): diff --git a/masakari/tests/unit/fakes.py b/masakari/tests/unit/fakes.py index c7efd8c3..64455343 100644 --- a/masakari/tests/unit/fakes.py +++ b/masakari/tests/unit/fakes.py @@ -136,8 +136,10 @@ class FakeNovaClient(object): binary=binary, status=status)) - def disable(self, host_name, binary): - service = self.list(host=host_name, binary=binary)[0] + def disable(self, service_id): + for _service in self._services: + if _service.id == service_id: + service = _service service.status = 'disabled' def list(self, host=None, binary=None):