Add description param for execution create/update
With this patch, users could do the following: mistral exeuction-create wf -d my_first_executio mistral execution-update d8922ca3-7908-4267-af03-bfad3d95fae2 -d my_second_execution However, state and description can't be updated at the same time, since there is no such scenario and avoid the implementation complexity. Add some tests accordingly. Change-Id: Ie10339e5da486a4e2a3e5d31557016be8b3f4fc6 Implements: blueprint workflow-execution-description-support
This commit is contained in:
		| @@ -26,10 +26,14 @@ class Execution(base.Resource): | ||||
| class ExecutionManager(base.ResourceManager): | ||||
|     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) | ||||
|  | ||||
|         data = {'workflow_name': workflow_name} | ||||
|         data = { | ||||
|             'workflow_name': workflow_name, | ||||
|             'description': description | ||||
|         } | ||||
|  | ||||
|         if workflow_input: | ||||
|             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): | ||||
|         return self.create(workflow_name, workflow_input, **params) | ||||
|  | ||||
|     def update(self, id, state): | ||||
|         self._ensure_not_empty(id=id, state=state) | ||||
|     def update(self, id, state, description=None): | ||||
|         if state: | ||||
|             data = {'state': state} | ||||
|  | ||||
|         data = { | ||||
|             'state': state | ||||
|         } | ||||
|         if description: | ||||
|             data = ({'description': description}) | ||||
|  | ||||
|         return self._update('/executions/%s' % id, data) | ||||
|  | ||||
|   | ||||
| @@ -35,6 +35,7 @@ def format(execution=None, lister=False): | ||||
|     columns = ( | ||||
|         'ID', | ||||
|         'Workflow', | ||||
|         'Description', | ||||
|         'State', | ||||
|         'State info', | ||||
|         'Created at', | ||||
| @@ -49,6 +50,7 @@ def format(execution=None, lister=False): | ||||
|         data = ( | ||||
|             execution.id, | ||||
|             execution.workflow_name, | ||||
|             execution.description, | ||||
|             execution.state, | ||||
|             state_info, | ||||
|             execution.created_at, | ||||
| @@ -107,6 +109,13 @@ class Create(show.ShowOne): | ||||
|             nargs='?', | ||||
|             help='Workflow additional parameters' | ||||
|         ) | ||||
|         parser.add_argument( | ||||
|             '-d', | ||||
|             '--description', | ||||
|             dest='description', | ||||
|             default='', | ||||
|             help='Execution description' | ||||
|         ) | ||||
|  | ||||
|         return parser | ||||
|  | ||||
| @@ -130,6 +139,7 @@ class Create(show.ShowOne): | ||||
|         execution = executions.ExecutionManager(self.app.client).create( | ||||
|             parsed_args.workflow_name, | ||||
|             wf_input, | ||||
|             parsed_args.description, | ||||
|             **params) | ||||
|  | ||||
|         return format(execution) | ||||
| @@ -169,18 +179,29 @@ class Update(show.ShowOne): | ||||
|             'id', | ||||
|             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'], | ||||
|             help='Execution state' | ||||
|         ) | ||||
|         group.add_argument( | ||||
|             '-d', | ||||
|             '--description', | ||||
|             dest='description', | ||||
|             help='Execution description' | ||||
|         ) | ||||
|  | ||||
|         return parser | ||||
|  | ||||
|     def take_action(self, parsed_args): | ||||
|         execution = executions.ExecutionManager(self.app.client).update( | ||||
|             parsed_args.id, | ||||
|             parsed_args.state) | ||||
|             parsed_args.state, | ||||
|             parsed_args.description) | ||||
|  | ||||
|         return format(execution) | ||||
|  | ||||
|   | ||||
| @@ -289,15 +289,19 @@ class ExecutionCLITests(base_v2.MistralClientTestBase): | ||||
|  | ||||
|     def test_execution_create_delete(self): | ||||
|         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') | ||||
|         self.assertTableStruct(execution, ['Field', 'Value']) | ||||
|  | ||||
|         wf = self.get_value_of_field(execution, 'Workflow') | ||||
|         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.assertIsNotNone(created_at) | ||||
|         self.assertEqual(description, "execution test") | ||||
|  | ||||
|         execs = self.mistral_admin('execution-list') | ||||
|         self.assertIn(exec_id, [ex['ID'] for ex in execs]) | ||||
| @@ -321,8 +325,9 @@ class ExecutionCLITests(base_v2.MistralClientTestBase): | ||||
|  | ||||
|         self.assertEqual('RUNNING', status) | ||||
|  | ||||
|         # update execution state | ||||
|         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') | ||||
|         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('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): | ||||
|         execution = self.execution_create(self.direct_wf['Name']) | ||||
|         exec_id = self.get_value_of_field(execution, 'ID') | ||||
| @@ -892,7 +907,16 @@ class NegativeCLITests(base_v2.MistralClientTestBase): | ||||
|         self.assertRaises(exceptions.CommandFailed, | ||||
|                           self.mistral_admin, | ||||
|                           '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): | ||||
|         self.assertRaises(exceptions.CommandFailed, | ||||
|   | ||||
| @@ -24,6 +24,7 @@ from mistralclient.tests.unit import base | ||||
| EXECUTION = executions.Execution(mock, { | ||||
|     'id': '123', | ||||
|     'workflow_name': 'some', | ||||
|     'description': '', | ||||
|     'state': 'RUNNING', | ||||
|     'state_info': None, | ||||
|     'created_at': '1', | ||||
| @@ -39,7 +40,7 @@ class TestCLIExecutionsV2(base.BaseCommandTest): | ||||
|         result = self.call(execution_cmd.Create, | ||||
|                            app_args=['id', '{ "context": true }']) | ||||
|  | ||||
|         self.assertEqual(('123', 'some', 'RUNNING', None, | ||||
|         self.assertEqual(('123', 'some', '', 'RUNNING', None, | ||||
|                           '1', '1'), result[1]) | ||||
|  | ||||
|     @mock.patch('mistralclient.api.v2.executions.ExecutionManager.create') | ||||
| @@ -50,7 +51,17 @@ class TestCLIExecutionsV2(base.BaseCommandTest): | ||||
|         result = self.call(execution_cmd.Create, | ||||
|                            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]) | ||||
|  | ||||
|     @mock.patch('mistralclient.api.v2.executions.ExecutionManager.update') | ||||
| @@ -58,9 +69,9 @@ class TestCLIExecutionsV2(base.BaseCommandTest): | ||||
|         mock.return_value = EXECUTION | ||||
|  | ||||
|         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]) | ||||
|  | ||||
|     @mock.patch('mistralclient.api.v2.executions.ExecutionManager.list') | ||||
| @@ -69,7 +80,7 @@ class TestCLIExecutionsV2(base.BaseCommandTest): | ||||
|  | ||||
|         result = self.call(execution_cmd.List) | ||||
|  | ||||
|         self.assertEqual([('123', 'some', 'RUNNING', None, | ||||
|         self.assertEqual([('123', 'some', '', 'RUNNING', None, | ||||
|                           '1', '1')], result[1]) | ||||
|  | ||||
|     @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']) | ||||
|  | ||||
|         self.assertEqual(('123', 'some', 'RUNNING', None, | ||||
|         self.assertEqual(('123', 'some', '', 'RUNNING', None, | ||||
|                           '1', '1'), result[1]) | ||||
|  | ||||
|     @mock.patch('mistralclient.api.v2.executions.ExecutionManager.delete') | ||||
|   | ||||
| @@ -24,6 +24,7 @@ from mistralclient.tests.unit.v2 import base | ||||
| EXEC = { | ||||
|     'id': "123", | ||||
|     'workflow_name': 'my_wf', | ||||
|     'description': '', | ||||
|     'state': 'RUNNING', | ||||
|     'input': { | ||||
|         "person": { | ||||
| @@ -43,6 +44,7 @@ class TestExecutionsV2(base.BaseClientV2Test): | ||||
|         mock = self.mock_http_post(content=EXEC) | ||||
|         body = { | ||||
|             'workflow_name': EXEC['workflow_name'], | ||||
|             'description': '', | ||||
|             'input': json.dumps(EXEC['input']), | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 LingxianKong
					LingxianKong