Adding '--params' to cron-trigger CLI
Closes-Bug: #1449522 Depends-On: I68cc1121f8b1b7c211644a032c788b1361e831db Change-Id: I1767961697fb995d9821543d2add23d8191662a4
This commit is contained in:
parent
74a3e03008
commit
63a41d657d
@ -24,7 +24,8 @@ class CronTrigger(base.Resource):
|
||||
class CronTriggerManager(base.ResourceManager):
|
||||
resource_class = CronTrigger
|
||||
|
||||
def create(self, name, workflow_name, workflow_input=None, pattern=None,
|
||||
def create(self, name, workflow_name, workflow_input=None,
|
||||
workflow_params=None, pattern=None,
|
||||
first_time=None, count=None):
|
||||
self._ensure_not_empty(
|
||||
name=name,
|
||||
@ -42,6 +43,9 @@ class CronTriggerManager(base.ResourceManager):
|
||||
if workflow_input:
|
||||
data.update({'workflow_input': json.dumps(workflow_input)})
|
||||
|
||||
if workflow_params:
|
||||
data.update({'workflow_params': json.dumps(workflow_params)})
|
||||
|
||||
return self._create('/cron_triggers', data)
|
||||
|
||||
def list(self):
|
||||
|
@ -35,6 +35,7 @@ def format(trigger=None, lister=False):
|
||||
columns = (
|
||||
'Name',
|
||||
'Workflow',
|
||||
'Params',
|
||||
'Pattern',
|
||||
# TODO(rakhmerov): Uncomment when passwords are handled properly.
|
||||
# TODO(rakhmerov): Add 'Workflow input' column.
|
||||
@ -52,6 +53,7 @@ def format(trigger=None, lister=False):
|
||||
data = (
|
||||
trigger.name,
|
||||
trigger.workflow_name,
|
||||
trigger.workflow_params,
|
||||
trigger.pattern,
|
||||
# TODO(rakhmerov): Uncomment when passwords are handled properly.
|
||||
# TODo(rakhmerov): Add 'wf_input' here.
|
||||
@ -111,6 +113,11 @@ class Create(show.ShowOne):
|
||||
help='Workflow input'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--params',
|
||||
help='Workflow params',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--pattern',
|
||||
type=str,
|
||||
@ -132,21 +139,27 @@ class Create(show.ShowOne):
|
||||
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
def _get_file_content_or_dict(string):
|
||||
if string:
|
||||
try:
|
||||
return json.loads(string)
|
||||
except:
|
||||
return json.load(open(string))
|
||||
else:
|
||||
return {}
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
mgr = cron_triggers.CronTriggerManager(self.app.client)
|
||||
|
||||
if parsed_args.workflow_input:
|
||||
try:
|
||||
wf_input = json.loads(parsed_args.workflow_input)
|
||||
except:
|
||||
wf_input = json.load(open(parsed_args.workflow_input))
|
||||
else:
|
||||
wf_input = {}
|
||||
wf_input = self._get_file_content_or_dict(parsed_args.workflow_input)
|
||||
wf_params = self._get_file_content_or_dict(parsed_args.params)
|
||||
|
||||
trigger = mgr.create(
|
||||
parsed_args.name,
|
||||
parsed_args.workflow_name,
|
||||
wf_input,
|
||||
wf_params,
|
||||
parsed_args.pattern,
|
||||
parsed_args.first_time,
|
||||
parsed_args.count
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Copyright 2014 Mirantis, Inc.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
@ -25,6 +25,7 @@ TRIGGER_DICT = {
|
||||
'name': 'my_trigger',
|
||||
'workflow_name': 'flow1',
|
||||
'workflow_input': {},
|
||||
'workflow_params': {},
|
||||
'pattern': '* * * * *',
|
||||
'next_execution_time': '4242-12-20 13:37',
|
||||
'remaining_executions': 5,
|
||||
@ -32,11 +33,10 @@ TRIGGER_DICT = {
|
||||
'updated_at': '1'
|
||||
}
|
||||
|
||||
|
||||
TRIGGER = cron_triggers.CronTrigger(mock, TRIGGER_DICT)
|
||||
|
||||
|
||||
class TestCLIWorkbooksV2(base.BaseCommandTest):
|
||||
class TestCLITriggersV2(base.BaseCommandTest):
|
||||
@mock.patch('argparse.open', create=True)
|
||||
@mock.patch('mistralclient.api.v2.cron_triggers.CronTriggerManager.create')
|
||||
def test_create(self, mock, mock_open):
|
||||
@ -46,12 +46,15 @@ class TestCLIWorkbooksV2(base.BaseCommandTest):
|
||||
result = self.call(
|
||||
cron_triggers_cmd.Create,
|
||||
app_args=['my_trigger', 'flow1', '--pattern', '* * * * *',
|
||||
'--count', '5', '--first-time', '4242-12-20 13:37']
|
||||
'--params', '{}', '--count', '5', '--first-time',
|
||||
'4242-12-20 13:37']
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
('my_trigger', 'flow1', '* * * * *', '4242-12-20 13:37', 5, '1',
|
||||
'1'),
|
||||
(
|
||||
'my_trigger', 'flow1', {}, '* * * * *',
|
||||
'4242-12-20 13:37', 5, '1', '1'
|
||||
),
|
||||
result[1]
|
||||
)
|
||||
|
||||
@ -62,8 +65,10 @@ class TestCLIWorkbooksV2(base.BaseCommandTest):
|
||||
result = self.call(cron_triggers_cmd.List)
|
||||
|
||||
self.assertEqual(
|
||||
[('my_trigger', 'flow1', '* * * * *', '4242-12-20 13:37', 5, '1',
|
||||
'1')],
|
||||
[(
|
||||
'my_trigger', 'flow1', {}, '* * * * *',
|
||||
'4242-12-20 13:37', 5, '1', '1'
|
||||
)],
|
||||
result[1]
|
||||
)
|
||||
|
||||
@ -74,8 +79,10 @@ class TestCLIWorkbooksV2(base.BaseCommandTest):
|
||||
result = self.call(cron_triggers_cmd.Get, app_args=['name'])
|
||||
|
||||
self.assertEqual(
|
||||
('my_trigger', 'flow1', '* * * * *', '4242-12-20 13:37', 5, '1',
|
||||
'1'),
|
||||
(
|
||||
'my_trigger', 'flow1', {}, '* * * * *',
|
||||
'4242-12-20 13:37', 5, '1', '1'
|
||||
),
|
||||
result[1]
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user