Provide an ability to make action/workflow public
Closes-Bug: #1436384 Depends-On: I776d10e8c3303e6c7d6430a0f338d6f6cbb255a9 Change-Id: I4a4072f0a4387ab4cc79522403d9f4daa9d4f01e
This commit is contained in:
		| @@ -22,11 +22,11 @@ class Action(base.Resource): | ||||
| class ActionManager(base.ResourceManager): | ||||
|     resource_class = Action | ||||
|  | ||||
|     def create(self, definition): | ||||
|     def create(self, definition, scope='private'): | ||||
|         self._ensure_not_empty(definition=definition) | ||||
|  | ||||
|         resp = self.client.http_client.post( | ||||
|             '/actions', | ||||
|             '/actions?scope=%s' % scope, | ||||
|             definition, | ||||
|             headers={'content-type': 'text/plain'} | ||||
|         ) | ||||
| @@ -37,11 +37,11 @@ class ActionManager(base.ResourceManager): | ||||
|         return [self.resource_class(self, resource_data) | ||||
|                 for resource_data in base.extract_json(resp, 'actions')] | ||||
|  | ||||
|     def update(self, definition): | ||||
|     def update(self, definition, scope='private'): | ||||
|         self._ensure_not_empty(definition=definition) | ||||
|  | ||||
|         resp = self.client.http_client.put( | ||||
|             '/actions', | ||||
|             '/actions?scope=%s' % scope, | ||||
|             definition, | ||||
|             headers={'content-type': 'text/plain'} | ||||
|         ) | ||||
|   | ||||
| @@ -23,11 +23,11 @@ class Workflow(base.Resource): | ||||
| class WorkflowManager(base.ResourceManager): | ||||
|     resource_class = Workflow | ||||
|  | ||||
|     def create(self, definition): | ||||
|     def create(self, definition, scope='private'): | ||||
|         self._ensure_not_empty(definition=definition) | ||||
|  | ||||
|         resp = self.client.http_client.post( | ||||
|             '/workflows', | ||||
|             '/workflows?scope=%s' % scope, | ||||
|             definition, | ||||
|             headers={'content-type': 'text/plain'} | ||||
|         ) | ||||
| @@ -38,11 +38,11 @@ class WorkflowManager(base.ResourceManager): | ||||
|         return [self.resource_class(self, resource_data) | ||||
|                 for resource_data in base.extract_json(resp, 'workflows')] | ||||
|  | ||||
|     def update(self, definition): | ||||
|     def update(self, definition, scope='private'): | ||||
|         self._ensure_not_empty(definition=definition) | ||||
|  | ||||
|         resp = self.client.http_client.put( | ||||
|             '/workflows', | ||||
|             '/workflows?scope=%s' % scope, | ||||
|             definition, | ||||
|             headers={'content-type': 'text/plain'} | ||||
|         ) | ||||
|   | ||||
| @@ -105,6 +105,11 @@ class Create(base.MistralLister): | ||||
|             type=argparse.FileType('r'), | ||||
|             help='Action definition file' | ||||
|         ) | ||||
|         parser.add_argument( | ||||
|             '--public', | ||||
|             action='store_true', | ||||
|             help='With this flag action will be marked as "public".' | ||||
|         ) | ||||
|  | ||||
|         return parser | ||||
|  | ||||
| @@ -116,8 +121,12 @@ class Create(base.MistralLister): | ||||
|         return format_list | ||||
|  | ||||
|     def _get_resources(self, parsed_args): | ||||
|         scope = 'public' if parsed_args.public else 'private' | ||||
|  | ||||
|         return actions.ActionManager(self.app.client).create( | ||||
|             parsed_args.definition.read()) | ||||
|             parsed_args.definition.read(), | ||||
|             scope=scope | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class Delete(command.Command): | ||||
| @@ -151,6 +160,11 @@ class Update(base.MistralLister): | ||||
|             type=argparse.FileType('r'), | ||||
|             help='Action definition file' | ||||
|         ) | ||||
|         parser.add_argument( | ||||
|             '--public', | ||||
|             action='store_true', | ||||
|             help='With this flag action will be marked as "public".' | ||||
|         ) | ||||
|  | ||||
|         return parser | ||||
|  | ||||
| @@ -158,8 +172,12 @@ class Update(base.MistralLister): | ||||
|         return format | ||||
|  | ||||
|     def _get_resources(self, parsed_args): | ||||
|         scope = 'public' if parsed_args.public else 'private' | ||||
|  | ||||
|         return actions.ActionManager(self.app.client).update( | ||||
|             parsed_args.definition.read()) | ||||
|             parsed_args.definition.read(), | ||||
|             scope=scope | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class GetDefinition(command.Command): | ||||
|   | ||||
| @@ -98,6 +98,11 @@ class Create(base.MistralLister): | ||||
|             type=argparse.FileType('r'), | ||||
|             help='Workflow definition file' | ||||
|         ) | ||||
|         parser.add_argument( | ||||
|             '--public', | ||||
|             action='store_true', | ||||
|             help='With this flag workflow will be marked as "public".' | ||||
|         ) | ||||
|  | ||||
|         return parser | ||||
|  | ||||
| @@ -110,8 +115,12 @@ class Create(base.MistralLister): | ||||
|                                "definition file.") | ||||
|  | ||||
|     def _get_resources(self, parsed_args): | ||||
|         scope = 'public' if parsed_args.public else 'private' | ||||
|  | ||||
|         return workflows.WorkflowManager(self.app.client).create( | ||||
|             parsed_args.definition.read()) | ||||
|             parsed_args.definition.read(), | ||||
|             scope=scope | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class Delete(command.Command): | ||||
| @@ -145,6 +154,11 @@ class Update(base.MistralLister): | ||||
|             type=argparse.FileType('r'), | ||||
|             help='Workflow definition' | ||||
|         ) | ||||
|         parser.add_argument( | ||||
|             '--public', | ||||
|             action='store_true', | ||||
|             help='With this flag workflow will be marked as "public".' | ||||
|         ) | ||||
|  | ||||
|         return parser | ||||
|  | ||||
| @@ -152,8 +166,11 @@ class Update(base.MistralLister): | ||||
|         return format | ||||
|  | ||||
|     def _get_resources(self, parsed_args): | ||||
|         scope = 'public' if parsed_args.public else 'private' | ||||
|  | ||||
|         return workflows.WorkflowManager(self.app.client).update( | ||||
|             parsed_args.definition.read() | ||||
|             parsed_args.definition.read(), | ||||
|             scope=scope | ||||
|         ) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -92,29 +92,47 @@ class MistralClientTestBase(base.MistralCLIAuth, base.MistralCLIAltAuth): | ||||
|  | ||||
|         return wb | ||||
|  | ||||
|     def workflow_create(self, wf_def, admin=True): | ||||
|     def workflow_create(self, wf_def, admin=True, scope='private'): | ||||
|         params = '{0}'.format(wf_def) | ||||
|  | ||||
|         if scope == 'public': | ||||
|             params += ' --public' | ||||
|  | ||||
|         wf = self.mistral_cli( | ||||
|             admin, | ||||
|             'workflow-create', | ||||
|             params='{0}'.format(wf_def)) | ||||
|             params=params | ||||
|         ) | ||||
|  | ||||
|         for workflow in wf: | ||||
|             self.addCleanup(self.mistral_cli, | ||||
|             self.addCleanup( | ||||
|                 self.mistral_cli, | ||||
|                 admin, | ||||
|                 'workflow-delete', | ||||
|                             params=workflow['Name']) | ||||
|                 params=workflow['Name'] | ||||
|             ) | ||||
|  | ||||
|         return wf | ||||
|  | ||||
|     def action_create(self, act_def, admin=True): | ||||
|     def action_create(self, act_def, admin=True, scope='private'): | ||||
|         params = '{0}'.format(act_def) | ||||
|  | ||||
|         if scope == 'public': | ||||
|             params += ' --public' | ||||
|  | ||||
|         acts = self.mistral_cli( | ||||
|             admin, | ||||
|             'action-create', | ||||
|             params='{0}'.format(act_def)) | ||||
|             params=params | ||||
|         ) | ||||
|  | ||||
|         for action in acts: | ||||
|             self.addCleanup(self.mistral_cli, | ||||
|             self.addCleanup( | ||||
|                 self.mistral_cli, | ||||
|                 admin, | ||||
|                 'action-delete', | ||||
|                             params=action['Name']) | ||||
|                 params=action['Name'] | ||||
|             ) | ||||
|  | ||||
|         return acts | ||||
|  | ||||
|   | ||||
| @@ -156,6 +156,19 @@ class WorkflowIsolationCLITests(base_v2.MistralClientTestBase): | ||||
|             params=wf[0]["Name"] | ||||
|         ) | ||||
|  | ||||
|     def test_create_public_workflow(self): | ||||
|         wf = self.workflow_create(self.wf_def, scope='public') | ||||
|  | ||||
|         same_wf = self.mistral_alt_user( | ||||
|             "workflow-get", | ||||
|             params=wf[0]["Name"] | ||||
|         ) | ||||
|  | ||||
|         self.assertEqual( | ||||
|             wf[0]["Name"], | ||||
|             self.get_value_of_field(same_wf, "Name") | ||||
|         ) | ||||
|  | ||||
|     def test_delete_wf_from_another_tenant(self): | ||||
|         wf = self.workflow_create(self.wf_def) | ||||
|  | ||||
| @@ -218,6 +231,19 @@ class ActionIsolationCLITests(base_v2.MistralClientTestBase): | ||||
|             params=act[0]["Name"] | ||||
|         ) | ||||
|  | ||||
|     def test_create_public_action(self): | ||||
|         act = self.action_create(self.act_def, scope='public') | ||||
|  | ||||
|         same_act = self.mistral_alt_user( | ||||
|             "action-get", | ||||
|             params=act[0]["Name"] | ||||
|         ) | ||||
|  | ||||
|         self.assertEqual( | ||||
|             act[0]["Name"], | ||||
|             self.get_value_of_field(same_act, "Name") | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class CronTriggerIsolationCLITests(base_v2.MistralClientTestBase): | ||||
|  | ||||
|   | ||||
| @@ -62,6 +62,23 @@ class TestCLIActionsV2(base.BaseCommandTest): | ||||
|             result[1] | ||||
|         ) | ||||
|  | ||||
|     @mock.patch('argparse.open', create=True) | ||||
|     @mock.patch('mistralclient.api.v2.actions.ActionManager.create') | ||||
|     def test_create_public(self, mock, mock_open): | ||||
|         mock.return_value = (ACTION,) | ||||
|  | ||||
|         result = self.call( | ||||
|             action_cmd.Create, | ||||
|             app_args=['1.txt', '--public'] | ||||
|         ) | ||||
|  | ||||
|         self.assertEqual( | ||||
|             [('a', True, "param1", 'My cool action', 'test', '1', '1')], | ||||
|             result[1] | ||||
|         ) | ||||
|  | ||||
|         self.assertEqual('public', mock.call_args[1]['scope']) | ||||
|  | ||||
|     @mock.patch('argparse.open', create=True) | ||||
|     @mock.patch('mistralclient.api.v2.actions.ActionManager.create') | ||||
|     def test_create_long_input(self, mock, mock_open): | ||||
| @@ -93,6 +110,23 @@ class TestCLIActionsV2(base.BaseCommandTest): | ||||
|             result[1] | ||||
|         ) | ||||
|  | ||||
|     @mock.patch('argparse.open', create=True) | ||||
|     @mock.patch('mistralclient.api.v2.actions.ActionManager.update') | ||||
|     def test_update_public(self, mock, mock_open): | ||||
|         mock.return_value = (ACTION,) | ||||
|  | ||||
|         result = self.call( | ||||
|             action_cmd.Update, | ||||
|             app_args=['my_action.yaml', '--public'] | ||||
|         ) | ||||
|  | ||||
|         self.assertEqual( | ||||
|             [('a', True, "param1", 'My cool action', 'test', '1', '1')], | ||||
|             result[1] | ||||
|         ) | ||||
|  | ||||
|         self.assertEqual('public', mock.call_args[1]['scope']) | ||||
|  | ||||
|     @mock.patch('mistralclient.api.v2.actions.ActionManager.list') | ||||
|     def test_list(self, mock): | ||||
|         mock.return_value = (ACTION,) | ||||
|   | ||||
| @@ -56,6 +56,20 @@ class TestCLIWorkflowsV2(base.BaseCommandTest): | ||||
|  | ||||
|         self.assertEqual([('a', 'a, b', 'param', '1', '1')], result[1]) | ||||
|  | ||||
|     @mock.patch('argparse.open', create=True) | ||||
|     @mock.patch('mistralclient.api.v2.workflows.WorkflowManager.create') | ||||
|     def test_create_public(self, mock, mock_open): | ||||
|         mock.return_value = (WORKFLOW,) | ||||
|  | ||||
|         result = self.call( | ||||
|             workflow_cmd.Create, | ||||
|             app_args=['1.txt', '--public'] | ||||
|         ) | ||||
|  | ||||
|         self.assertEqual([('a', 'a, b', 'param', '1', '1')], result[1]) | ||||
|  | ||||
|         self.assertEqual('public', mock.call_args[1]['scope']) | ||||
|  | ||||
|     @mock.patch('argparse.open', create=True) | ||||
|     @mock.patch('mistralclient.api.v2.workflows.WorkflowManager.create') | ||||
|     def test_create_long_input(self, mock, mock_open): | ||||
| @@ -83,6 +97,20 @@ class TestCLIWorkflowsV2(base.BaseCommandTest): | ||||
|  | ||||
|         self.assertEqual([('a', 'a, b', 'param', '1', '1')], result[1]) | ||||
|  | ||||
|     @mock.patch('argparse.open', create=True) | ||||
|     @mock.patch('mistralclient.api.v2.workflows.WorkflowManager.update') | ||||
|     def test_update_public(self, mock, mock_open): | ||||
|         mock.return_value = (WORKFLOW,) | ||||
|  | ||||
|         result = self.call( | ||||
|             workflow_cmd.Update, | ||||
|             app_args=['1.txt', '--public'] | ||||
|         ) | ||||
|  | ||||
|         self.assertEqual([('a', 'a, b', 'param', '1', '1')], result[1]) | ||||
|  | ||||
|         self.assertEqual('public', mock.call_args[1]['scope']) | ||||
|  | ||||
|     @mock.patch('mistralclient.api.v2.workflows.WorkflowManager.list') | ||||
|     def test_list(self, mock): | ||||
|         mock.return_value = (WORKFLOW,) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Nikolay Mahotkin
					Nikolay Mahotkin