change nova.services.disable use service_uuid
nova_api_version has been bump to 2.53 in bug/1800073, with this version, nova-client only take service_uuid to disable service, args host_name and binary are no longer supported. Change-Id: I6ab942f657f8983a22c9e16747090399c01fc3f8 Closes-bug: 1811742
This commit is contained in:
parent
4808a2a3d3
commit
fc3c689912
|
@ -149,19 +149,19 @@ class API(object):
|
||||||
@translate_nova_exception
|
@translate_nova_exception
|
||||||
def enable_disable_service(self, context, host_name, enable=False,
|
def enable_disable_service(self, context, host_name, enable=False,
|
||||||
reason=None):
|
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)
|
nova = novaclient(context)
|
||||||
|
service = nova.services.list(host=host_name, binary='nova-compute')[0]
|
||||||
|
|
||||||
if not enable:
|
if not enable:
|
||||||
LOG.info('Disable nova-compute on %s', host_name)
|
LOG.info('Disable nova-compute on %s', host_name)
|
||||||
if reason:
|
if reason:
|
||||||
nova.services.disable_log_reason(host_name, 'nova-compute',
|
nova.services.disable_log_reason(service.id, reason)
|
||||||
reason)
|
|
||||||
else:
|
else:
|
||||||
nova.services.disable(host_name, 'nova-compute')
|
nova.services.disable(service.id)
|
||||||
else:
|
else:
|
||||||
LOG.info('Enable nova-compute on %s', host_name)
|
LOG.info('Enable nova-compute on %s', host_name)
|
||||||
nova.services.enable(host_name, 'nova-compute')
|
nova.services.enable(service.id)
|
||||||
|
|
||||||
@translate_nova_exception
|
@translate_nova_exception
|
||||||
def is_service_down(self, context, host_name, binary):
|
def is_service_down(self, context, host_name, binary):
|
||||||
|
|
|
@ -182,31 +182,40 @@ class NovaApiTestCase(test.TestCase):
|
||||||
host = 'fake'
|
host = 'fake'
|
||||||
mock_services = mock.MagicMock()
|
mock_services = mock.MagicMock()
|
||||||
mock_novaclient.return_value = mock.MagicMock(services=mock_services)
|
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)
|
self.api.enable_disable_service(self.ctx, host, enable=True)
|
||||||
|
|
||||||
mock_novaclient.assert_called_once_with(self.ctx)
|
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')
|
@mock.patch('masakari.compute.nova.novaclient')
|
||||||
def test_enable_disable_service_disable(self, mock_novaclient):
|
def test_enable_disable_service_disable(self, mock_novaclient):
|
||||||
host = 'fake'
|
host = 'fake'
|
||||||
mock_services = mock.MagicMock()
|
mock_services = mock.MagicMock()
|
||||||
mock_novaclient.return_value = mock.MagicMock(services=mock_services)
|
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)
|
self.api.enable_disable_service(self.ctx, host)
|
||||||
|
|
||||||
mock_novaclient.assert_called_once_with(self.ctx)
|
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')
|
@mock.patch('masakari.compute.nova.novaclient')
|
||||||
def test_enable_disable_service_disable_reason(self, mock_novaclient):
|
def test_enable_disable_service_disable_reason(self, mock_novaclient):
|
||||||
host = 'fake'
|
host = 'fake'
|
||||||
mock_services = mock.MagicMock()
|
mock_services = mock.MagicMock()
|
||||||
mock_novaclient.return_value = mock.MagicMock(services=mock_services)
|
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')
|
self.api.enable_disable_service(self.ctx, host, reason='fake_reason')
|
||||||
|
|
||||||
mock_novaclient.assert_called_once_with(self.ctx)
|
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(
|
mock_services.disable_log_reason.assert_called_once_with(
|
||||||
host, 'nova-compute', 'fake_reason')
|
'fake_id', 'fake_reason')
|
||||||
|
|
||||||
@mock.patch('masakari.compute.nova.novaclient')
|
@mock.patch('masakari.compute.nova.novaclient')
|
||||||
def test_is_service_down(self, mock_novaclient):
|
def test_is_service_down(self, mock_novaclient):
|
||||||
|
|
|
@ -136,8 +136,10 @@ class FakeNovaClient(object):
|
||||||
binary=binary,
|
binary=binary,
|
||||||
status=status))
|
status=status))
|
||||||
|
|
||||||
def disable(self, host_name, binary):
|
def disable(self, service_id):
|
||||||
service = self.list(host=host_name, binary=binary)[0]
|
for _service in self._services:
|
||||||
|
if _service.id == service_id:
|
||||||
|
service = _service
|
||||||
service.status = 'disabled'
|
service.status = 'disabled'
|
||||||
|
|
||||||
def list(self, host=None, binary=None):
|
def list(self, host=None, binary=None):
|
||||||
|
|
Loading…
Reference in New Issue