compute: limit the service's force down command above 2.10
The force down action is added in Microversion 2.11, we should limit the command only can be executed when the microversion is above 2.10. Change-Id: I0a87e02e71ff025d30181fc17ebcd003a590f110
This commit is contained in:
parent
9766eb23e7
commit
956eabe967
@ -17,6 +17,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from novaclient import api_versions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
@ -192,18 +193,23 @@ class SetService(command.Command):
|
||||
result += 1
|
||||
|
||||
force_down = None
|
||||
try:
|
||||
if parsed_args.down:
|
||||
force_down = True
|
||||
if parsed_args.up:
|
||||
force_down = False
|
||||
if force_down is not None:
|
||||
if parsed_args.down:
|
||||
force_down = True
|
||||
if parsed_args.up:
|
||||
force_down = False
|
||||
if force_down is not None:
|
||||
if compute_client.api_version < api_versions.APIVersion(
|
||||
'2.11'):
|
||||
msg = _('--os-compute-api-version 2.11 or later is '
|
||||
'required')
|
||||
raise exceptions.CommandError(msg)
|
||||
try:
|
||||
cs.force_down(parsed_args.host, parsed_args.service,
|
||||
force_down=force_down)
|
||||
except Exception:
|
||||
state = "down" if force_down else "up"
|
||||
LOG.error("Failed to set service state to %s", state)
|
||||
result += 1
|
||||
except Exception:
|
||||
state = "down" if force_down else "up"
|
||||
LOG.error("Failed to set service state to %s", state)
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
msg = _("Compute service %(service)s of host %(host)s failed to "
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import mock
|
||||
from mock import call
|
||||
|
||||
from novaclient import api_versions
|
||||
from osc_lib import exceptions
|
||||
|
||||
from openstackclient.compute.v2 import service
|
||||
@ -340,6 +340,8 @@ class TestServiceSet(TestService):
|
||||
('service', self.service.binary),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.11')
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.service_mock.force_down.assert_called_once_with(
|
||||
self.service.host, self.service.binary, force_down=False)
|
||||
@ -359,6 +361,8 @@ class TestServiceSet(TestService):
|
||||
('service', self.service.binary),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.11')
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.service_mock.force_down.assert_called_once_with(
|
||||
self.service.host, self.service.binary, force_down=True)
|
||||
@ -380,6 +384,8 @@ class TestServiceSet(TestService):
|
||||
('service', self.service.binary),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.11')
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.service_mock.enable.assert_called_once_with(
|
||||
self.service.host, self.service.binary)
|
||||
@ -402,6 +408,8 @@ class TestServiceSet(TestService):
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.11')
|
||||
with mock.patch.object(self.service_mock, 'enable',
|
||||
side_effect=Exception()):
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
|
Loading…
Reference in New Issue
Block a user