Merge "Add description param for execution create/update"
This commit is contained in:
@@ -26,10 +26,14 @@ class Execution(base.Resource):
|
|||||||
class ExecutionManager(base.ResourceManager):
|
class ExecutionManager(base.ResourceManager):
|
||||||
resource_class = Execution
|
resource_class = Execution
|
||||||
|
|
||||||
def create(self, workflow_name, workflow_input=None, **params):
|
def create(self, workflow_name, workflow_input=None, description='',
|
||||||
|
**params):
|
||||||
self._ensure_not_empty(workflow_name=workflow_name)
|
self._ensure_not_empty(workflow_name=workflow_name)
|
||||||
|
|
||||||
data = {'workflow_name': workflow_name}
|
data = {
|
||||||
|
'workflow_name': workflow_name,
|
||||||
|
'description': description
|
||||||
|
}
|
||||||
|
|
||||||
if workflow_input:
|
if workflow_input:
|
||||||
if isinstance(workflow_input, six.string_types):
|
if isinstance(workflow_input, six.string_types):
|
||||||
@@ -51,12 +55,12 @@ class ExecutionManager(base.ResourceManager):
|
|||||||
def create_direct_workflow(self, workflow_name, workflow_input, **params):
|
def create_direct_workflow(self, workflow_name, workflow_input, **params):
|
||||||
return self.create(workflow_name, workflow_input, **params)
|
return self.create(workflow_name, workflow_input, **params)
|
||||||
|
|
||||||
def update(self, id, state):
|
def update(self, id, state, description=None):
|
||||||
self._ensure_not_empty(id=id, state=state)
|
if state:
|
||||||
|
data = {'state': state}
|
||||||
|
|
||||||
data = {
|
if description:
|
||||||
'state': state
|
data = ({'description': description})
|
||||||
}
|
|
||||||
|
|
||||||
return self._update('/executions/%s' % id, data)
|
return self._update('/executions/%s' % id, data)
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ def format(execution=None, lister=False):
|
|||||||
columns = (
|
columns = (
|
||||||
'ID',
|
'ID',
|
||||||
'Workflow',
|
'Workflow',
|
||||||
|
'Description',
|
||||||
'State',
|
'State',
|
||||||
'State info',
|
'State info',
|
||||||
'Created at',
|
'Created at',
|
||||||
@@ -49,6 +50,7 @@ def format(execution=None, lister=False):
|
|||||||
data = (
|
data = (
|
||||||
execution.id,
|
execution.id,
|
||||||
execution.workflow_name,
|
execution.workflow_name,
|
||||||
|
execution.description,
|
||||||
execution.state,
|
execution.state,
|
||||||
state_info,
|
state_info,
|
||||||
execution.created_at,
|
execution.created_at,
|
||||||
@@ -107,6 +109,13 @@ class Create(show.ShowOne):
|
|||||||
nargs='?',
|
nargs='?',
|
||||||
help='Workflow additional parameters'
|
help='Workflow additional parameters'
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-d',
|
||||||
|
'--description',
|
||||||
|
dest='description',
|
||||||
|
default='',
|
||||||
|
help='Execution description'
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@@ -130,6 +139,7 @@ class Create(show.ShowOne):
|
|||||||
execution = executions.ExecutionManager(self.app.client).create(
|
execution = executions.ExecutionManager(self.app.client).create(
|
||||||
parsed_args.workflow_name,
|
parsed_args.workflow_name,
|
||||||
wf_input,
|
wf_input,
|
||||||
|
parsed_args.description,
|
||||||
**params)
|
**params)
|
||||||
|
|
||||||
return format(execution)
|
return format(execution)
|
||||||
@@ -169,18 +179,29 @@ class Update(show.ShowOne):
|
|||||||
'id',
|
'id',
|
||||||
help='Execution identifier'
|
help='Execution identifier'
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
|
||||||
'state',
|
group = parser.add_mutually_exclusive_group(required=True)
|
||||||
|
group.add_argument(
|
||||||
|
'-s',
|
||||||
|
'--state',
|
||||||
|
dest='state',
|
||||||
choices=['RUNNING', 'PAUSED', 'SUCCESS', 'ERROR'],
|
choices=['RUNNING', 'PAUSED', 'SUCCESS', 'ERROR'],
|
||||||
help='Execution state'
|
help='Execution state'
|
||||||
)
|
)
|
||||||
|
group.add_argument(
|
||||||
|
'-d',
|
||||||
|
'--description',
|
||||||
|
dest='description',
|
||||||
|
help='Execution description'
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
execution = executions.ExecutionManager(self.app.client).update(
|
execution = executions.ExecutionManager(self.app.client).update(
|
||||||
parsed_args.id,
|
parsed_args.id,
|
||||||
parsed_args.state)
|
parsed_args.state,
|
||||||
|
parsed_args.description)
|
||||||
|
|
||||||
return format(execution)
|
return format(execution)
|
||||||
|
|
||||||
|
@@ -289,15 +289,19 @@ class ExecutionCLITests(base_v2.MistralClientTestBase):
|
|||||||
|
|
||||||
def test_execution_create_delete(self):
|
def test_execution_create_delete(self):
|
||||||
execution = self.mistral_admin(
|
execution = self.mistral_admin(
|
||||||
'execution-create', params=self.direct_wf['Name'])
|
'execution-create',
|
||||||
|
params='{0} -d "execution test"'.format(self.direct_wf['Name'])
|
||||||
|
)
|
||||||
exec_id = self.get_value_of_field(execution, 'ID')
|
exec_id = self.get_value_of_field(execution, 'ID')
|
||||||
self.assertTableStruct(execution, ['Field', 'Value'])
|
self.assertTableStruct(execution, ['Field', 'Value'])
|
||||||
|
|
||||||
wf = self.get_value_of_field(execution, 'Workflow')
|
wf = self.get_value_of_field(execution, 'Workflow')
|
||||||
created_at = self.get_value_of_field(execution, 'Created at')
|
created_at = self.get_value_of_field(execution, 'Created at')
|
||||||
|
description = self.get_value_of_field(execution, 'Description')
|
||||||
|
|
||||||
self.assertEqual(self.direct_wf['Name'], wf)
|
self.assertEqual(self.direct_wf['Name'], wf)
|
||||||
self.assertIsNotNone(created_at)
|
self.assertIsNotNone(created_at)
|
||||||
|
self.assertEqual(description, "execution test")
|
||||||
|
|
||||||
execs = self.mistral_admin('execution-list')
|
execs = self.mistral_admin('execution-list')
|
||||||
self.assertIn(exec_id, [ex['ID'] for ex in execs])
|
self.assertIn(exec_id, [ex['ID'] for ex in execs])
|
||||||
@@ -321,8 +325,9 @@ class ExecutionCLITests(base_v2.MistralClientTestBase):
|
|||||||
|
|
||||||
self.assertEqual('RUNNING', status)
|
self.assertEqual('RUNNING', status)
|
||||||
|
|
||||||
|
# update execution state
|
||||||
execution = self.mistral_admin(
|
execution = self.mistral_admin(
|
||||||
'execution-update', params='{0} "PAUSED"'.format(exec_id))
|
'execution-update', params='{0} -s PAUSED'.format(exec_id))
|
||||||
|
|
||||||
updated_exec_id = self.get_value_of_field(execution, 'ID')
|
updated_exec_id = self.get_value_of_field(execution, 'ID')
|
||||||
status = self.get_value_of_field(execution, 'State')
|
status = self.get_value_of_field(execution, 'State')
|
||||||
@@ -330,6 +335,16 @@ class ExecutionCLITests(base_v2.MistralClientTestBase):
|
|||||||
self.assertEqual(exec_id, updated_exec_id)
|
self.assertEqual(exec_id, updated_exec_id)
|
||||||
self.assertEqual('PAUSED', status)
|
self.assertEqual('PAUSED', status)
|
||||||
|
|
||||||
|
# update execution description
|
||||||
|
execution = self.mistral_admin(
|
||||||
|
'execution-update',
|
||||||
|
params='{0} -d "execution update test"'.format(exec_id)
|
||||||
|
)
|
||||||
|
|
||||||
|
description = self.get_value_of_field(execution, 'Description')
|
||||||
|
|
||||||
|
self.assertEqual(description, "execution update test")
|
||||||
|
|
||||||
def test_execution_get(self):
|
def test_execution_get(self):
|
||||||
execution = self.execution_create(self.direct_wf['Name'])
|
execution = self.execution_create(self.direct_wf['Name'])
|
||||||
exec_id = self.get_value_of_field(execution, 'ID')
|
exec_id = self.get_value_of_field(execution, 'ID')
|
||||||
@@ -892,7 +907,16 @@ class NegativeCLITests(base_v2.MistralClientTestBase):
|
|||||||
self.assertRaises(exceptions.CommandFailed,
|
self.assertRaises(exceptions.CommandFailed,
|
||||||
self.mistral_admin,
|
self.mistral_admin,
|
||||||
'execution-update',
|
'execution-update',
|
||||||
params='%s ERROR' % exec_id)
|
params='%s -s ERROR' % exec_id)
|
||||||
|
|
||||||
|
def test_ex_update_both_state_and_description(self):
|
||||||
|
wf = self.workflow_create(self.wf_def)
|
||||||
|
execution = self.execution_create(params=wf[0]['Name'])
|
||||||
|
exec_id = self.get_value_of_field(execution, 'ID')
|
||||||
|
self.assertRaises(exceptions.CommandFailed,
|
||||||
|
self.mistral_admin,
|
||||||
|
'execution-update',
|
||||||
|
params='%s -s ERROR -d update' % exec_id)
|
||||||
|
|
||||||
def test_ex_delete_nonexistent_execution(self):
|
def test_ex_delete_nonexistent_execution(self):
|
||||||
self.assertRaises(exceptions.CommandFailed,
|
self.assertRaises(exceptions.CommandFailed,
|
||||||
|
@@ -24,6 +24,7 @@ from mistralclient.tests.unit import base
|
|||||||
EXECUTION = executions.Execution(mock, {
|
EXECUTION = executions.Execution(mock, {
|
||||||
'id': '123',
|
'id': '123',
|
||||||
'workflow_name': 'some',
|
'workflow_name': 'some',
|
||||||
|
'description': '',
|
||||||
'state': 'RUNNING',
|
'state': 'RUNNING',
|
||||||
'state_info': None,
|
'state_info': None,
|
||||||
'created_at': '1',
|
'created_at': '1',
|
||||||
@@ -39,7 +40,7 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
|
|||||||
result = self.call(execution_cmd.Create,
|
result = self.call(execution_cmd.Create,
|
||||||
app_args=['id', '{ "context": true }'])
|
app_args=['id', '{ "context": true }'])
|
||||||
|
|
||||||
self.assertEqual(('123', 'some', 'RUNNING', None,
|
self.assertEqual(('123', 'some', '', 'RUNNING', None,
|
||||||
'1', '1'), result[1])
|
'1', '1'), result[1])
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.create')
|
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.create')
|
||||||
@@ -50,7 +51,17 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
|
|||||||
result = self.call(execution_cmd.Create,
|
result = self.call(execution_cmd.Create,
|
||||||
app_args=['id', path])
|
app_args=['id', path])
|
||||||
|
|
||||||
self.assertEqual(('123', 'some', 'RUNNING', None,
|
self.assertEqual(('123', 'some', '', 'RUNNING', None,
|
||||||
|
'1', '1'), result[1])
|
||||||
|
|
||||||
|
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.create')
|
||||||
|
def test_create_with_description(self, mock):
|
||||||
|
mock.return_value = EXECUTION
|
||||||
|
|
||||||
|
result = self.call(execution_cmd.Create,
|
||||||
|
app_args=['id', '{ "context": true }', '-d', ''])
|
||||||
|
|
||||||
|
self.assertEqual(('123', 'some', '', 'RUNNING', None,
|
||||||
'1', '1'), result[1])
|
'1', '1'), result[1])
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.update')
|
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.update')
|
||||||
@@ -58,9 +69,9 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
|
|||||||
mock.return_value = EXECUTION
|
mock.return_value = EXECUTION
|
||||||
|
|
||||||
result = self.call(execution_cmd.Update,
|
result = self.call(execution_cmd.Update,
|
||||||
app_args=['id', 'SUCCESS'])
|
app_args=['id', '-s', 'SUCCESS'])
|
||||||
|
|
||||||
self.assertEqual(('123', 'some', 'RUNNING', None,
|
self.assertEqual(('123', 'some', '', 'RUNNING', None,
|
||||||
'1', '1'), result[1])
|
'1', '1'), result[1])
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.list')
|
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.list')
|
||||||
@@ -69,7 +80,7 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
|
|||||||
|
|
||||||
result = self.call(execution_cmd.List)
|
result = self.call(execution_cmd.List)
|
||||||
|
|
||||||
self.assertEqual([('123', 'some', 'RUNNING', None,
|
self.assertEqual([('123', 'some', '', 'RUNNING', None,
|
||||||
'1', '1')], result[1])
|
'1', '1')], result[1])
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.get')
|
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.get')
|
||||||
@@ -78,7 +89,7 @@ class TestCLIExecutionsV2(base.BaseCommandTest):
|
|||||||
|
|
||||||
result = self.call(execution_cmd.Get, app_args=['id'])
|
result = self.call(execution_cmd.Get, app_args=['id'])
|
||||||
|
|
||||||
self.assertEqual(('123', 'some', 'RUNNING', None,
|
self.assertEqual(('123', 'some', '', 'RUNNING', None,
|
||||||
'1', '1'), result[1])
|
'1', '1'), result[1])
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.delete')
|
@mock.patch('mistralclient.api.v2.executions.ExecutionManager.delete')
|
||||||
|
@@ -24,6 +24,7 @@ from mistralclient.tests.unit.v2 import base
|
|||||||
EXEC = {
|
EXEC = {
|
||||||
'id': "123",
|
'id': "123",
|
||||||
'workflow_name': 'my_wf',
|
'workflow_name': 'my_wf',
|
||||||
|
'description': '',
|
||||||
'state': 'RUNNING',
|
'state': 'RUNNING',
|
||||||
'input': {
|
'input': {
|
||||||
"person": {
|
"person": {
|
||||||
@@ -43,6 +44,7 @@ class TestExecutionsV2(base.BaseClientV2Test):
|
|||||||
mock = self.mock_http_post(content=EXEC)
|
mock = self.mock_http_post(content=EXEC)
|
||||||
body = {
|
body = {
|
||||||
'workflow_name': EXEC['workflow_name'],
|
'workflow_name': EXEC['workflow_name'],
|
||||||
|
'description': '',
|
||||||
'input': json.dumps(EXEC['input']),
|
'input': json.dumps(EXEC['input']),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user