Refactor API tests for v2
- Separated v1 and v2 api tests for workbooks and executions; - Added more tests scenarios; - Optimize methods realization for v2 tests. Change-Id: Ic24383bc7e6c059088e98eeeeab28ae7bda2de6a Closes-Bug: #1384564
This commit is contained in:
parent
b1f624390e
commit
407eeb5551
@ -31,7 +31,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
|
||||
def test_reverse_flow(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/task_with_diamond_dependencies.yaml')
|
||||
'data_flow/task_with_diamond_dependencies.yaml')
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
@ -63,7 +63,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
|
||||
def test_task_with_two_dependencies(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/task_with_two_dependencies.yaml')
|
||||
'data_flow/task_with_two_dependencies.yaml')
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
@ -88,7 +88,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
|
||||
def test_direct_flow_tasks_on_success(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/three_subsequent_tasks.yaml')
|
||||
'data_flow/three_subsequent_tasks.yaml')
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
@ -113,7 +113,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
|
||||
def test_two_dependent_tasks(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/two_dependent_tasks.yaml')
|
||||
'data_flow/two_dependent_tasks.yaml')
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
@ -133,7 +133,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
|
||||
def test_two_subsequent_tasks(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/two_subsequent_tasks.yaml')
|
||||
'data_flow/two_subsequent_tasks.yaml')
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
@ -154,7 +154,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
|
||||
def test_mixed_workflow(self):
|
||||
text = base.get_resource(
|
||||
'resources/test_mixed_flow.yaml')
|
||||
'test_mixed_flow.yaml')
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
@ -182,7 +182,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
|
||||
def test_direct_workflow_all_keywords(self):
|
||||
text = base.get_resource(
|
||||
'resources/test_direct_flow_all_keywords.yaml')
|
||||
'test_direct_flow_all_keywords.yaml')
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
|
@ -15,11 +15,10 @@
|
||||
from tempest import exceptions
|
||||
from tempest import test
|
||||
|
||||
from mistral.tests.functional.api.v1 import test_mistral_basic
|
||||
from mistral.tests.functional import base
|
||||
|
||||
|
||||
class WorkbookTestsV2(test_mistral_basic.WorkbookTestsV1):
|
||||
class WorkbookTestsV2(base.TestCase):
|
||||
|
||||
_version = 2
|
||||
|
||||
@ -30,6 +29,93 @@ class WorkbookTestsV2(test_mistral_basic.WorkbookTestsV1):
|
||||
|
||||
super(WorkbookTestsV2, self).tearDown()
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_list_workbooks(self):
|
||||
resp, body = self.client.get_list_obj('workbooks')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual([], body['workbooks'])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_create_and_delete_workbook(self):
|
||||
resp, body = self.client.create_workbook('wb_v2.yaml')
|
||||
name = body['name']
|
||||
self.assertEqual(201, resp.status)
|
||||
|
||||
resp, body = self.client.get_list_obj('workbooks')
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(name, body['workbooks'][0]['name'])
|
||||
|
||||
self.client.delete_obj('workbooks', name)
|
||||
self.client.workbooks.remove(name)
|
||||
|
||||
_, body = self.client.get_list_obj('workbooks')
|
||||
self.assertEqual([], body['workbooks'])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_get_workbook(self):
|
||||
_, body = self.client.create_workbook('wb_v2.yaml')
|
||||
name = body['name']
|
||||
|
||||
resp, body = self.client.get_object('workbooks', name)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(name, body['name'])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_update_workbook(self):
|
||||
_, body = self.client.create_workbook('wb_v2.yaml')
|
||||
name = body['name']
|
||||
resp, body = self.client.update_request('workbooks', 'wb_v2.yaml')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(name, body['name'])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_get_workbook_definition(self):
|
||||
_, body = self.client.create_workbook('wb_v2.yaml')
|
||||
name = body['name']
|
||||
resp, body = self.client.get_definition('workbooks', name)
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertIsNotNone(body)
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_nonexistent_workbook_definition(self):
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.client.get_definition,
|
||||
'workbooks', 'nonexist')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_nonexistent_workbook(self):
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_object,
|
||||
'workbooks', 'nonexist')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_double_create_workbook(self):
|
||||
_, body = self.client.create_workbook('wb_v2.yaml')
|
||||
name = body['name']
|
||||
self.assertRaises(exceptions.Conflict,
|
||||
self.client.create_workbook,
|
||||
'wb_v2.yaml')
|
||||
|
||||
self.client.delete_obj('workbooks', name)
|
||||
self.client.workbooks.remove(name)
|
||||
_, body = self.client.get_list_obj('workbooks')
|
||||
|
||||
self.assertEqual([], body['workbooks'])
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_create_wb_with_invalid_def(self):
|
||||
self.assertRaises(exceptions.ServerFault,
|
||||
self.client.create_workbook,
|
||||
'wb_v1.yaml')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_update_wb_with_invalid_def(self):
|
||||
self.assertRaises(exceptions.ServerFault,
|
||||
self.client.update_request,
|
||||
'workbooks', 'wb_v1.yaml')
|
||||
|
||||
|
||||
class WorkflowTestsV2(base.TestCase):
|
||||
|
||||
@ -45,65 +131,121 @@ class WorkflowTestsV2(base.TestCase):
|
||||
@test.attr(type='smoke')
|
||||
def test_get_list_workflows(self):
|
||||
resp, body = self.client.get_list_obj('workflows')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual([], body['workflows'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
names = [wf['name'] for wf in body['workflows']]
|
||||
|
||||
self.assertIn('std.create_instance', names)
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_create_and_delete_workflow(self):
|
||||
resp, body = self.client.create_workflow()
|
||||
resp, body = self.client.create_workflow('wf_v2.yaml')
|
||||
name = body['workflows'][0]['name']
|
||||
|
||||
self.assertEqual(201, resp.status)
|
||||
self.assertEqual('wf', body['workflows'][0]['name'])
|
||||
|
||||
resp, body = self.client.get_list_obj('workflows')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
names = [wf['name'] for wf in body['workflows']]
|
||||
self.assertIn('wf', names)
|
||||
|
||||
self.client.delete_obj('workflows', 'wf')
|
||||
self.client.workflows.remove('wf')
|
||||
names = [wf['name'] for wf in body['workflows']]
|
||||
self.assertIn(name, names)
|
||||
|
||||
self.client.delete_obj('workflows', name)
|
||||
self.client.workflows.remove(name)
|
||||
|
||||
_, body = self.client.get_list_obj('workflows')
|
||||
|
||||
names = [wf['name'] for wf in body['workflows']]
|
||||
self.assertNotIn('wf', names)
|
||||
self.assertNotIn(name, names)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
@test.attr(type='sanity')
|
||||
def test_get_workflow(self):
|
||||
self.client.create_workflow()
|
||||
resp, body = self.client.get_object('workflows', 'wf')
|
||||
_, body = self.client.create_workflow('wf_v2.yaml')
|
||||
name = body['workflows'][0]['name']
|
||||
|
||||
resp, body = self.client.get_object('workflows', name)
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('wf', body['name'])
|
||||
self.assertEqual(name, body['name'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
@test.attr(type='sanity')
|
||||
def test_update_workflow(self):
|
||||
self.client.create_workflow()
|
||||
resp, body = self.client.update_workflow()
|
||||
_, body = self.client.create_workflow('wf_v2.yaml')
|
||||
name = body['workflows'][0]['name']
|
||||
|
||||
resp, body = self.client.update_request('workflows', 'wf_v2.yaml')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('wf', body['workflows'][0]['name'])
|
||||
self.assertEqual(name, body['workflows'][0]['name'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
@test.attr(type='sanity')
|
||||
def test_get_workflow_definition(self):
|
||||
self.client.create_workflow()
|
||||
resp, body = self.client.get_workflow_definition('wf')
|
||||
_, body = self.client.create_workflow('wf_v2.yaml')
|
||||
name = body['workflows'][0]['name']
|
||||
|
||||
resp, body = self.client.get_definition('workflows', name)
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertIsNotNone(body)
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_get_workflow_uploaded_in_wb(self):
|
||||
_, body = self.client.create_workbook('wb_v2.yaml')
|
||||
wb_name = body['name']
|
||||
|
||||
class ExecutionTestsV2(test_mistral_basic.ExecutionTestsV1):
|
||||
_, body = self.client.get_list_obj('workflows')
|
||||
wf_names = [wf['name'] for wf in body['workflows']
|
||||
if wf['name'].startswith(wb_name)]
|
||||
|
||||
self.assertNotEmpty(wf_names)
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_nonexistent_workflow_definition(self):
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.client.get_definition,
|
||||
'workflows', 'nonexist')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_nonexistent_workflow(self):
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_object,
|
||||
'workflows', 'nonexist')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_double_create_workflows(self):
|
||||
_, body = self.client.create_workflow('wf_v2.yaml')
|
||||
self.assertRaises(exceptions.Conflict,
|
||||
self.client.create_workflow,
|
||||
'wf_v2.yaml')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_create_wf_with_invalid_def(self):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.client.create_workflow,
|
||||
'wb_v1.yaml')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_update_wf_with_invalid_def(self):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.client.update_request,
|
||||
'workflows', 'wb_v1.yaml')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_delete_nonexistent_wf(self):
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.client.delete_obj,
|
||||
'workflows', 'nonexist')
|
||||
|
||||
|
||||
class ExecutionTestsV2(base.TestCase):
|
||||
|
||||
_version = 2
|
||||
|
||||
def setUp(self):
|
||||
super(ExecutionTestsV2, self).setUp()
|
||||
|
||||
self.entity_type = 'workflow_name'
|
||||
self.entity_name = 'test.test'
|
||||
_, body = self.client.create_workflow('wf_v2.yaml')
|
||||
self.direct_wf = body['workflows'][0]['name']
|
||||
self.reverse_wf = body['workflows'][1]
|
||||
|
||||
def tearDown(self):
|
||||
for wf in self.client.workflows:
|
||||
@ -112,6 +254,106 @@ class ExecutionTestsV2(test_mistral_basic.ExecutionTestsV1):
|
||||
|
||||
super(ExecutionTestsV2, self).tearDown()
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_list_executions(self):
|
||||
resp, _ = self.client.get_list_obj('executions')
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_create_execution_for_direct_wf(self):
|
||||
resp, body = self.client.create_execution(self.direct_wf)
|
||||
exec_id = body['id']
|
||||
self.assertEqual(201, resp.status)
|
||||
self.assertEqual(self.direct_wf, body['workflow_name'])
|
||||
self.assertEqual('RUNNING', body['state'])
|
||||
|
||||
resp, body = self.client.get_list_obj('executions')
|
||||
self.assertIn(exec_id,
|
||||
[ex_id['id'] for ex_id in body['executions']])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_create_execution_for_reverse_wf(self):
|
||||
resp, body = self.client.create_execution(
|
||||
self.reverse_wf['name'],
|
||||
{self.reverse_wf['input']: "Bye"},
|
||||
{"task_name": "goodbye"})
|
||||
|
||||
exec_id = body['id']
|
||||
self.assertEqual(201, resp.status)
|
||||
self.assertEqual(self.reverse_wf['name'], body['workflow_name'])
|
||||
self.assertEqual('RUNNING', body['state'])
|
||||
|
||||
resp, body = self.client.get_list_obj('executions')
|
||||
self.assertIn(exec_id,
|
||||
[ex_id['id'] for ex_id in body['executions']])
|
||||
|
||||
resp, body = self.client.get_object('executions', exec_id)
|
||||
while body['state'] != 'SUCCESS':
|
||||
resp, body = self.client.get_object('executions', exec_id)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('SUCCESS', body['state'])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_get_execution(self):
|
||||
_, execution = self.client.create_execution(self.direct_wf)
|
||||
|
||||
resp, body = self.client.get_object('executions', execution['id'])
|
||||
|
||||
del execution['state']
|
||||
del body['state']
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(execution['id'], body['id'])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_update_execution(self):
|
||||
_, execution = self.client.create_execution(self.direct_wf)
|
||||
resp, body = self.client.update_execution(
|
||||
execution['id'], '{"state": "PAUSED"}')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('PAUSED', body['state'])
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_nonexistent_execution(self):
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_object,
|
||||
'executions', '1a2b3c')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_update_nonexistent_execution(self):
|
||||
put_body = '{"state": "STOPPED"}'
|
||||
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.client.update_execution,
|
||||
'1a2b3c', put_body)
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_delete_nonexistent_execution(self):
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.client.delete_obj,
|
||||
'executions', 'nonexist')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_create_ex_for_nonexistent_wf(self):
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.client.create_execution,
|
||||
'nonexist')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_create_execution_for_reverse_wf_invalid_start_task(self):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.client.create_execution,
|
||||
self.reverse_wf['name'],
|
||||
{self.reverse_wf['input']: "Bye"},
|
||||
{"task_name": "nonexist"})
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_create_execution_forgot_input_params(self):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.client.create_execution,
|
||||
self.reverse_wf['name'],
|
||||
params={"task_name": "nonexist"})
|
||||
|
||||
|
||||
class CronTriggerTestsV2(base.TestCase):
|
||||
|
||||
@ -120,7 +362,7 @@ class CronTriggerTestsV2(base.TestCase):
|
||||
def setUp(self):
|
||||
super(CronTriggerTestsV2, self).setUp()
|
||||
|
||||
_, body = self.client.create_workflow()
|
||||
_, body = self.client.create_workflow('wf_v2.yaml')
|
||||
self.wf_name = body['workflows'][0]['name']
|
||||
|
||||
def tearDown(self):
|
||||
@ -272,91 +514,68 @@ class ActionTestsV2(base.TestCase):
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_create_and_delete_few_actions(self):
|
||||
text = base.get_resource('resources/action_v2.yaml')
|
||||
action1_name = 'greeting'
|
||||
action2_name = 'farewell'
|
||||
|
||||
resp, body = self.client.create_action(text)
|
||||
resp, body = self.client.create_action('action_v2.yaml')
|
||||
self.assertEqual(201, resp.status)
|
||||
|
||||
actions = [action['name'] for action in body['actions']]
|
||||
self.assertIn(action1_name, actions)
|
||||
self.assertIn(action2_name, actions)
|
||||
created_acts = [action['name'] for action in body['actions']]
|
||||
|
||||
resp, body = self.client.get_list_obj('actions')
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
actions = [action['name'] for action in body['actions']]
|
||||
self.assertIn(action1_name, actions)
|
||||
self.assertIn(action2_name, actions)
|
||||
|
||||
self.client.delete_obj('actions', action1_name)
|
||||
self.client.delete_obj('actions', action2_name)
|
||||
for act in created_acts:
|
||||
self.assertIn(act, actions)
|
||||
self.client.delete_obj('actions', act)
|
||||
|
||||
_, body = self.client.get_list_obj('actions')
|
||||
|
||||
actions = [action['name'] for action in body['actions']]
|
||||
self.assertNotIn(action1_name, actions)
|
||||
self.assertNotIn(action2_name, actions)
|
||||
self.client.actions.remove(action1_name)
|
||||
self.client.actions.remove(action2_name)
|
||||
|
||||
for act in created_acts:
|
||||
self.assertNotIn(act, actions)
|
||||
self.client.actions.remove(act)
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_get_action(self):
|
||||
text = base.get_resource('resources/action_v2.yaml')
|
||||
action1_name = 'greeting'
|
||||
self.client.create_action(text)
|
||||
|
||||
resp, body = self.client.get_object('actions', action1_name)
|
||||
_, body = self.client.create_action('action_v2.yaml')
|
||||
action_name = body['actions'][0]['name']
|
||||
resp, body = self.client.get_object('actions', action_name)
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(action1_name, body['name'])
|
||||
self.assertEqual(action_name, body['name'])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_update_action(self):
|
||||
text = base.get_resource('resources/action_v2.yaml')
|
||||
act1_name = 'greeting'
|
||||
act2_name = 'farewell'
|
||||
_, body = self.client.create_action('action_v2.yaml')
|
||||
action = body['actions'][0]['name']
|
||||
|
||||
resp, body = self.client.create_action(text)
|
||||
act1_created_at = self.get_field_value(
|
||||
body=body, act_name=act1_name, field='created_at')
|
||||
act2_created_at = self.get_field_value(
|
||||
body=body, act_name=act2_name, field='created_at')
|
||||
act_created_at = self.get_field_value(
|
||||
body=body, act_name=action, field='created_at')
|
||||
|
||||
self.assertNotIn('updated at', body['actions'])
|
||||
|
||||
resp, body = self.client.update_action(text)
|
||||
resp, body = self.client.update_request('actions', 'action_v2.yaml')
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
actions = [action['name'] for action in body['actions']]
|
||||
self.assertIn(act1_name, actions)
|
||||
self.assertIn(act2_name, actions)
|
||||
actions = [act['name'] for act in body['actions']]
|
||||
self.assertIn(action, actions)
|
||||
|
||||
updated1_created_at = self.get_field_value(
|
||||
body=body, act_name=act1_name, field='created_at')
|
||||
updated2_created_at = self.get_field_value(
|
||||
body=body, act_name=act2_name, field='created_at')
|
||||
updated_act_created_at = self.get_field_value(
|
||||
body=body, act_name=action, field='created_at')
|
||||
|
||||
self.assertEqual(act1_created_at.split(".")[0], updated1_created_at)
|
||||
self.assertEqual(act2_created_at.split(".")[0], updated2_created_at)
|
||||
self.assertEqual(act_created_at.split(".")[0], updated_act_created_at)
|
||||
self.assertTrue(all(['updated_at' in item
|
||||
for item in body['actions']]))
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_get_action_definition(self):
|
||||
text = base.get_resource('resources/action_v2.yaml')
|
||||
action1_name = 'greeting'
|
||||
action2_name = 'farewell'
|
||||
self.client.create_action(text)
|
||||
_, body = self.client.create_action('action_v2.yaml')
|
||||
act_name = body['actions'][0]['name']
|
||||
|
||||
resp, body = self.client.get_action_definition(action1_name)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertIsNotNone(body)
|
||||
|
||||
resp, body = self.client.get_action_definition(action2_name)
|
||||
resp, body = self.client.get_definition('actions', act_name)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertIsNotNone(body)
|
||||
self.assertIn(act_name, body)
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_nonexistent_action(self):
|
||||
@ -366,22 +585,22 @@ class ActionTestsV2(base.TestCase):
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_double_creation(self):
|
||||
text = base.get_resource('resources/action_v2.yaml')
|
||||
self.client.create_action(text)
|
||||
self.client.create_action('action_v2.yaml')
|
||||
|
||||
self.assertRaises(exceptions.Conflict,
|
||||
self.client.create_action,
|
||||
text)
|
||||
'action_v2.yaml')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_create_action_invalid_def(self):
|
||||
self.assertRaises(exceptions.ServerFault,
|
||||
self.client.create_action, "")
|
||||
self.client.create_action, 'wb_v2.yaml')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_update_action_invalid_def(self):
|
||||
self.assertRaises(exceptions.ServerFault,
|
||||
self.client.update_action, "")
|
||||
self.client.update_request,
|
||||
'actions', 'wb_v2.yaml')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_delete_nonexistent_action(self):
|
||||
@ -394,3 +613,36 @@ class ActionTestsV2(base.TestCase):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.client.delete_obj,
|
||||
'actions', 'nova.servers_create')
|
||||
|
||||
|
||||
class TasksTestsV2(base.TestCase):
|
||||
|
||||
_version = 2
|
||||
|
||||
def setUp(self):
|
||||
super(TasksTestsV2, self).setUp()
|
||||
|
||||
_, body = self.client.create_workflow('wf_v2.yaml')
|
||||
self.direct_wf = body['workflows'][0]['name']
|
||||
_, execution = self.client.create_execution(self.direct_wf)
|
||||
|
||||
def tearDown(self):
|
||||
for wf in self.client.workflows:
|
||||
self.client.delete_obj('workflows', wf)
|
||||
self.client.workflows = []
|
||||
|
||||
super(TasksTestsV2, self).tearDown()
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_tasks_list(self):
|
||||
resp, body = self.client.get_list_obj('tasks')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertNotEmpty(body['tasks'])
|
||||
|
||||
@test.attr(type='sanity')
|
||||
def test_get_task(self):
|
||||
resp, body = self.client.get_list_obj('tasks')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(self.direct_wf, body['tasks'][-1]['wf_name'])
|
||||
|
@ -1,5 +1,4 @@
|
||||
# Copyright 2013 Mirantis, Inc.
|
||||
# All Rights Reserved.
|
||||
# Copyright 2013 Mirantis, Inc. All Rights Reserved.
|
||||
#
|
||||
# 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
|
||||
@ -32,23 +31,23 @@ def get_resource(path):
|
||||
main_package = 'mistral/tests'
|
||||
dir_path = __file__[0:__file__.find(main_package) + len(main_package) + 1]
|
||||
|
||||
return open(dir_path + path).read()
|
||||
return open(dir_path + 'resources/' + path).read()
|
||||
|
||||
|
||||
def find_items(items, **props):
|
||||
def _matches(item, **props):
|
||||
for prop_name, prop_val in props.iteritems():
|
||||
if item[prop_name] != prop_val:
|
||||
return False
|
||||
def _matches(item, **props):
|
||||
for prop_name, prop_val in props.iteritems():
|
||||
if item[prop_name] != prop_val:
|
||||
return False
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
filtered = filter(lambda item: _matches(item, **props), items)
|
||||
filtered = filter(lambda item: _matches(item, **props), items)
|
||||
|
||||
if len(filtered) == 1:
|
||||
return filtered[0]
|
||||
if len(filtered) == 1:
|
||||
return filtered[0]
|
||||
|
||||
return filtered
|
||||
return filtered
|
||||
|
||||
|
||||
class MistralClientBase(rest_client.RestClient):
|
||||
@ -113,7 +112,7 @@ class MistralClientV1(MistralClientBase):
|
||||
def upload_workbook_definition(self, name):
|
||||
headers = {'Content-Type': 'text/plain',
|
||||
'X-Auth-Token': self.auth_provider.get_token()}
|
||||
text = get_resource('resources/wb_v1.yaml')
|
||||
text = get_resource('wb_v1.yaml')
|
||||
|
||||
return self.put('workbooks/{name}/definition'.format(name=name),
|
||||
text, headers)
|
||||
@ -215,76 +214,59 @@ class MistralClientV2(MistralClientBase):
|
||||
|
||||
_version = 2
|
||||
|
||||
def create_workbook(self, name):
|
||||
text = get_resource('resources/wb_v2.yaml')
|
||||
post_body = {"definition": "%s" % text}
|
||||
resp, body = self.post('workbooks', json.dumps(post_body))
|
||||
def post_request(self, url, file_name):
|
||||
text = get_resource(file_name)
|
||||
headers = {"headers": "Content-Type:text/plain"}
|
||||
return self.post(url, text, headers=headers)
|
||||
|
||||
self.workbooks.append(json.loads(body)['name'])
|
||||
|
||||
_, wfs = self.get('workflows')
|
||||
self.workflows.append(json.loads(wfs)['workflows'][0]['name'])
|
||||
def update_request(self, url, file_name):
|
||||
text = get_resource(file_name)
|
||||
headers = {"headers": "Content-Type:text/plain"}
|
||||
resp, body = self.put(url, text, headers=headers)
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def update_workbook(self, name):
|
||||
text = get_resource('resources/wb_v2.yaml')
|
||||
post_body = {"definition": "%s" % text}
|
||||
resp, body = self.put('workbooks',
|
||||
json.dumps(post_body))
|
||||
def get_definition(self, item, name):
|
||||
resp, body = self.get("%s/%s" % (item, name))
|
||||
|
||||
return resp, json.loads(body)['definition']
|
||||
|
||||
def create_workbook(self, yaml_file):
|
||||
resp, body = self.post_request('workbooks', yaml_file)
|
||||
|
||||
wb_name = json.loads(body)['name']
|
||||
self.workbooks.append(wb_name)
|
||||
|
||||
_, wfs = self.get_list_obj('workflows')
|
||||
for wf in wfs['workflows']:
|
||||
if wf['name'].startswith(wb_name):
|
||||
self.workflows.append(wf['name'])
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def get_workbook_definition(self, name):
|
||||
return self.get('workbooks/{name}'.format(name=name))
|
||||
def create_workflow(self, yaml_file):
|
||||
resp, body = self.post_request('workflows', yaml_file)
|
||||
|
||||
def upload_workbook_definition(self, name):
|
||||
text = get_resource('resources/wb_v2.yaml')
|
||||
post_body = {"definition": "%s" % text}
|
||||
resp, body = self.put('workbooks',
|
||||
json.dumps(post_body))
|
||||
for wf in json.loads(body)['workflows']:
|
||||
self.workflows.append(wf['name'])
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def create_workflow(self):
|
||||
text = get_resource('resources/wf_v2.yaml')
|
||||
post_body = {"definition": "%s" % text}
|
||||
resp, body = self.post('workflows',
|
||||
json.dumps(post_body))
|
||||
def create_execution(self, wf_name, wf_input=None, params=None):
|
||||
body = {"workflow_name": "%s" % wf_name}
|
||||
if wf_input:
|
||||
body.update({'input': json.dumps(wf_input)})
|
||||
if params:
|
||||
body.update({'params': json.dumps(params)})
|
||||
|
||||
self.workflows.append(json.loads(body)['workflows'][0]['name'])
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def update_workflow(self):
|
||||
text = get_resource('resources/wf_v2.yaml')
|
||||
post_body = {"definition": "%s" % text}
|
||||
resp, body = self.put('workflows',
|
||||
json.dumps(post_body))
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def get_workflow_definition(self, name):
|
||||
return self.get('workflows/{name}'.format(name=name))
|
||||
|
||||
def create_execution(self, wf_name, post_body=None):
|
||||
if post_body is None:
|
||||
body = '{"workflow_name": "%s"}' % wf_name
|
||||
else:
|
||||
body = post_body
|
||||
rest, body = self.post('executions', body)
|
||||
resp, body = self.post('executions', json.dumps(body))
|
||||
|
||||
self.executions.append(json.loads(body)['id'])
|
||||
|
||||
return rest, json.loads(body)
|
||||
return resp, json.loads(body)
|
||||
|
||||
def update_execution(self, execution_id, put_body):
|
||||
return self.put('executions/{execution}'.format(
|
||||
execution=execution_id), json.dumps(put_body))
|
||||
|
||||
def update_task(self, task_id, put_body):
|
||||
resp, body = self.put('tasks/{task}'.format(
|
||||
task=task_id), json.dumps(put_body))
|
||||
resp, body = self.put('executions/%s' % execution_id, put_body)
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
@ -303,27 +285,14 @@ class MistralClientV2(MistralClientBase):
|
||||
|
||||
return rest, json.loads(body)
|
||||
|
||||
def create_action(self, text):
|
||||
post_body = {"definition": "%s" % text}
|
||||
resp, body = self.post('actions',
|
||||
json.dumps(post_body))
|
||||
def create_action(self, yaml_file):
|
||||
resp, body = self.post_request('actions', yaml_file)
|
||||
|
||||
self.actions.extend(
|
||||
[action['name'] for action in json.loads(body)['actions']])
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def update_action(self, text):
|
||||
post_body = {"definition": "%s" % text}
|
||||
resp, body = self.put('actions',
|
||||
json.dumps(post_body))
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def get_action_definition(self, name):
|
||||
resp, body = self.get("actions/%s" % name)
|
||||
|
||||
return resp, json.loads(body)['definition']
|
||||
|
||||
|
||||
class AuthProv(auth.KeystoneV2AuthProvider):
|
||||
|
||||
|
@ -37,7 +37,7 @@ class OpenStackActionsTest(base.TestCaseAdvanced):
|
||||
@test.attr(type='openstack')
|
||||
def test_nova_actions(self):
|
||||
nova_wb = base.get_resource(
|
||||
'resources/openstack/nova_actions.yaml')
|
||||
'openstack/nova_actions.yaml')
|
||||
self.client.prepare_workbook(self.workbook_name, nova_wb)
|
||||
|
||||
context = {
|
||||
@ -66,7 +66,7 @@ class OpenStackActionsTest(base.TestCaseAdvanced):
|
||||
@test.attr(type='openstack')
|
||||
def test_keystone_actions(self):
|
||||
keystone_wb = base.get_resource(
|
||||
'resources/openstack/keystone_actions.yaml')
|
||||
'openstack/keystone_actions.yaml')
|
||||
self.client.prepare_workbook(self.workbook_name,
|
||||
keystone_wb)
|
||||
_, execution = self.client.create_execution_wait_success(
|
||||
@ -86,7 +86,7 @@ class OpenStackActionsTest(base.TestCaseAdvanced):
|
||||
@test.attr(type='openstack')
|
||||
def test_glance_actions(self):
|
||||
glance_wb = base.get_resource(
|
||||
'resources/openstack/glance_actions.yaml')
|
||||
'openstack/glance_actions.yaml')
|
||||
self.client.prepare_workbook(self.workbook_name,
|
||||
glance_wb)
|
||||
|
||||
|
@ -6,5 +6,21 @@ wf:
|
||||
tasks:
|
||||
hello:
|
||||
action: std.echo output="Hello"
|
||||
policies:
|
||||
wait-before: 1
|
||||
publish:
|
||||
result: $
|
||||
|
||||
wf1:
|
||||
type: reverse
|
||||
input:
|
||||
- farewell
|
||||
tasks:
|
||||
addressee:
|
||||
action: std.echo output="John"
|
||||
publish:
|
||||
name: $
|
||||
goodbye:
|
||||
action: std.echo output="{$.farewell}, {$.name}"
|
||||
requires: [addressee]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user