Merge "Add action update command"
This commit is contained in:
commit
852a0f4cc6
@ -174,3 +174,46 @@ class TestActionShow(TestAction):
|
||||
error = self.assertRaises(exc.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertEqual('Action not found: my_action', str(error))
|
||||
|
||||
|
||||
class TestActionUpdate(TestAction):
|
||||
|
||||
def setUp(self):
|
||||
super(TestActionUpdate, self).setUp()
|
||||
self.cmd = osc_action.UpdateAction(self.app, None)
|
||||
fake_action = mock.Mock(
|
||||
action="NODE_CREATE",
|
||||
cause="RPC Request",
|
||||
created_at="2015-12-04T04:54:41",
|
||||
depended_by=[],
|
||||
depends_on=[],
|
||||
end_time=1425550000.0,
|
||||
id="2366d440-c73e-4961-9254-6d1c3af7c167",
|
||||
inputs={},
|
||||
interval=-1,
|
||||
name="node_create_0df0931b",
|
||||
outputs={},
|
||||
owner=None,
|
||||
start_time=1425550000.0,
|
||||
status="INIT",
|
||||
status_reason="Action completed successfully.",
|
||||
target_id="0df0931b-e251-4f2e-8719-4ebfda3627ba",
|
||||
timeout=3600,
|
||||
updated_at=None
|
||||
)
|
||||
fake_action.to_dict = mock.Mock(return_value={})
|
||||
self.mock_client.get_action = mock.Mock(return_value=fake_action)
|
||||
self.mock_client.update_action = mock.Mock(return_value=fake_action)
|
||||
|
||||
def test_action_update(self):
|
||||
arglist = ['--status', 'CANCELLED',
|
||||
'2366d440-c73e-4961-9254-6d1c3af7c167']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
defaults = {
|
||||
"status": "CANCELLED"
|
||||
}
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.mock_client.update_action.assert_called_with(
|
||||
"2366d440-c73e-4961-9254-6d1c3af7c167", **defaults)
|
||||
|
@ -462,6 +462,15 @@ class ClientTest(testtools.TestCase):
|
||||
self.assertEqual(self.service.get_action.return_value, res)
|
||||
self.service.get_action.assert_called_once_with('FOOBAR')
|
||||
|
||||
def test_update_action(self, mock_conn):
|
||||
mock_conn.return_value = self.conn
|
||||
sc = client.Client()
|
||||
|
||||
res = sc.update_action('FAKE_ID', status='CANCELLED')
|
||||
self.assertEqual(self.service.update_action.return_value, res)
|
||||
self.service.update_action.assert_called_once_with(
|
||||
'FAKE_ID', status='CANCELLED')
|
||||
|
||||
def test_events(self, mock_conn):
|
||||
mock_conn.return_value = self.conn
|
||||
sc = client.Client()
|
||||
|
@ -114,6 +114,27 @@ class ListAction(command.Lister):
|
||||
)
|
||||
|
||||
|
||||
def _show_action(senlin_client, action_id):
|
||||
try:
|
||||
action = senlin_client.get_action(action_id)
|
||||
except sdk_exc.ResourceNotFound:
|
||||
raise exc.CommandError(_('Action not found: %s')
|
||||
% action_id)
|
||||
|
||||
formatters = {
|
||||
'inputs': senlin_utils.json_formatter,
|
||||
'outputs': senlin_utils.json_formatter,
|
||||
'metadata': senlin_utils.json_formatter,
|
||||
'data': senlin_utils.json_formatter,
|
||||
'depends_on': senlin_utils.list_formatter,
|
||||
'depended_by': senlin_utils.list_formatter,
|
||||
}
|
||||
data = action.to_dict()
|
||||
columns = sorted(data.keys())
|
||||
return columns, utils.get_dict_properties(data, columns,
|
||||
formatters=formatters)
|
||||
|
||||
|
||||
class ShowAction(command.ShowOne):
|
||||
"""Show detailed info about the specified action."""
|
||||
|
||||
@ -132,21 +153,35 @@ class ShowAction(command.ShowOne):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
|
||||
senlin_client = self.app.client_manager.clustering
|
||||
try:
|
||||
action = senlin_client.get_action(parsed_args.action)
|
||||
except sdk_exc.ResourceNotFound:
|
||||
raise exc.CommandError(_('Action not found: %s')
|
||||
% parsed_args.action)
|
||||
return _show_action(senlin_client, parsed_args.action)
|
||||
|
||||
formatters = {
|
||||
'inputs': senlin_utils.json_formatter,
|
||||
'outputs': senlin_utils.json_formatter,
|
||||
'metadata': senlin_utils.json_formatter,
|
||||
'data': senlin_utils.json_formatter,
|
||||
'depends_on': senlin_utils.list_formatter,
|
||||
'depended_by': senlin_utils.list_formatter,
|
||||
|
||||
class UpdateAction(command.ShowOne):
|
||||
"""Update an action."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".UpdateAction")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UpdateAction, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--status',
|
||||
metavar='<status>',
|
||||
help=_('The new status for the action')
|
||||
)
|
||||
parser.add_argument(
|
||||
'action',
|
||||
metavar='<action>',
|
||||
help=_('ID of the action to update')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
senlin_client = self.app.client_manager.clustering
|
||||
|
||||
params = {
|
||||
'status': parsed_args.status,
|
||||
}
|
||||
data = action.to_dict()
|
||||
columns = sorted(data.keys())
|
||||
return columns, utils.get_dict_properties(data, columns,
|
||||
formatters=formatters)
|
||||
|
||||
senlin_client.update_action(parsed_args.action, **params)
|
||||
return _show_action(senlin_client, parsed_args.action)
|
||||
|
@ -495,6 +495,14 @@ class Client(object):
|
||||
"""
|
||||
return self.service.get_action(action)
|
||||
|
||||
def update_action(self, action, **attrs):
|
||||
"""Update an action
|
||||
|
||||
Doc link:
|
||||
https://docs.openstack.org/api-ref/clustering/#update-action
|
||||
"""
|
||||
return self.service.update_action(action, **attrs)
|
||||
|
||||
def services(self, **queries):
|
||||
"""List services
|
||||
|
||||
|
@ -30,6 +30,7 @@ openstack.cli.extension =
|
||||
openstack.clustering.v1 =
|
||||
cluster_action_list = senlinclient.v1.action:ListAction
|
||||
cluster_action_show = senlinclient.v1.action:ShowAction
|
||||
cluster_action_update = senlinclient.v1.action:UpdateAction
|
||||
cluster_build_info = senlinclient.v1.build_info:BuildInfo
|
||||
cluster_check = senlinclient.v1.cluster:CheckCluster
|
||||
cluster_create = senlinclient.v1.cluster:CreateCluster
|
||||
|
Loading…
x
Reference in New Issue
Block a user