Add OSC plugin for stack resource mark unhealthy
This change implements the "openstack stack resource mark unhealthy" command Based on the existing heat command: heat resource-mark-unhealthy Change-Id: I8b4735085e1656f991b648d094f690b8d7df451d Blueprint: heat-support-python-openstackclient
This commit is contained in:
parent
4f4575565c
commit
ee73d343f5
|
@ -249,3 +249,51 @@ def _resource_signal(heat_client, args):
|
|||
'not found.') %
|
||||
{'stack': args.stack,
|
||||
'resource': args.resource})
|
||||
|
||||
|
||||
class ResourceMarkUnhealthy(command.Command):
|
||||
"""Set resource's health."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".ResourceMarkUnhealthy")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ResourceMarkUnhealthy, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'stack',
|
||||
metavar='<stack>',
|
||||
help=_('Name or ID of stack the resource belongs to')
|
||||
)
|
||||
parser.add_argument(
|
||||
'resource',
|
||||
metavar='<resource>',
|
||||
help=_('Name of the resource')
|
||||
)
|
||||
parser.add_argument(
|
||||
'reason',
|
||||
default="",
|
||||
nargs='?',
|
||||
help=_('Reason for state change')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--reset',
|
||||
default=False,
|
||||
action="store_true",
|
||||
help=_('Set the resource as healthy')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
|
||||
heat_client = self.app.client_manager.orchestration
|
||||
fields = {'stack_id': parsed_args.stack,
|
||||
'resource_name': parsed_args.resource,
|
||||
'mark_unhealthy': not parsed_args.reset,
|
||||
'resource_status_reason': parsed_args.reason}
|
||||
try:
|
||||
heat_client.resources.mark_unhealthy(**fields)
|
||||
except heat_exc.HTTPNotFound:
|
||||
raise exc.CommandError(_('Stack or resource not found: '
|
||||
'%(id)s %(resource)s') %
|
||||
{'id': parsed_args.stack,
|
||||
'resource': parsed_args.resource})
|
||||
|
|
|
@ -322,3 +322,43 @@ class TestResourceSignal(TestResource):
|
|||
'stack_id': 'my_stack',
|
||||
'resource_name': 'my_resource'
|
||||
})
|
||||
|
||||
|
||||
class TestResourceMarkUnhealthy(TestResource):
|
||||
def setUp(self):
|
||||
super(TestResourceMarkUnhealthy, self).setUp()
|
||||
self.cmd = resource.ResourceMarkUnhealthy(self.app, None)
|
||||
self.resource_client.mark_unhealthy = mock.Mock()
|
||||
|
||||
def test_resource_mark_unhealthy(self):
|
||||
arglist = ['my_stack', 'my_resource', 'reason']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.resource_client.mark_unhealthy.assert_called_with(**{
|
||||
"stack_id": "my_stack",
|
||||
"resource_name": "my_resource",
|
||||
"mark_unhealthy": True,
|
||||
"resource_status_reason": "reason"
|
||||
})
|
||||
|
||||
def test_resource_mark_unhealthy_reset(self):
|
||||
arglist = ['my_stack', 'my_resource', '--reset']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.resource_client.mark_unhealthy.assert_called_with(**{
|
||||
"stack_id": "my_stack",
|
||||
"resource_name": "my_resource",
|
||||
"mark_unhealthy": False,
|
||||
"resource_status_reason": ""
|
||||
})
|
||||
|
||||
def test_resource_mark_unhealthy_not_found(self):
|
||||
arglist = ['my_stack', 'my_resource', '--reset']
|
||||
self.resource_client.mark_unhealthy.side_effect = (
|
||||
heat_exc.HTTPNotFound)
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
|
||||
error = self.assertRaises(exc.CommandError,
|
||||
self.cmd.take_action, parsed_args)
|
||||
self.assertEqual('Stack or resource not found: my_stack my_resource',
|
||||
str(error))
|
||||
|
|
|
@ -58,6 +58,7 @@ openstack.orchestration.v1 =
|
|||
stack_output_list = heatclient.osc.v1.stack:OutputListStack
|
||||
stack_output_show = heatclient.osc.v1.stack:OutputShowStack
|
||||
stack_resource_list = heatclient.osc.v1.resource:ResourceList
|
||||
stack_resource_mark_unhealthy = heatclient.osc.v1.resource:ResourceMarkUnhealthy
|
||||
stack_resource_metadata = heatclient.osc.v1.resource:ResourceMetadata
|
||||
stack_resource_show = heatclient.osc.v1.resource:ResourceShow
|
||||
stack_resource_signal = heatclient.osc.v1.resource:ResourceSignal
|
||||
|
|
Loading…
Reference in New Issue