CLI for disable service reason
Adds cli option to allow users to give reason for service-disable. Also adds disabled reason as a column in service list, so any disabled service can be seen with reason. A recent cinder change that allows disable-log-reason allows users to provide reason for disabling service. This just adds the cli option for the method. Implements bp record-reason-for-disabling-service Change-Id: I90f4566764790eeb0c047c4a0fd0108050ab6ad9
This commit is contained in:
parent
e8e785f016
commit
8a59f2ca57
@ -708,6 +708,11 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
return (200, {}, {'host': body['host'], 'binary': body['binary'],
|
return (200, {}, {'host': body['host'], 'binary': body['binary'],
|
||||||
'status': 'disabled'})
|
'status': 'disabled'})
|
||||||
|
|
||||||
|
def put_os_services_disable_log_reason(self, body, **kw):
|
||||||
|
return (200, {}, {'host': body['host'], 'binary': body['binary'],
|
||||||
|
'status': 'disabled',
|
||||||
|
'disabled_reason': body['disabled_reason']})
|
||||||
|
|
||||||
def get_os_availability_zone(self, **kw):
|
def get_os_availability_zone(self, **kw):
|
||||||
return (200, {}, {
|
return (200, {}, {
|
||||||
"availabilityZoneInfo": [
|
"availabilityZoneInfo": [
|
||||||
|
@ -64,3 +64,12 @@ class ServicesTest(utils.TestCase):
|
|||||||
cs.assert_called('PUT', '/os-services/disable', values)
|
cs.assert_called('PUT', '/os-services/disable', values)
|
||||||
self.assertTrue(isinstance(s, services.Service))
|
self.assertTrue(isinstance(s, services.Service))
|
||||||
self.assertEqual(s.status, 'disabled')
|
self.assertEqual(s.status, 'disabled')
|
||||||
|
|
||||||
|
def test_services_disable_log_reason(self):
|
||||||
|
s = cs.services.disable_log_reason(
|
||||||
|
'host1', 'cinder-volume', 'disable bad host')
|
||||||
|
values = {"host": "host1", 'binary': 'cinder-volume',
|
||||||
|
"disabled_reason": "disable bad host"}
|
||||||
|
cs.assert_called('PUT', '/os-services/disable-log-reason', values)
|
||||||
|
self.assertTrue(isinstance(s, services.Service))
|
||||||
|
self.assertEqual(s.status, 'disabled')
|
||||||
|
@ -347,6 +347,13 @@ class ShellTest(utils.TestCase):
|
|||||||
self.assert_called('PUT', '/os-services/disable',
|
self.assert_called('PUT', '/os-services/disable',
|
||||||
{"binary": "cinder-volume", "host": "host"})
|
{"binary": "cinder-volume", "host": "host"})
|
||||||
|
|
||||||
|
def test_services_disable_with_reason(self):
|
||||||
|
cmd = 'service-disable host cinder-volume --reason no_reason'
|
||||||
|
self.run_command(cmd)
|
||||||
|
body = {'host': 'host', 'binary': 'cinder-volume',
|
||||||
|
'disabled_reason': 'no_reason'}
|
||||||
|
self.assert_called('PUT', '/os-services/disable-log-reason', body)
|
||||||
|
|
||||||
def test_service_enable(self):
|
def test_service_enable(self):
|
||||||
self.run_command('service-enable host cinder-volume')
|
self.run_command('service-enable host cinder-volume')
|
||||||
self.assert_called('PUT', '/os-services/enable',
|
self.assert_called('PUT', '/os-services/enable',
|
||||||
|
@ -741,6 +741,11 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||||||
return (200, {}, {'host': body['host'], 'binary': body['binary'],
|
return (200, {}, {'host': body['host'], 'binary': body['binary'],
|
||||||
'status': 'disabled'})
|
'status': 'disabled'})
|
||||||
|
|
||||||
|
def put_os_services_disable_log_reason(self, body, **kw):
|
||||||
|
return (200, {}, {'host': body['host'], 'binary': body['binary'],
|
||||||
|
'status': 'disabled',
|
||||||
|
'disabled_reason': body['disabled_reason']})
|
||||||
|
|
||||||
def get_os_availability_zone(self, **kw):
|
def get_os_availability_zone(self, **kw):
|
||||||
return (200, {}, {
|
return (200, {}, {
|
||||||
"availabilityZoneInfo": [
|
"availabilityZoneInfo": [
|
||||||
|
@ -64,3 +64,12 @@ class ServicesTest(utils.TestCase):
|
|||||||
cs.assert_called('PUT', '/os-services/disable', values)
|
cs.assert_called('PUT', '/os-services/disable', values)
|
||||||
self.assertTrue(isinstance(s, services.Service))
|
self.assertTrue(isinstance(s, services.Service))
|
||||||
self.assertEqual(s.status, 'disabled')
|
self.assertEqual(s.status, 'disabled')
|
||||||
|
|
||||||
|
def test_services_disable_log_reason(self):
|
||||||
|
s = cs.services.disable_log_reason(
|
||||||
|
'host1', 'cinder-volume', 'disable bad host')
|
||||||
|
values = {"host": "host1", 'binary': 'cinder-volume',
|
||||||
|
"disabled_reason": "disable bad host"}
|
||||||
|
cs.assert_called('PUT', '/os-services/disable-log-reason', values)
|
||||||
|
self.assertTrue(isinstance(s, services.Service))
|
||||||
|
self.assertEqual(s.status, 'disabled')
|
||||||
|
@ -335,6 +335,13 @@ class ShellTest(utils.TestCase):
|
|||||||
self.assert_called('PUT', '/os-services/disable',
|
self.assert_called('PUT', '/os-services/disable',
|
||||||
{"binary": "cinder-volume", "host": "host"})
|
{"binary": "cinder-volume", "host": "host"})
|
||||||
|
|
||||||
|
def test_services_disable_with_reason(self):
|
||||||
|
cmd = 'service-disable host cinder-volume --reason no_reason'
|
||||||
|
self.run_command(cmd)
|
||||||
|
body = {'host': 'host', 'binary': 'cinder-volume',
|
||||||
|
'disabled_reason': 'no_reason'}
|
||||||
|
self.assert_called('PUT', '/os-services/disable-log-reason', body)
|
||||||
|
|
||||||
def test_service_enable(self):
|
def test_service_enable(self):
|
||||||
self.run_command('service-enable host cinder-volume')
|
self.run_command('service-enable host cinder-volume')
|
||||||
self.assert_called('PUT', '/os-services/enable',
|
self.assert_called('PUT', '/os-services/enable',
|
||||||
|
@ -56,3 +56,9 @@ class ServiceManager(base.ManagerWithFind):
|
|||||||
body = {"host": host, "binary": binary}
|
body = {"host": host, "binary": binary}
|
||||||
result = self._update("/os-services/disable", body)
|
result = self._update("/os-services/disable", body)
|
||||||
return self.resource_class(self, result)
|
return self.resource_class(self, result)
|
||||||
|
|
||||||
|
def disable_log_reason(self, host, binary, reason):
|
||||||
|
"""Disable the service with reason."""
|
||||||
|
body = {"host": host, "binary": binary, "disabled_reason": reason}
|
||||||
|
result = self._update("/os-services/disable-log-reason", body)
|
||||||
|
return self.resource_class(self, result)
|
||||||
|
@ -986,6 +986,10 @@ def do_service_list(cs, args):
|
|||||||
"""List all the services. Filter by host & service binary."""
|
"""List all the services. Filter by host & service binary."""
|
||||||
result = cs.services.list(host=args.host, binary=args.binary)
|
result = cs.services.list(host=args.host, binary=args.binary)
|
||||||
columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"]
|
columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"]
|
||||||
|
# NOTE(jay-lau-513): we check if the response has disabled_reason
|
||||||
|
# so as not to add the column when the extended ext is not enabled.
|
||||||
|
if result and hasattr(result[0], 'disabled_reason'):
|
||||||
|
columns.append("Disabled Reason")
|
||||||
utils.print_list(result, columns)
|
utils.print_list(result, columns)
|
||||||
|
|
||||||
|
|
||||||
@ -1001,11 +1005,18 @@ def do_service_enable(cs, args):
|
|||||||
|
|
||||||
@utils.arg('host', metavar='<hostname>', help='Name of host.')
|
@utils.arg('host', metavar='<hostname>', help='Name of host.')
|
||||||
@utils.arg('binary', metavar='<binary>', help='Service binary.')
|
@utils.arg('binary', metavar='<binary>', help='Service binary.')
|
||||||
|
@utils.arg('--reason', metavar='<reason>',
|
||||||
|
help='Reason for disabling service.')
|
||||||
@utils.service_type('volume')
|
@utils.service_type('volume')
|
||||||
def do_service_disable(cs, args):
|
def do_service_disable(cs, args):
|
||||||
"""Disable the service."""
|
"""Disable the service."""
|
||||||
result = cs.services.disable(args.host, args.binary)
|
|
||||||
columns = ["Host", "Binary", "Status"]
|
columns = ["Host", "Binary", "Status"]
|
||||||
|
if args.reason:
|
||||||
|
columns.append('Disabled Reason')
|
||||||
|
result = cs.services.disable_log_reason(args.host, args.binary,
|
||||||
|
args.reason)
|
||||||
|
else:
|
||||||
|
result = cs.services.disable(args.host, args.binary)
|
||||||
utils.print_list([result], columns)
|
utils.print_list([result], columns)
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,3 +56,9 @@ class ServiceManager(base.ManagerWithFind):
|
|||||||
body = {"host": host, "binary": binary}
|
body = {"host": host, "binary": binary}
|
||||||
result = self._update("/os-services/disable", body)
|
result = self._update("/os-services/disable", body)
|
||||||
return self.resource_class(self, result)
|
return self.resource_class(self, result)
|
||||||
|
|
||||||
|
def disable_log_reason(self, host, binary, reason):
|
||||||
|
"""Disable the service with reason."""
|
||||||
|
body = {"host": host, "binary": binary, "disabled_reason": reason}
|
||||||
|
result = self._update("/os-services/disable-log-reason", body)
|
||||||
|
return self.resource_class(self, result)
|
||||||
|
@ -1118,6 +1118,10 @@ def do_service_list(cs, args):
|
|||||||
"""List all the services. Filter by host & service binary."""
|
"""List all the services. Filter by host & service binary."""
|
||||||
result = cs.services.list(host=args.host, binary=args.binary)
|
result = cs.services.list(host=args.host, binary=args.binary)
|
||||||
columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"]
|
columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"]
|
||||||
|
# NOTE(jay-lau-513): we check if the response has disabled_reason
|
||||||
|
# so as not to add the column when the extended ext is not enabled.
|
||||||
|
if result and hasattr(result[0], 'disabled_reason'):
|
||||||
|
columns.append("Disabled Reason")
|
||||||
utils.print_list(result, columns)
|
utils.print_list(result, columns)
|
||||||
|
|
||||||
|
|
||||||
@ -1133,11 +1137,18 @@ def do_service_enable(cs, args):
|
|||||||
|
|
||||||
@utils.arg('host', metavar='<hostname>', help='Name of host.')
|
@utils.arg('host', metavar='<hostname>', help='Name of host.')
|
||||||
@utils.arg('binary', metavar='<binary>', help='Service binary.')
|
@utils.arg('binary', metavar='<binary>', help='Service binary.')
|
||||||
|
@utils.arg('--reason', metavar='<reason>',
|
||||||
|
help='Reason for disabling service.')
|
||||||
@utils.service_type('volumev2')
|
@utils.service_type('volumev2')
|
||||||
def do_service_disable(cs, args):
|
def do_service_disable(cs, args):
|
||||||
"""Disable the service."""
|
"""Disable the service."""
|
||||||
result = cs.services.disable(args.host, args.binary)
|
|
||||||
columns = ["Host", "Binary", "Status"]
|
columns = ["Host", "Binary", "Status"]
|
||||||
|
if args.reason:
|
||||||
|
columns.append('Disabled Reason')
|
||||||
|
result = cs.services.disable_log_reason(args.host, args.binary,
|
||||||
|
args.reason)
|
||||||
|
else:
|
||||||
|
result = cs.services.disable(args.host, args.binary)
|
||||||
utils.print_list([result], columns)
|
utils.print_list([result], columns)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user