Merge "change nova.services.disable use service_uuid"

This commit is contained in:
Zuul 2019-01-22 04:30:07 +00:00 committed by Gerrit Code Review
commit f1e074e29b
3 changed files with 21 additions and 10 deletions

View File

@ -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):

View File

@ -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):

View File

@ -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):