Merge "Log hint when --enable present with --disable-reason"
This commit is contained in:
commit
523ab58fb6
doc/source/command-objects
openstackclient
@ -36,7 +36,7 @@ List service command
|
|||||||
.. _compute-service-list:
|
.. _compute-service-list:
|
||||||
.. option:: --host <host>
|
.. option:: --host <host>
|
||||||
|
|
||||||
List services on specified host (name only)
|
List services on specified host (name only)
|
||||||
|
|
||||||
.. option:: --service <service>
|
.. option:: --service <service>
|
||||||
|
|
||||||
@ -71,7 +71,8 @@ Set service command
|
|||||||
|
|
||||||
.. option:: --disable-reason <reason>
|
.. option:: --disable-reason <reason>
|
||||||
|
|
||||||
Reason for disabling the service (in quotes)
|
Reason for disabling the service (in quotes). Note that when the service
|
||||||
|
is enabled, this option is ignored.
|
||||||
|
|
||||||
.. describe:: <host>
|
.. describe:: <host>
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
from openstackclient.common import command
|
from openstackclient.common import command
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
|
from openstackclient.i18n import _ # noqa
|
||||||
|
|
||||||
|
|
||||||
class DeleteService(command.Command):
|
class DeleteService(command.Command):
|
||||||
@ -117,8 +118,8 @@ class SetService(command.Command):
|
|||||||
"--disable-reason",
|
"--disable-reason",
|
||||||
default=None,
|
default=None,
|
||||||
metavar="<reason>",
|
metavar="<reason>",
|
||||||
help="Reason for disabling the service (in quotas)"
|
help="Reason for disabling the service (in quotas). Note that "
|
||||||
)
|
"when the service is enabled, this option is ignored.")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -133,4 +134,8 @@ class SetService(command.Command):
|
|||||||
else:
|
else:
|
||||||
cs.disable(parsed_args.host, parsed_args.service)
|
cs.disable(parsed_args.host, parsed_args.service)
|
||||||
else:
|
else:
|
||||||
|
if parsed_args.disable_reason:
|
||||||
|
msg = _("argument --disable-reason has been ignored")
|
||||||
|
self.log.info(msg)
|
||||||
|
|
||||||
cs.enable(parsed_args.host, parsed_args.service)
|
cs.enable(parsed_args.host, parsed_args.service)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import mock
|
||||||
|
|
||||||
from openstackclient.compute.v2 import service
|
from openstackclient.compute.v2 import service
|
||||||
from openstackclient.tests.compute.v2 import fakes as compute_fakes
|
from openstackclient.tests.compute.v2 import fakes as compute_fakes
|
||||||
@ -138,14 +139,14 @@ class TestServiceSet(TestService):
|
|||||||
|
|
||||||
def test_service_set_enable(self):
|
def test_service_set_enable(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
|
'--enable',
|
||||||
compute_fakes.service_host,
|
compute_fakes.service_host,
|
||||||
compute_fakes.service_binary,
|
compute_fakes.service_binary,
|
||||||
'--enable',
|
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
|
('enabled', True),
|
||||||
('host', compute_fakes.service_host),
|
('host', compute_fakes.service_host),
|
||||||
('service', compute_fakes.service_binary),
|
('service', compute_fakes.service_binary),
|
||||||
('enabled', True),
|
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
@ -159,14 +160,14 @@ class TestServiceSet(TestService):
|
|||||||
|
|
||||||
def test_service_set_disable(self):
|
def test_service_set_disable(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
|
'--disable',
|
||||||
compute_fakes.service_host,
|
compute_fakes.service_host,
|
||||||
compute_fakes.service_binary,
|
compute_fakes.service_binary,
|
||||||
'--disable',
|
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
|
('enabled', False),
|
||||||
('host', compute_fakes.service_host),
|
('host', compute_fakes.service_host),
|
||||||
('service', compute_fakes.service_binary),
|
('service', compute_fakes.service_binary),
|
||||||
('enabled', False),
|
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
@ -181,17 +182,16 @@ class TestServiceSet(TestService):
|
|||||||
def test_service_set_disable_with_reason(self):
|
def test_service_set_disable_with_reason(self):
|
||||||
reason = 'earthquake'
|
reason = 'earthquake'
|
||||||
arglist = [
|
arglist = [
|
||||||
|
'--disable',
|
||||||
|
'--disable-reason', reason,
|
||||||
compute_fakes.service_host,
|
compute_fakes.service_host,
|
||||||
compute_fakes.service_binary,
|
compute_fakes.service_binary,
|
||||||
'--disable',
|
|
||||||
'--disable-reason',
|
|
||||||
reason
|
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
|
('enabled', False),
|
||||||
|
('disable_reason', reason),
|
||||||
('host', compute_fakes.service_host),
|
('host', compute_fakes.service_host),
|
||||||
('service', compute_fakes.service_binary),
|
('service', compute_fakes.service_binary),
|
||||||
('enabled', False),
|
|
||||||
('disable_reason', reason)
|
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
@ -203,3 +203,58 @@ class TestServiceSet(TestService):
|
|||||||
reason
|
reason
|
||||||
)
|
)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_service_set_only_with_disable_reason(self):
|
||||||
|
reason = 'earthquake'
|
||||||
|
arglist = [
|
||||||
|
'--disable-reason', reason,
|
||||||
|
compute_fakes.service_host,
|
||||||
|
compute_fakes.service_binary,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('enabled', True),
|
||||||
|
('disable_reason', reason),
|
||||||
|
('host', compute_fakes.service_host),
|
||||||
|
('service', compute_fakes.service_binary),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
with mock.patch.object(self.cmd.log, 'info') as mock_log:
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
msg = "argument --disable-reason has been ignored"
|
||||||
|
mock_log.assert_called_once_with(msg)
|
||||||
|
|
||||||
|
self.service_mock.enable.assert_called_with(
|
||||||
|
compute_fakes.service_host,
|
||||||
|
compute_fakes.service_binary
|
||||||
|
)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_service_set_enable_with_disable_reason(self):
|
||||||
|
reason = 'earthquake'
|
||||||
|
arglist = [
|
||||||
|
'--enable',
|
||||||
|
'--disable-reason', reason,
|
||||||
|
compute_fakes.service_host,
|
||||||
|
compute_fakes.service_binary,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('enabled', True),
|
||||||
|
('disable_reason', reason),
|
||||||
|
('host', compute_fakes.service_host),
|
||||||
|
('service', compute_fakes.service_binary),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
with mock.patch.object(self.cmd.log, 'info') as mock_log:
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
msg = "argument --disable-reason has been ignored"
|
||||||
|
mock_log.assert_called_once_with(msg)
|
||||||
|
|
||||||
|
self.service_mock.enable.assert_called_with(
|
||||||
|
compute_fakes.service_host,
|
||||||
|
compute_fakes.service_binary
|
||||||
|
)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user