From 5c21d5379870dc7c4088a448964d0109b5f303c4 Mon Sep 17 00:00:00 2001 From: Anastasia Kuznetsova Date: Tue, 11 Nov 2014 13:10:36 +0400 Subject: [PATCH] Add CLI multi tenancy tests - Refactor CLI tests infrastructure - Added auth in Mistral by two different users - Removed tearDown methods, add usage of addCleanup methods - Create new base methods like 'workbook-create', which contain addCleanup call and makes tests more clear for reading Implements: blueprint mistral-milti-tenancy-tests Change-Id: I4a58b4c1bfff192912f3f1d149869656f7e9c54b --- mistralclient/tests/functional/cli/base.py | 34 +- .../tests/functional/cli/v2/base_v2.py | 117 +++++ .../cli/v2/cli_multi_tenancy_tests.py | 199 +++++++++ .../tests/functional/cli/v2/cli_tests_v2.py | 417 +++++------------- 4 files changed, 468 insertions(+), 299 deletions(-) create mode 100644 mistralclient/tests/functional/cli/v2/base_v2.py create mode 100644 mistralclient/tests/functional/cli/v2/cli_multi_tenancy_tests.py diff --git a/mistralclient/tests/functional/cli/base.py b/mistralclient/tests/functional/cli/base.py index 45d7528f..74ddfe09 100644 --- a/mistralclient/tests/functional/cli/base.py +++ b/mistralclient/tests/functional/cli/base.py @@ -15,25 +15,28 @@ import os from tempest import config -from tempest import test from tempest_lib.cli import base CONF = config.CONF -class MistralCLIAuth(base.ClientTestBase, test.BaseTestCase): +class MistralCLIAuth(base.ClientTestBase): _mistral_url = None - def _get_clients(self): + def _get_admin_clients(self): clients = base.CLIClient( CONF.identity.admin_username, CONF.identity.admin_password, CONF.identity.admin_tenant_name, CONF.identity.uri, CONF.cli.cli_dir) + return clients + def _get_clients(self): + return self._get_admin_clients() + def mistral(self, action, flags='', params='', fail_ok=False): """Executes Mistral command.""" mistral_url_op = "--os-mistral-url %s" % self._mistral_url @@ -46,3 +49,28 @@ class MistralCLIAuth(base.ClientTestBase, test.BaseTestCase): return self.clients.cmd_with_auth( 'mistral %s' % mistral_url_op, action, flags, params, fail_ok) + + +class MistralCLIAltAuth(base.ClientTestBase): + + _mistral_url = None + + def _get_alt_clients(self): + clients = base.CLIClient( + CONF.identity.alt_username, + CONF.identity.alt_password, + CONF.identity.alt_tenant_name, + CONF.identity.uri, + CONF.cli.cli_dir) + + return clients + + def _get_clients(self): + return self._get_alt_clients() + + def mistral_alt(self, action, flags='', params='', mode='alt_user'): + """Executes Mistral command for alt_user from alt_tenant.""" + mistral_url_op = "--os-mistral-url %s" % self._mistral_url + + return self.clients.cmd_with_auth( + 'mistral %s' % mistral_url_op, action, flags, params) diff --git a/mistralclient/tests/functional/cli/v2/base_v2.py b/mistralclient/tests/functional/cli/v2/base_v2.py new file mode 100644 index 00000000..2e101881 --- /dev/null +++ b/mistralclient/tests/functional/cli/v2/base_v2.py @@ -0,0 +1,117 @@ +# Copyright (c) 2014 Mirantis, Inc. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os + +from mistralclient.tests.functional.cli import base + + +MISTRAL_URL = "http://localhost:8989/v2" + + +class MistralClientTestBase(base.MistralCLIAuth, base.MistralCLIAltAuth): + + _mistral_url = MISTRAL_URL + + @classmethod + def setUpClass(cls): + super(MistralClientTestBase, cls).setUpClass() + + cls.wb_def = os.path.relpath( + 'functionaltests/resources/v2/wb_v2.yaml', os.getcwd()) + + cls.wb_with_tags_def = os.path.relpath( + 'functionaltests/resources/v2/wb_with_tags_v2.yaml', os.getcwd()) + + cls.wf_def = os.path.relpath( + 'functionaltests/resources/v2/wf_v2.yaml', os.getcwd()) + + cls.wf_with_delay_def = os.path.relpath( + 'functionaltests/resources/v2/wf_delay_v2.yaml', os.getcwd()) + + cls.act_def = os.path.relpath( + 'functionaltests/resources/v2/action_v2.yaml', os.getcwd()) + + def setUp(self): + super(MistralClientTestBase, self).setUp() + + def get_value_of_field(self, obj, field): + return [o['Value'] for o in obj + if o['Field'] == "{0}".format(field)][0] + + def get_item_info(self, get_from, get_by, value): + return [i for i in get_from if i[get_by] == value][0] + + def mistral_admin(self, cmd, params=""): + self.clients = self._get_admin_clients() + return self.parser.listing(self.mistral( + '{0}'.format(cmd), params='{0}'.format(params))) + + def mistral_alt_user(self, cmd, params=""): + self.clients = self._get_alt_clients() + return self.parser.listing(self.mistral_alt( + '{0}'.format(cmd), params='{0}'.format(params))) + + def mistral_cli(self, admin, cmd, params): + if admin: + return self.mistral_admin(cmd, params) + else: + return self.mistral_alt_user(cmd, params) + + def workbook_create(self, wb_def, admin=True): + wb = self.mistral_cli( + admin, 'workbook-create', params='{0}'.format(wb_def)) + wb_name = self.get_value_of_field(wb, "Name") + self.addCleanup(self.mistral_cli, + admin, 'workbook-delete', params=wb_name) + self.addCleanup(self.mistral_cli, + admin, 'workflow-delete', params='wb.wf1') + + return wb + + def workflow_create(self, wf_def, admin=True): + wf = self.mistral_cli( + admin, 'workflow-create', params='{0}'.format(wf_def)) + for workflow in wf: + self.addCleanup(self.mistral_cli, admin, + 'workflow-delete', params=workflow['Name']) + + return wf + + def action_create(self, act_def, admin=True): + acts = self.mistral_cli( + admin, 'action-create', params='{0}'.format(act_def)) + for action in acts: + self.addCleanup(self.mistral_cli, admin, + 'action-delete', params=action['Name']) + + return acts + + def cron_trigger_create(self, name, pattern, + wf_name, wf_input, admin=True): + trigger = self.mistral_cli( + admin, 'cron-trigger-create', + params='%s "%s" %s %s' % (name, pattern, wf_name, wf_input)) + self.addCleanup(self.mistral_cli, admin, + 'cron-trigger-delete', params=name) + + return trigger + + def execution_create(self, wf_name, admin=True): + ex = self.mistral_cli(admin, 'execution-create', params=wf_name) + exec_id = self.get_value_of_field(ex, 'ID') + self.addCleanup(self.mistral_cli, admin, + 'execution-delete', params=exec_id) + + return ex diff --git a/mistralclient/tests/functional/cli/v2/cli_multi_tenancy_tests.py b/mistralclient/tests/functional/cli/v2/cli_multi_tenancy_tests.py new file mode 100644 index 00000000..808fb633 --- /dev/null +++ b/mistralclient/tests/functional/cli/v2/cli_multi_tenancy_tests.py @@ -0,0 +1,199 @@ +# Copyright (c) 2014 Mirantis, Inc. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest import test +from tempest_lib import exceptions + +from mistralclient.tests.functional.cli.v2 import base_v2 + + +class MultiTenancyCLITests(base_v2.MistralClientTestBase): + + @classmethod + def setUpClass(cls): + super(MultiTenancyCLITests, cls).setUpClass() + + def test_std_workflows_availability(self): + wfs = self.mistral_admin('workflow-list') + self.assertTableStruct(wfs, + ['Name', 'Tags', 'Input', + 'Created at', 'Updated at']) + self.assertIn('std.create_instance', + [workflow['Name'] for workflow in wfs]) + + wfs = self.mistral_alt_user('workflow-list') + self.assertTableStruct(wfs, + ['Name', 'Tags', 'Input', + 'Created at', 'Updated at']) + self.assertIn('std.create_instance', + [workflow['Name'] for workflow in wfs]) + + def test_std_actions_availability(self): + acts = self.mistral_admin('action-list') + self.assertTableStruct(acts, + ['Name', 'Is system', 'Input', + 'Description', 'Tags', 'Created at', + 'Updated at']) + self.assertIn('glance.images_list', + [action['Name'] for action in acts]) + + acts = self.mistral_alt_user('action-list') + self.assertTableStruct(acts, + ['Name', 'Is system', 'Input', + 'Description', 'Tags', 'Created at', + 'Updated at']) + self.assertIn('glance.images_list', + [action['Name'] for action in acts]) + + def test_workbook_name_uniqueness(self): + self.workbook_create(self.wb_def) + self.assertRaises(exceptions.CommandFailed, + self.mistral_admin, 'workbook-create', + params='{0}'.format(self.wb_def)) + + self.workbook_create(self.wb_def, admin=False) + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'workbook-create', + params='{0}'.format(self.wb_def)) + + def test_workflow_name_uniqueness(self): + self.workflow_create(self.wf_def) + self.assertRaises(exceptions.CommandFailed, + self.mistral_admin, 'workflow-create', + params='{0}'.format(self.wf_def)) + + self.workflow_create(self.wf_def, admin=False) + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'workflow-create', + params='{0}'.format(self.wf_def)) + + def test_actions_name_uniqueness(self): + self.action_create(self.act_def) + self.assertRaises(exceptions.CommandFailed, + self.mistral_admin, 'action-create', + params='{0}'.format(self.act_def)) + + self.action_create(self.act_def, admin=False) + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'action-create', + params='{0}'.format(self.act_def)) + + def test_cron_trigger_name_uniqueness(self): + wf = self.workflow_create(self.wf_def) + self.cron_trigger_create( + 'trigger', '5 * * * *', wf[0]['Name'], '{}') + self.assertRaises(exceptions.CommandFailed, + self.cron_trigger_create, + 'trigger', '5 * * * *', wf[0]['Name'], '{}') + + wf = self.workflow_create(self.wf_def, admin=False) + self.cron_trigger_create( + 'trigger', '5 * * * *', wf[0]['Name'], '{}', admin=False) + self.assertRaises(exceptions.CommandFailed, + self.cron_trigger_create, + 'trigger', '5 * * * *', wf[0]['Name'], '{}', + admin=False) + + def test_wb_isolation(self): + wb = self.workbook_create(self.wb_def) + wb_name = self.get_value_of_field(wb, 'Name') + wbs = self.mistral_admin('workbook-list') + self.assertIn(wb_name, [w['Name'] for w in wbs]) + + alt_wbs = self.mistral_alt_user('workbook-list') + self.assertNotIn(wb_name, [w['Name'] for w in alt_wbs]) + + def test_wf_isolation(self): + wf = self.workflow_create(self.wf_def) + wfs = self.mistral_admin('workflow-list') + self.assertIn(wf[0]['Name'], [w['Name'] for w in wfs]) + + alt_wfs = self.mistral_alt_user('workflow-list') + self.assertNotIn(wf[0]['Name'], [w['Name'] for w in alt_wfs]) + + def test_action_isolation(self): + act = self.action_create(self.act_def) + acts = self.mistral_admin('action-list') + self.assertIn(act[0]['Name'], [a['Name'] for a in acts]) + + alt_acts = self.mistral_alt_user('action-list') + self.assertNotIn(act[0]['Name'], [a['Name'] for a in alt_acts]) + + def test_cron_trigger_isolation(self): + wf = self.workflow_create(self.wf_def) + self.cron_trigger_create( + 'trigger', '5 * * * *', wf[0]['Name'], '{}') + + alt_trs = self.mistral_alt_user('cron-trigger-list') + self.assertNotIn('trigger', [t['Name'] for t in alt_trs]) + + @test.skip_because(bug='1384552') + def test_execution_isolation(self): + wf = self.workflow_create(self.wf_def) + ex = self.execution_create(wf[0]['Name']) + exec_id = self.get_value_of_field(ex, 'ID') + + execs = self.mistral_admin('execution-list') + self.assertIn(exec_id, [e['ID'] for e in execs]) + + alt_execs = self.mistral_alt_user('execution-list') + self.assertNotIn(exec_id, [e['ID'] for e in alt_execs]) + + def test_get_wb_from_another_tenant(self): + wb = self.workbook_create(self.wb_def) + name = self.get_value_of_field(wb, 'Name') + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'workbook-get', + params=name) + + def test_delete_wb_from_another_tenant(self): + wb = self.workbook_create(self.wb_def) + name = self.get_value_of_field(wb, 'Name') + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'workbook-delete', + params=name) + + def test_get_wf_from_another_tenant(self): + wf = self.workflow_create(self.wf_def) + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'workflow-get', + params=wf[0]['Name']) + + def test_delete_wf_from_another_tenant(self): + wf = self.workflow_create(self.wf_def) + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'workflow-delete', + params=wf[0]['Name']) + + def test_get_action_from_another_tenant(self): + act = self.action_create(self.act_def) + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'action-get', + params=act[0]['Name']) + + def test_delete_action_from_another_tenant(self): + act = self.action_create(self.act_def) + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'action-delete', + params=act[0]['Name']) + + @test.skip_because(bug='1384552') + def test_get_execution_from_another_tenant(self): + wf = self.workflow_create(self.wf_def) + ex = self.execution_create(wf[0]['Name']) + exec_id = self.get_value_of_field(ex, 'ID') + + self.assertRaises(exceptions.CommandFailed, + self.mistral_alt_user, 'execution-get', + params=exec_id) diff --git a/mistralclient/tests/functional/cli/v2/cli_tests_v2.py b/mistralclient/tests/functional/cli/v2/cli_tests_v2.py index be32a2e9..e574cab1 100644 --- a/mistralclient/tests/functional/cli/v2/cli_tests_v2.py +++ b/mistralclient/tests/functional/cli/v2/cli_tests_v2.py @@ -12,11 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -import os - from tempest_lib import exceptions from mistralclient.tests.functional.cli import base +from mistralclient.tests.functional.cli.v2 import base_v2 MISTRAL_URL = "http://localhost:8989/v2" @@ -74,101 +73,39 @@ class SimpleMistralCLITests(base.MistralCLIAuth): 'Updated at']) -class ClientTestBase(base.MistralCLIAuth): - - _mistral_url = MISTRAL_URL - - @classmethod - def setUpClass(cls): - super(ClientTestBase, cls).setUpClass() - - cls.wb_def = os.path.relpath( - 'functionaltests/resources/v2/wb_v2.yaml', os.getcwd()) - - cls.wb_with_tags_def = os.path.relpath( - 'functionaltests/resources/v2/wb_with_tags_v2.yaml', os.getcwd()) - - cls.wf_def = os.path.relpath( - 'functionaltests/resources/v2/wf_v2.yaml', os.getcwd()) - - cls.wf_with_delay_def = os.path.relpath( - 'functionaltests/resources/v2/wf_delay_v2.yaml', os.getcwd()) - - cls.act_def = os.path.relpath( - 'functionaltests/resources/v2/action_v2.yaml', os.getcwd()) - - def setUp(self): - super(ClientTestBase, self).setUp() - - self.actions = [] - self.executions = [] - self.workflows = [] - self.workbooks = [] - self.cron_triggers = [] - - def tearDown(self): - super(ClientTestBase, self).tearDown() - - del self.actions - del self.executions - del self.workflows - del self.workbooks - del self.cron_triggers - - def get_value_of_field(self, obj, field): - return [o['Value'] for o in obj - if o['Field'] == "{0}".format(field)][0] - - def get_item_info(self, get_from, get_by, value): - return [i for i in get_from if i[get_by] == value][0] - - def mistral_command(self, cmd, params=""): - return self.parser.listing(self.mistral('{0}'.format(cmd), - params='{0}'.format(params))) - - -class WorkbookCLITests(ClientTestBase): +class WorkbookCLITests(base_v2.MistralClientTestBase): """Test suite checks commands to work with workbooks.""" @classmethod def setUpClass(cls): super(WorkbookCLITests, cls).setUpClass() - def tearDown(self): - for wb in self.workbooks: - self.mistral('workbook-delete', params=wb) - - super(WorkbookCLITests, self).tearDown() - def test_workbook_create_delete(self): - wb = self.mistral_command( - 'workbook-create', params='{0}'.format(self.wb_def)) + wb = self.mistral_admin( + 'workbook-create', params=self.wb_def) wb_name = self.get_value_of_field(wb, "Name") - self.workbooks.append(wb_name) + self.assertTableStruct(wb, ['Field', 'Value']) - wbs = self.mistral_command('workbook-list') + wbs = self.mistral_admin('workbook-list') self.assertIn(wb_name, [workbook['Name'] for workbook in wbs]) - wbs = self.mistral_command('workbook-list') + wbs = self.mistral_admin('workbook-list') self.assertIn(wb_name, [workbook['Name'] for workbook in wbs]) - self.mistral_command('workbook-delete', params=wb_name) + self.mistral_admin('workbook-delete', params=wb_name) - wbs = self.mistral_command('workbook-list') + wbs = self.mistral_admin('workbook-list') self.assertNotIn(wb_name, [workbook['Name'] for workbook in wbs]) - self.workbooks.remove(wb_name) def test_workbook_update(self): - wb = self.mistral_command( - 'workbook-create', params='{0}'.format(self.wb_def)) + wb = self.workbook_create(self.wb_def) wb_name = self.get_value_of_field(wb, "Name") - self.workbooks.append(wb_name) tags = self.get_value_of_field(wb, 'Tags') self.assertNotIn('tag', tags) - wb = self.mistral_command( + wb = self.mistral_admin( 'workbook-update', params='{0}'.format(self.wb_with_tags_def)) self.assertTableStruct(wb, ['Field', 'Value']) @@ -179,12 +116,10 @@ class WorkbookCLITests(ClientTestBase): self.assertIn('tag', tags) def test_workbook_get(self): - created = self.mistral_command( - 'workbook-create', params='{0}'.format(self.wb_with_tags_def)) + created = self.workbook_create(self.wb_with_tags_def) wb_name = self.get_value_of_field(created, "Name") - self.workbooks.append(wb_name) - fetched = self.mistral_command('workbook-get', params=wb_name) + fetched = self.mistral_admin('workbook-get', params=wb_name) created_wb_name = self.get_value_of_field(created, 'Name') fetched_wb_name = self.get_value_of_field(fetched, 'Name') @@ -197,80 +132,63 @@ class WorkbookCLITests(ClientTestBase): self.assertEqual(created_wb_tag, fetched_wb_tag) def test_workbook_get_definition(self): - wb = self.mistral_command( - 'workbook-create', params='{0}'.format(self.wb_def)) + wb = self.workbook_create(self.wb_def) wb_name = self.get_value_of_field(wb, "Name") - self.workbooks.append(wb_name) - definition = self.mistral_command( + definition = self.mistral_admin( 'workbook-get-definition', params=wb_name) self.assertNotIn('404 Not Found', definition) -class WorkflowCLITests(ClientTestBase): +class WorkflowCLITests(base_v2.MistralClientTestBase): """Test suite checks commands to work with workflows.""" @classmethod def setUpClass(cls): super(WorkflowCLITests, cls).setUpClass() - def tearDown(self): - for wf in self.workflows: - self.mistral('workflow-delete', params=wf) - - super(WorkflowCLITests, self).tearDown() - def test_workflow_create_delete(self): - init_wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) + init_wf = self.mistral_admin( + 'workflow-create', params=self.wf_def) wf_name = init_wf[0]['Name'] - self.workflows.extend([workflow['Name'] for workflow in init_wf]) self.assertTableStruct(init_wf, ['Name', 'Created at', 'Updated at']) - wfs = self.mistral_command('workflow-list') + wfs = self.mistral_admin('workflow-list') self.assertIn(wf_name, [workflow['Name'] for workflow in wfs]) - self.mistral_command('workflow-delete', params=wf_name) + self.mistral_admin('workflow-delete', params=wf_name) - wfs = self.mistral_command('workflow-list') + wfs = self.mistral_admin('workflow-list') self.assertNotIn(wf_name, [workflow['Name'] for workflow in wfs]) - for w in [workflow['Name'] for workflow in init_wf]: - self.workflows.remove(w) def test_workflow_update(self): - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) + wf = self.workflow_create(self.wf_def) wf_name = wf[0]['Name'] - self.workflows.extend([workflow['Name'] for workflow in wf]) - upd_wf = self.mistral_command( + upd_wf = self.mistral_admin( 'workflow-update', params='{0}'.format(self.wf_def)) self.assertTableStruct(upd_wf, ['Name', 'Created at', 'Updated at']) self.assertEqual(wf_name, upd_wf[0]['Name']) def test_workflow_get(self): - created = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) + created = self.workflow_create(self.wf_def) wf_name = created[0]['Name'] - self.workflows.extend([workflow['Name'] for workflow in created]) - fetched = self.mistral_command('workflow-get', params=wf_name) + fetched = self.mistral_admin('workflow-get', params=wf_name) fetched_wf_name = self.get_value_of_field(fetched, 'Name') self.assertEqual(wf_name, fetched_wf_name) def test_workflow_get_definition(self): - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) + wf = self.workflow_create(self.wf_def) wf_name = wf[0]['Name'] - self.workflows.extend([workflow['Name'] for workflow in wf]) - definition = self.mistral_command( + definition = self.mistral_admin( 'workflow-get-definition', params=wf_name) self.assertNotIn('404 Not Found', definition) -class ExecutionCLITests(ClientTestBase): +class ExecutionCLITests(base_v2.MistralClientTestBase): """Test suite checks commands to work with executions.""" @classmethod @@ -280,31 +198,16 @@ class ExecutionCLITests(ClientTestBase): def setUp(self): super(ExecutionCLITests, self).setUp() - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) + wf = self.workflow_create(self.wf_def) self.wf_name = wf[0]['Name'] - self.workflows.extend([workflow['Name'] for workflow in wf]) - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_with_delay_def)) - self.wf_with_delay_name = wf[0]['Name'] - self.workflows += [self.wf_with_delay_name] - - def tearDown(self): - for ex in self.executions: - self.mistral('execution-delete', params=ex) - - self.mistral('workflow-delete', params=self.wf_name) - self.mistral('workflow-delete', params=self.wf_with_delay_name) - - super(ExecutionCLITests, self).tearDown() + wf_delay = self.workflow_create(self.wf_with_delay_def) + self.wf_delay = wf_delay[0]["Name"] def test_execution_create_delete(self): - execution = self.mistral_command( + execution = self.mistral_admin( 'execution-create', params=self.wf_name) - exec_id = self.get_value_of_field(execution, 'ID') - self.executions.append(exec_id) self.assertTableStruct(execution, ['Field', 'Value']) wf = self.get_value_of_field(execution, 'Workflow') @@ -313,25 +216,22 @@ class ExecutionCLITests(ClientTestBase): self.assertEqual(self.wf_name, wf) self.assertIsNotNone(created_at) - execs = self.mistral_command('execution-list') + execs = self.mistral_admin('execution-list') self.assertIn(exec_id, [ex['ID'] for ex in execs]) self.assertIn(wf, [ex['Workflow'] for ex in execs]) self.assertIn('SUCCESS', [ex['State'] for ex in execs]) - self.mistral_command('execution-delete', params=exec_id) - self.executions.remove(exec_id) + self.mistral_admin('execution-delete', params=exec_id) def test_execution_update(self): - execution = self.mistral_command( - 'execution-create', params=self.wf_with_delay_name) - exec_id = self.get_value_of_field(execution, 'ID') - self.executions.append(exec_id) + execution = self.execution_create(self.wf_delay) + exec_id = self.get_value_of_field(execution, 'ID') status = self.get_value_of_field(execution, 'State') self.assertEqual('RUNNING', status) - execution = self.mistral_command( + execution = self.mistral_admin( 'execution-update', params='{0} "PAUSED"'.format(exec_id)) updated_exec_id = self.get_value_of_field(execution, 'ID') @@ -341,13 +241,10 @@ class ExecutionCLITests(ClientTestBase): self.assertEqual('PAUSED', status) def test_execution_get(self): - execution = self.mistral_command( - 'execution-create', params=self.wf_name) - + execution = self.execution_create(self.wf_name) exec_id = self.get_value_of_field(execution, 'ID') - self.executions.append(exec_id) - execution = self.mistral_command( + execution = self.mistral_admin( 'execution-get', params='{0}'.format(exec_id)) gotten_id = self.get_value_of_field(execution, 'ID') @@ -357,28 +254,22 @@ class ExecutionCLITests(ClientTestBase): self.assertEqual(self.wf_name, wf) def test_execution_get_input(self): - execution = self.mistral_command( - 'execution-create', params=self.wf_name) - + execution = self.execution_create(self.wf_name) exec_id = self.get_value_of_field(execution, 'ID') - self.executions.append(exec_id) - ex_input = self.mistral_command('execution-get-input', params=exec_id) + ex_input = self.mistral_admin('execution-get-input', params=exec_id) self.assertEqual([], ex_input) def test_execution_get_output(self): - execution = self.mistral_command( - 'execution-create', params=self.wf_name) - + execution = self.execution_create(self.wf_name) exec_id = self.get_value_of_field(execution, 'ID') - self.executions.append(exec_id) - ex_output = self.mistral_command( + ex_output = self.mistral_admin( 'execution-get-output', params=exec_id) self.assertEqual([], ex_output) -class CronTriggerCLITests(ClientTestBase): +class CronTriggerCLITests(base_v2.MistralClientTestBase): """Test suite checks commands to work with cron-triggers.""" @classmethod @@ -388,25 +279,13 @@ class CronTriggerCLITests(ClientTestBase): def setUp(self): super(CronTriggerCLITests, self).setUp() - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) + wf = self.workflow_create(self.wf_def) self.wf_name = wf[0]['Name'] - self.workflows.append(self.wf_name) - - def tearDown(self): - for tr in self.cron_triggers: - self.mistral('cron-trigger-delete', params=tr) - - self.mistral('workflow-delete', params=self.wf_name) - - super(CronTriggerCLITests, self).tearDown() def test_cron_trigger_create_delete(self): - trigger = self.mistral_command( + trigger = self.mistral_admin( 'cron-trigger-create', params='trigger "5 * * * *" %s {}' % self.wf_name) - cron_tr_name = 'trigger' - self.cron_triggers.append(cron_tr_name) self.assertTableStruct(trigger, ['Field', 'Value']) tr_name = self.get_value_of_field(trigger, 'Name') @@ -417,46 +296,33 @@ class CronTriggerCLITests(ClientTestBase): self.assertEqual(self.wf_name, wf_name) self.assertIsNotNone(created_at) - trgs = self.mistral_command('cron-trigger-list') + trgs = self.mistral_admin('cron-trigger-list') self.assertIn(tr_name, [tr['Name'] for tr in trgs]) self.assertIn(wf_name, [tr['Workflow'] for tr in trgs]) self.mistral('cron-trigger-delete', params='{0}'.format(tr_name)) - trgs = self.mistral_command('cron-trigger-list') + trgs = self.mistral_admin('cron-trigger-list') self.assertNotIn(tr_name, [tr['Name'] for tr in trgs]) - self.cron_triggers.remove(cron_tr_name) def test_two_cron_triggers_for_one_wf(self): - self.mistral( - 'cron-trigger-create', - params='trigger1 "5 * * * *" %s {}' % self.wf_name) - self.cron_triggers.append('trigger1') - self.mistral( - 'cron-trigger-create', - params='trigger2 "15 * * * *" %s {}' % self.wf_name) - self.cron_triggers.append('trigger2') + self.cron_trigger_create( + 'trigger1', "5 * * * *", self.wf_name, '{}') + self.cron_trigger_create( + 'trigger2', "15 * * * *", self.wf_name, '{}') - trgs = self.mistral_command('cron-trigger-list') + trgs = self.mistral_admin('cron-trigger-list') self.assertIn("trigger1", [tr['Name'] for tr in trgs]) self.assertIn("trigger2", [tr['Name'] for tr in trgs]) - self.mistral('cron-trigger-delete', params='trigger1') - self.mistral('cron-trigger-delete', params='trigger2') - - self.cron_triggers.remove('trigger1') - self.cron_triggers.remove('trigger2') - def test_cron_trigger_get(self): - trigger = self.mistral_command( - 'cron-trigger-create', - params='trigger "5 * * * *" %s {}' % self.wf_name) - self.cron_triggers.append('trigger') + trigger = self.cron_trigger_create( + 'trigger', "5 * * * *", self.wf_name, '{}') self.assertTableStruct(trigger, ['Field', 'Value']) tr_name = self.get_value_of_field(trigger, 'Name') - fetched_tr = self.mistral_command( + fetched_tr = self.mistral_admin( 'cron-trigger-get', params='trigger') self.assertTableStruct(trigger, ['Field', 'Value']) @@ -469,27 +335,17 @@ class CronTriggerCLITests(ClientTestBase): self.assertEqual(self.wf_name, wf_name) self.assertIsNotNone(created_at) - self.mistral('cron-trigger-delete', params='{0}'.format(tr_name)) - self.cron_triggers.remove('trigger') - -class ActionCLITests(ClientTestBase): +class ActionCLITests(base_v2.MistralClientTestBase): """Test suite checks commands to work with actions.""" @classmethod def setUpClass(cls): super(ActionCLITests, cls).setUpClass() - def tearDown(self): - for act in self.actions: - self.mistral('action-delete', params=act) - - super(ActionCLITests, self).tearDown() - def test_action_create_delete(self): - init_acts = self.mistral_command( - 'action-create', params='{0}'.format(self.act_def)) - self.actions.extend([action['Name'] for action in init_acts]) + init_acts = self.mistral_admin( + 'action-create', params=self.act_def) self.assertTableStruct(init_acts, ['Name', 'Is system', 'Input', 'Description', 'Tags', 'Created at', 'Updated at']) @@ -511,31 +367,26 @@ class ActionCLITests(ClientTestBase): self.assertEqual(action_1['Input'], 'name') self.assertEqual(action_2['Input'], '') - acts = self.mistral_command('action-list') + acts = self.mistral_admin('action-list') self.assertIn(action_1['Name'], [action['Name'] for action in acts]) self.assertIn(action_2['Name'], [action['Name'] for action in acts]) - self.mistral_command( + self.mistral_admin( 'action-delete', params='{0}'.format(action_1['Name'])) - self.mistral_command( + self.mistral_admin( 'action-delete', params='{0}'.format(action_2['Name'])) - acts = self.mistral_command('action-list') + acts = self.mistral_admin('action-list') self.assertNotIn(action_1['Name'], [action['Name'] for action in acts]) self.assertNotIn(action_2['Name'], [action['Name'] for action in acts]) - for a in [action['Name'] for action in init_acts]: - self.actions.remove(a) def test_action_update(self): - acts = self.mistral_command( - 'action-create', params='{0}'.format(self.act_def)) - - self.actions.extend([action['Name'] for action in acts]) + acts = self.action_create(self.act_def) created_action = self.get_item_info( get_from=acts, get_by='Name', value='greeting') - acts = self.mistral_command( + acts = self.mistral_admin( 'action-update', params='{0}'.format(self.act_def)) updated_action = self.get_item_info( @@ -548,178 +399,154 @@ class ActionCLITests(ClientTestBase): updated_action['Updated at']) def test_action_get_definition(self): - acts = self.mistral_command( - 'action-create', params='{0}'.format(self.act_def)) + self.action_create(self.act_def) - self.actions.extend([action['Name'] for action in acts]) - - definition = self.mistral_command( + definition = self.mistral_admin( 'action-get-definition', params='greeting') self.assertNotIn('404 Not Found', definition) -class NegativeCLITests(ClientTestBase): +class NegativeCLITests(base_v2.MistralClientTestBase): """This class contains negative tests.""" - def tearDown(self): - for wb in self.workbooks: - self.mistral('workbook-delete', params=wb) - - for cron_tr in self.cron_triggers: - self.mistral('cron-trigger-delete', params=cron_tr) - - for wf in self.workflows: - self.mistral('workflow-delete', params=wf) - - for act in self.actions: - self.mistral('action-delete', params=act) - - super(NegativeCLITests, self).tearDown() - def test_wb_list_extra_param(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workbook-list', params='param') + self.mistral_admin, + 'workbook-list', params='param') def test_wb_get_unexist_wb(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workbook-get', params='wb') + self.mistral_admin, + 'workbook-get', params='wb') def test_wb_get_without_param(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workbook-get') + self.mistral_admin, 'workbook-get') def test_wb_create_same_name(self): - wb = self.mistral_command( - 'workbook-create', params='{0}'.format(self.wb_def)) - wb_name = self.get_value_of_field(wb, "Name") - self.workbooks.append(wb_name) - self.workflows.append('wb.wf1') + self.workbook_create(self.wb_def) self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workbook-create', - params='{0}'.format(self.wb_def)) + self.workbook_create, + self.wb_def) def test_wb_create_with_wrong_path_to_definition(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, - 'workbook-create', params='wb') + self.mistral_admin, + 'workbook_create', 'wb') def test_wb_delete_unexist_wb(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workbook-delete', params='wb') + self.mistral_admin, + 'workbook-delete', params='wb') def test_wb_update_unexist_wb(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workbook-update', params='wb') + self.mistral_admin, + 'workbook-update', params='wb') def test_wb_get_definition_unexist_wb(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, + self.mistral_admin, 'workbook-get-definition', params='wb') def test_wf_list_extra_param(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workflow-list', params='param') + self.mistral_admin, + 'workflow-list', params='param') def test_wf_get_unexist_wf(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workflow-get', params='wb') + self.mistral_admin, + 'workflow-get', params='wb') def test_wf_get_without_param(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workflow-get') + self.mistral_admin, 'workflow-get') def test_wf_create_without_definition(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, + self.mistral_admin, 'workflow-create', params='') def test_wf_create_with_wrong_path_to_definition(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, + self.mistral_admin, 'workflow-create', params='wf') def test_wf_delete_unexist_wf(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workflow-delete', params='wf') + self.mistral_admin, + 'workflow-delete', params='wf') def test_wf_update_unexist_wf(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'workflow-update', params='wf') + self.mistral_admin, + 'workflow-update', params='wf') def test_wf_get_definition_unexist_wf(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, + self.mistral_admin, 'workflow-get-definition', params='wf') def test_ex_list_extra_param(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'execution-list', params='param') + self.mistral_admin, + 'execution-list', params='param') def test_ex_create_unexist_wf(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'execution-create', params='wf') + self.mistral_admin, + 'execution-create', params='wf') def test_ex_create_unexist_task(self): - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) - self.workflows.append(wf[0]['Name']) + wf = self.workflow_create(self.wf_def) self.assertRaises(exceptions.CommandFailed, - self.mistral, 'execution-create', + self.mistral_admin, 'execution-create', params='%s param {}' % wf[0]['Name']) def test_ex_create_with_invalid_input(self): - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) - self.workflows.append(wf[0]['Name']) + wf = self.workflow_create(self.wf_def) self.assertRaises(exceptions.CommandFailed, - self.mistral, 'execution-create', + self.mistral_admin, 'execution-create', params="%s input" % wf[0]['Name']) def test_ex_get_nonexist_execution(self): - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) - self.workflows.append(wf[0]['Name']) + wf = self.workflow_create(self.wf_def) self.assertRaises(exceptions.CommandFailed, - self.mistral, 'execution-get', + self.mistral_admin, 'execution-get', params='%s id' % wf[0]['Name']) def test_tr_create_without_pattern(self): - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) - self.workflows.append(wf[0]['Name']) + wf = self.workflow_create(self.wf_def) self.assertRaises(exceptions.CommandFailed, - self.mistral, 'cron-trigger-create', + self.mistral_admin, 'cron-trigger-create', params='tr "" %s {}' % wf[0]['Name']) def test_tr_create_invalid_pattern(self): - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) - self.workflows.append(wf[0]['Name']) + wf = self.workflow_create(self.wf_def) self.assertRaises(exceptions.CommandFailed, - self.mistral, 'cron-trigger-create', + self.mistral_admin, 'cron-trigger-create', params='tr "q" %s {}' % wf[0]['Name']) def test_tr_create_invalid_pattern_value_out_of_range(self): - wf = self.mistral_command( - 'workflow-create', params='{0}'.format(self.wf_def)) - self.workflows.append(wf[0]['Name']) + wf = self.workflow_create(self.wf_def) self.assertRaises(exceptions.CommandFailed, - self.mistral, 'cron-trigger-create', + self.mistral_admin, 'cron-trigger-create', params='tr "88 * * * *" %s {}' % wf[0]['Name']) def test_tr_create_nonexistent_wf(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'cron-trigger-create', + self.mistral_admin, 'cron-trigger-create', params='tr "* * * * *" wb.wf1 {}') def test_tr_delete_nonexistant_tr(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, + self.mistral_admin, 'cron-trigger-delete', params='tr') def test_tr_get_nonexistant_tr(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, + self.mistral_admin, 'cron-trigger-get', params='tr') def test_action_get_nonexistent(self): @@ -728,34 +555,32 @@ class NegativeCLITests(ClientTestBase): 'action-get', params='nonexist') def test_action_double_creation(self): - acts = self.mistral_command( - 'action-create', params='{0}'.format(self.act_def)) - self.actions.extend([action['Name'] for action in acts]) + self.action_create(self.act_def) self.assertRaises(exceptions.CommandFailed, - self.mistral, 'action-create', + self.mistral_admin, 'action-create', params='{0}'.format(self.act_def)) def test_action_create_without_def(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'action-create', + self.mistral_admin, 'action-create', params='') def test_action_create_invalid_def(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'action-create', + self.mistral_admin, 'action-create', params='{0}'.format(self.wb_def)) def test_action_delete_nonexistent_act(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'action-delete', + self.mistral_admin, 'action-delete', params='nonexist') def test_action_delete_standard_action(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'action-delete', + self.mistral_admin, 'action-delete', params='heat.events_get') def test_action_get_definition_nonexistent_action(self): self.assertRaises(exceptions.CommandFailed, - self.mistral, 'action-get-definition', + self.mistral_admin, 'action-get-definition', params='nonexist')