Merge "Add --reason for disable service"
This commit is contained in:
commit
c8e4a1407f
@ -50,19 +50,24 @@ Set service command
|
||||
.. program:: compute service set
|
||||
.. code:: bash
|
||||
|
||||
os compute service list
|
||||
os compute service set
|
||||
[--enable | --disable]
|
||||
[--disable-reason <reason>]
|
||||
<host> <service>
|
||||
|
||||
.. _compute-service-set:
|
||||
.. describe:: --enable
|
||||
.. option:: --enable
|
||||
|
||||
Enable service (default)
|
||||
|
||||
.. describe:: --disable
|
||||
.. option:: --disable
|
||||
|
||||
Disable service
|
||||
|
||||
.. option:: --disable-reason <reason>
|
||||
|
||||
Reason for disabling the service (in quotes)
|
||||
|
||||
.. describe:: <host>
|
||||
|
||||
Name of host
|
||||
|
@ -95,14 +95,24 @@ class SetService(command.Command):
|
||||
dest="enabled",
|
||||
help="Disable a service",
|
||||
action="store_false")
|
||||
parser.add_argument(
|
||||
"--disable-reason",
|
||||
default=None,
|
||||
metavar="<reason>",
|
||||
help="Reason for disabling the service (in quotas)"
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
cs = compute_client.services
|
||||
|
||||
if parsed_args.enabled:
|
||||
action = compute_client.services.enable
|
||||
if not parsed_args.enabled:
|
||||
if parsed_args.disable_reason:
|
||||
cs.disable_log_reason(parsed_args.host,
|
||||
parsed_args.service,
|
||||
parsed_args.disable_reason)
|
||||
else:
|
||||
action = compute_client.services.disable
|
||||
|
||||
action(parsed_args.host, parsed_args.service)
|
||||
cs.disable(parsed_args.host, parsed_args.service)
|
||||
else:
|
||||
cs.enable(parsed_args.host, parsed_args.service)
|
||||
|
@ -153,3 +153,29 @@ class TestServiceSet(TestService):
|
||||
compute_fakes.service_binary,
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_service_set_disable_with_reason(self):
|
||||
reason = 'earthquake'
|
||||
arglist = [
|
||||
compute_fakes.service_host,
|
||||
compute_fakes.service_binary,
|
||||
'--disable',
|
||||
'--disable-reason',
|
||||
reason
|
||||
]
|
||||
verifylist = [
|
||||
('host', compute_fakes.service_host),
|
||||
('service', compute_fakes.service_binary),
|
||||
('enabled', False),
|
||||
('disable_reason', reason)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.service_mock.disable_log_reason.assert_called_with(
|
||||
compute_fakes.service_host,
|
||||
compute_fakes.service_binary,
|
||||
reason
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add support for the ``--disable-reason`` of ``service set`` command
|
Loading…
Reference in New Issue
Block a user