Add API integration tests for v2
- Added integration tests for API version 2 - Refactor base.py, separate methods for v1 and v2 - Created second endpoint /v2 in keystone in devstack installation Change-Id: Ibe23971b2335242ed72b837bfc1f861d0a74e395
This commit is contained in:
parent
38ddb508e1
commit
b5724cae4a
@ -81,9 +81,23 @@ function create_mistral_accounts {
|
||||
openstack endpoint create \
|
||||
$MISTRAL_SERVICE \
|
||||
--region RegionOne \
|
||||
--publicurl "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v1" \
|
||||
--adminurl "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v1" \
|
||||
--internalurl "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v1"
|
||||
|
||||
MISTRAL_SERVICE_V2=$(openstack service create \
|
||||
mistral \
|
||||
--type=workflowv2 \
|
||||
--description="Workflow Service v2" \
|
||||
| grep " id " | get_field 2)
|
||||
|
||||
openstack endpoint create \
|
||||
$MISTRAL_SERVICE_V2 \
|
||||
--region RegionOne \
|
||||
--publicurl "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v2" \
|
||||
--adminurl "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v2" \
|
||||
--internalurl "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v2"
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,9 @@ from tempest import test
|
||||
from mistral.tests.functional import base
|
||||
|
||||
|
||||
class SanityTests(base.TestCase):
|
||||
class WorkbooksTestsV1(base.TestCase):
|
||||
|
||||
_version = 1
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_list_obj(self):
|
||||
@ -35,22 +37,6 @@ class SanityTests(base.TestCase):
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual([], body['workbooks'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_workbook(self):
|
||||
self.client.create_workbook('test')
|
||||
resp, body = self.client.get_list_obj('workbooks/test')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('test', body['name'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_executions(self):
|
||||
self.client.create_workbook('test')
|
||||
resp, body = self.client.get_list_obj('workbooks/test/executions')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual([], body['executions'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_create_and_delete_workbook(self):
|
||||
resp, body = self.client.create_workbook('test')
|
||||
@ -63,15 +49,23 @@ class SanityTests(base.TestCase):
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('test', body['workbooks'][0]['name'])
|
||||
|
||||
self.client.delete_workbook('test')
|
||||
self.client.delete_obj('workbooks', 'test')
|
||||
_, body = self.client.get_list_obj('workbooks')
|
||||
|
||||
self.assertEqual([], body['workbooks'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_workbook(self):
|
||||
self.client.create_workbook('test')
|
||||
resp, body = self.client.get_list_obj('workbooks/test')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('test', body['name'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_update_workbook(self):
|
||||
self.client.create_workbook('test')
|
||||
resp, body = self.client.update_obj('workbooks', 'test')
|
||||
resp, body = self.client.update_workbook('test')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('testupdated', body['name'])
|
||||
@ -79,9 +73,7 @@ class SanityTests(base.TestCase):
|
||||
@test.attr(type='smoke')
|
||||
def test_get_workbook_definition(self):
|
||||
self.client.create_workbook('test')
|
||||
text = base.get_resource('resources/hello.yaml')
|
||||
self.client.upload_workbook_definition(
|
||||
'test', text)
|
||||
self.client.upload_workbook_definition('test')
|
||||
resp, body = self.client.get_workbook_definition('test')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
@ -90,13 +82,23 @@ class SanityTests(base.TestCase):
|
||||
@test.attr(type='smoke')
|
||||
def test_upload_workbook_definition(self):
|
||||
self.client.create_workbook('test1')
|
||||
text = base.get_resource('resources/hello.yaml')
|
||||
resp, body = self.client.upload_workbook_definition(
|
||||
'test1', text)
|
||||
'test1')
|
||||
|
||||
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_workbook_definition,
|
||||
'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_obj(self):
|
||||
self.client.create_workbook('test')
|
||||
@ -104,144 +106,75 @@ class SanityTests(base.TestCase):
|
||||
self.assertRaises(exceptions.Conflict, self.client.create_workbook,
|
||||
'test')
|
||||
|
||||
self.client.delete_workbook('test')
|
||||
self.client.delete_obj('workbooks', 'test')
|
||||
_, body = self.client.get_list_obj('workbooks')
|
||||
|
||||
self.assertEqual([], body['workbooks'])
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_nonexistent_workbook_definition(self):
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.client.get_workbook_definition,
|
||||
'fksn')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_executions_list_from_nonexistent_workbook(self):
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_list_obj,
|
||||
'workbooks/nonexistentworkbook/executions')
|
||||
class ExecutionsTestsV1(base.TestCase):
|
||||
|
||||
_version = 1
|
||||
|
||||
class AdvancedTests(base.TestCaseAdvanced):
|
||||
def setUp(self):
|
||||
super(AdvancedTests, self).setUp()
|
||||
super(ExecutionsTestsV1, self).setUp()
|
||||
|
||||
wb = base.get_resource('resources/hello.yaml')
|
||||
self.client.upload_workbook_definition('test', wb)
|
||||
self.client.create_workbook('test')
|
||||
self.client.upload_workbook_definition('test')
|
||||
self.entity_type = 'workbook_name'
|
||||
self.entity_name = 'test'
|
||||
|
||||
def tearDown(self):
|
||||
super(ExecutionsTestsV1, self).tearDown()
|
||||
|
||||
_, executions = self.client.get_list_obj('executions')
|
||||
for ex in executions['executions']:
|
||||
self.client.delete_obj('executions', '{0}'.format(ex['id']))
|
||||
|
||||
@test.attr(type='positive')
|
||||
def test_create_execution(self):
|
||||
resp, body = self.client.create_execution_wait_success(
|
||||
'test', '', 'hello')
|
||||
resp, body = self.client.create_execution(self.entity_name)
|
||||
|
||||
self.assertEqual(201, resp.status)
|
||||
self.assertEqual('test', body["workbook_name"])
|
||||
self.assertEqual(self.entity_name, body[self.entity_type])
|
||||
|
||||
@test.attr(type='positive')
|
||||
def test_get_execution(self):
|
||||
_, execution = self.client.create_execution_wait_success('test', '',
|
||||
'hello')
|
||||
_, execution = self.client.create_execution(self.entity_name)
|
||||
|
||||
resp, body = self.client.get_execution('test', execution['id'])
|
||||
resp, body = self.client.get_object('executions', execution['id'])
|
||||
|
||||
body = json.loads(body)
|
||||
del execution['state']
|
||||
del body['state']
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(execution, body)
|
||||
self.assertEqual(execution['id'], body['id'])
|
||||
|
||||
@test.attr(type='positive')
|
||||
def test_update_execution(self):
|
||||
_, execution = self.client.create_execution_wait_success('test', '',
|
||||
'hello')
|
||||
_, execution = self.client.create_execution(self.entity_name)
|
||||
|
||||
resp, body = self.client.update_execution(
|
||||
'test', execution['id'], '{}')
|
||||
execution['id'], '{}')
|
||||
|
||||
body = json.loads(body)
|
||||
del execution['state']
|
||||
del body['state']
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(execution, body)
|
||||
|
||||
@test.attr(type='positive')
|
||||
def test_get_tasks_list(self):
|
||||
_, execution = self.client.create_execution_wait_success('test', '',
|
||||
'hello')
|
||||
|
||||
resp, tasks = self.client.get_tasks_list('test', execution['id'])
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
for task in tasks:
|
||||
self.assertEqual(execution['id'], task['execution_id'])
|
||||
self.assertEqual('test', task['workbook_name'])
|
||||
|
||||
@test.attr(type='positive')
|
||||
def test_get_task(self):
|
||||
_, execution = self.client.create_execution_wait_success('test', '',
|
||||
'hello')
|
||||
|
||||
_, tasks = self.client.get_tasks_list('test', execution['id'])
|
||||
|
||||
resp, task = self.client.get_task('test', execution['id'],
|
||||
tasks[0]['id'])
|
||||
|
||||
del tasks[0]['state']
|
||||
del task['state']
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(tasks[0], task)
|
||||
self.assertEqual(execution['id'], body['id'])
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_create_execution_in_nonexistent_workbook(self):
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.client.create_execution_wait_success,
|
||||
'nonexistentworkbook', '', 'catchme')
|
||||
|
||||
def test_get_nonexistent_execution(self):
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_execution,
|
||||
'test', str(uuid.uuid4()))
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_object,
|
||||
'executions', str(uuid.uuid4()))
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_update_nonexistent_execution(self):
|
||||
id = str(uuid.uuid4())
|
||||
put_body = {
|
||||
"id": id,
|
||||
"state": "STOPPED"
|
||||
}
|
||||
|
||||
self.assertRaises(exceptions.NotFound, self.client.update_execution,
|
||||
'test', id, put_body)
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_tasks_list_of_nonexistent_execution(self):
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_tasks_list,
|
||||
'test', str(uuid.uuid4()))
|
||||
|
||||
|
||||
class AdvancedNegativeTestsWithExecutionCreate(base.TestCaseAdvanced):
|
||||
def setUp(self):
|
||||
super(AdvancedNegativeTestsWithExecutionCreate, self).setUp()
|
||||
|
||||
wb = base.get_resource('resources/hello.yaml')
|
||||
self.client.upload_workbook_definition('test', wb)
|
||||
_, self.execution = self.client.create_execution_wait_success(
|
||||
'test', '', 'hello')
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_get_nonexistent_task(self):
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_task,
|
||||
'test', self.execution['id'], str(uuid.uuid4()))
|
||||
|
||||
@test.attr(type='negative')
|
||||
def test_update_nonexistent_task(self):
|
||||
id = str(uuid.uuid4())
|
||||
put_body = {
|
||||
"id": id,
|
||||
"state": "ERROR"
|
||||
}
|
||||
|
||||
self.assertRaises(exceptions.NotFound, self.client.update_task,
|
||||
'test', self.execution['id'], str(uuid.uuid4()),
|
||||
put_body)
|
||||
id, put_body)
|
||||
|
@ -26,10 +26,13 @@ CONTEXT = {
|
||||
|
||||
|
||||
class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
|
||||
_version = 1
|
||||
|
||||
def test_reverse_flow(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/task_with_diamond_dependencies.yaml')
|
||||
self.client.upload_workbook_definition('test', text)
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
'test', CONTEXT, 'send_greeting')
|
||||
@ -61,7 +64,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
def test_task_with_two_dependencies(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/task_with_two_dependencies.yaml')
|
||||
self.client.upload_workbook_definition('test', text)
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
'test', CONTEXT, 'send_greeting')
|
||||
@ -86,7 +89,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
def test_direct_flow_tasks_on_success(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/three_subsequent_tasks.yaml')
|
||||
self.client.upload_workbook_definition('test', text)
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
'test', CONTEXT, 'build_full_name')
|
||||
@ -111,7 +114,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
def test_two_dependent_tasks(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/two_dependent_tasks.yaml')
|
||||
self.client.upload_workbook_definition('test', text)
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
'test', CONTEXT, 'build_greeting')
|
||||
@ -131,7 +134,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
def test_two_subsequent_tasks(self):
|
||||
text = base.get_resource(
|
||||
'resources/data_flow/two_subsequent_tasks.yaml')
|
||||
self.client.upload_workbook_definition('test', text)
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
'test', CONTEXT, 'build_full_name')
|
||||
@ -152,7 +155,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
def test_mixed_workflow(self):
|
||||
text = base.get_resource(
|
||||
'resources/test_mixed_flow.yaml')
|
||||
self.client.upload_workbook_definition('test', text)
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
'test', {}, 'task2')
|
||||
@ -180,7 +183,7 @@ class MistralWorkflowExecutionTests(base.TestCaseAdvanced):
|
||||
def test_direct_workflow_all_keywords(self):
|
||||
text = base.get_resource(
|
||||
'resources/test_direct_flow_all_keywords.yaml')
|
||||
self.client.upload_workbook_definition('test', text)
|
||||
self.client.prepare_workbook('test', text)
|
||||
|
||||
_, ex = self.client.create_execution_wait_success(
|
||||
'test', {}, 'task1')
|
||||
|
0
mistral/tests/functional/api/v2/__init__.py
Normal file
0
mistral/tests/functional/api/v2/__init__.py
Normal file
107
mistral/tests/functional/api/v2/test_mistral_basic_v2.py
Normal file
107
mistral/tests/functional/api/v2/test_mistral_basic_v2.py
Normal file
@ -0,0 +1,107 @@
|
||||
# Copyright 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 mistral.tests.functional.api.v1 import test_mistral_basic
|
||||
from mistral.tests.functional import base
|
||||
|
||||
|
||||
class WorkbooksTestsV2(test_mistral_basic.WorkbooksTestsV1):
|
||||
|
||||
_version = 2
|
||||
|
||||
|
||||
class WorkflowsTestsV2(base.TestCase):
|
||||
|
||||
_version = 2
|
||||
|
||||
def tearDown(self):
|
||||
|
||||
_, wfs = self.client.get_list_obj('workflows')
|
||||
for wf in wfs['workflows']:
|
||||
self.client.delete_obj('workflows', wf['name'])
|
||||
|
||||
super(WorkflowsTestsV2, self).tearDown()
|
||||
|
||||
@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')
|
||||
def test_create_and_delete_workflow(self):
|
||||
resp, body = self.client.create_workflow('wf')
|
||||
|
||||
self.assertEqual(201, resp.status)
|
||||
self.assertEqual('wf', body['name'])
|
||||
|
||||
resp, body = self.client.get_list_obj('workflows')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
names = [body['workflows'][i]['name']
|
||||
for i in range(len(body['workflows']))]
|
||||
self.assertIn('wf', names)
|
||||
|
||||
self.client.delete_obj('workflows', 'wf')
|
||||
_, body = self.client.get_list_obj('workflows')
|
||||
|
||||
names = [body['workflows'][i]['name']
|
||||
for i in range(len(body['workflows']))]
|
||||
self.assertNotIn('wf', names)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_workflow(self):
|
||||
self.client.create_workflow('wf')
|
||||
resp, body = self.client.get_object('workflows', 'wf')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('wf', body['name'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_update_workflow(self):
|
||||
self.client.create_workflow('wf')
|
||||
resp, body = self.client.update_workflow('wf')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('wfupdated', body['name'])
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_upload_workflow_definition(self):
|
||||
self.client.create_workflow('test_wf')
|
||||
resp, body = self.client.upload_workflow_definition('test_wf')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertIsNotNone(body)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
def test_get_workflow_definition(self):
|
||||
self.client.create_workflow('test')
|
||||
self.client.upload_workflow_definition('test')
|
||||
resp, body = self.client.get_workflow_definition('test')
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertIsNotNone(body)
|
||||
|
||||
|
||||
class ExecutionsTestsV2(test_mistral_basic.ExecutionsTestsV1):
|
||||
|
||||
_version = 2
|
||||
|
||||
def setUp(self):
|
||||
super(ExecutionsTestsV2, self).setUp()
|
||||
self.entity_type = 'workflow_name'
|
||||
self.entity_name = 'test.test'
|
@ -28,6 +28,7 @@ CONF = config.CONF
|
||||
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()
|
||||
|
||||
|
||||
@ -47,36 +48,47 @@ def find_items(items, **props):
|
||||
return filtered
|
||||
|
||||
|
||||
class MistralClient(rest_client.RestClient):
|
||||
class MistralClientBase(rest_client.RestClient):
|
||||
|
||||
_version = None
|
||||
|
||||
def __init__(self, auth_provider):
|
||||
super(MistralClient, self).__init__(auth_provider)
|
||||
super(MistralClientBase, self).__init__(auth_provider)
|
||||
|
||||
self.service = 'workflow'
|
||||
if self._version == 1:
|
||||
self.service = 'workflow'
|
||||
elif self._version == 2:
|
||||
self.service = 'workflowv2'
|
||||
else:
|
||||
msg = ("Invalid parameter 'version'. "
|
||||
"Use version=1 or version=2.")
|
||||
raise exceptions.UnprocessableEntity(msg)
|
||||
self.endpoint_url = 'publicURL'
|
||||
|
||||
def get_list_obj(self, name):
|
||||
resp, body = self.get(name)
|
||||
return resp, json.loads(body)
|
||||
|
||||
def get_workbook_list(self):
|
||||
resp, body = self.get_list_obj('workbooks')
|
||||
return resp, body['workbooks']
|
||||
def delete_obj(self, obj, name):
|
||||
return self.delete('{obj}/{name}'.format(obj=obj, name=name))
|
||||
|
||||
def get_object(self, obj, id):
|
||||
resp, body = self.get('{obj}/{id}'.format(obj=obj, id=id))
|
||||
return resp, json.loads(body)
|
||||
|
||||
|
||||
class MistralClientV1(MistralClientBase):
|
||||
|
||||
_version = 1
|
||||
|
||||
def create_workbook(self, name):
|
||||
post_body = '{"name": "%s"}' % name
|
||||
resp, body = self.post('workbooks', post_body)
|
||||
return resp, json.loads(body)
|
||||
|
||||
def delete_obj(self, path, name):
|
||||
return self.delete('{path}/{name}'.format(path=path, name=name))
|
||||
|
||||
def delete_workbook(self, workbook_name):
|
||||
return self.delete_obj('workbooks', workbook_name)
|
||||
|
||||
def update_obj(self, path, name):
|
||||
def update_workbook(self, name):
|
||||
post_body = '{"name": "%s"}' % (name + 'updated')
|
||||
resp, body = self.put('{path}/{name}'.format(path=path, name=name),
|
||||
resp, body = self.put('workbooks/{name}'.format(name=name),
|
||||
post_body)
|
||||
return resp, json.loads(body)
|
||||
|
||||
@ -85,24 +97,32 @@ class MistralClient(rest_client.RestClient):
|
||||
return self.get('workbooks/{name}/definition'.format(name=name),
|
||||
headers)
|
||||
|
||||
def upload_workbook_definition(self, name, text):
|
||||
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')
|
||||
|
||||
return self.put('workbooks/{name}/definition'.format(name=name),
|
||||
text, headers)
|
||||
|
||||
def create_execution(self, workbook_name, body):
|
||||
return self.post('workbooks/{name}/executions'.format(
|
||||
def create_execution(self, workbook_name, post_body=None):
|
||||
if post_body is None:
|
||||
body = {
|
||||
"workbook_name": workbook_name,
|
||||
"task": 'hello',
|
||||
"context": ''
|
||||
}
|
||||
else:
|
||||
body = post_body
|
||||
|
||||
rest, body = self.post('workbooks/{name}/executions'.format(
|
||||
name=workbook_name), json.dumps(body))
|
||||
|
||||
def get_execution(self, workbook_name, execution_id):
|
||||
return self.get('/workbooks/{name}/executions/{execution}'.format(
|
||||
name=workbook_name, execution=execution_id))
|
||||
return rest, json.loads(body)
|
||||
|
||||
def update_execution(self, workbook_name, execution_id, put_body):
|
||||
return self.put('/workbooks/{name}/executions/{execution}'.format(
|
||||
name=workbook_name, execution=execution_id), json.dumps(put_body))
|
||||
def update_execution(self, execution_id, put_body):
|
||||
return self.put('executions/{execution}'.format(
|
||||
execution=execution_id), json.dumps(put_body))
|
||||
|
||||
def get_tasks_list(self, workbook_name, execution_id):
|
||||
resp, body = self.get(
|
||||
@ -121,25 +141,29 @@ class MistralClient(rest_client.RestClient):
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def update_task(self, workbook_name, execution_id, task_id, put_body):
|
||||
resp, body = self.put(
|
||||
'/workbooks/{name}/executions/{execution}/tasks/{task}'.format(
|
||||
name=workbook_name,
|
||||
execution=execution_id,
|
||||
task=task_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))
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def prepare_workbook(self, name, text):
|
||||
headers = {'Content-Type': 'text/plain',
|
||||
'X-Auth-Token': self.auth_provider.get_token()}
|
||||
|
||||
return self.put('workbooks/{name}/definition'.format(name=name),
|
||||
text, headers)
|
||||
|
||||
def create_execution_wait_success(self, workbook_name,
|
||||
context, task, timeout=180):
|
||||
post_body = {
|
||||
|
||||
body = {
|
||||
"workbook_name": workbook_name,
|
||||
"task": task,
|
||||
"context": json.dumps(context)
|
||||
}
|
||||
|
||||
resp, ex_body = self.create_execution(workbook_name, post_body)
|
||||
ex_body = json.loads(ex_body)
|
||||
resp, ex_body = self.create_execution(workbook_name, body)
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
@ -151,8 +175,7 @@ class MistralClient(rest_client.RestClient):
|
||||
"to SUCCESS. Execution: {1}".format(timeout, ex_body)
|
||||
raise exceptions.TimeoutException(msg)
|
||||
|
||||
_, ex_body = self.get_execution(workbook_name, ex_body['id'])
|
||||
ex_body = json.loads(ex_body)
|
||||
_, ex_body = self.get_object('executions', ex_body['id'])
|
||||
|
||||
if ex_body['state'] not in expected_states:
|
||||
msg = "Execution state %s is not in expected " \
|
||||
@ -173,7 +196,87 @@ class MistralClient(rest_client.RestClient):
|
||||
return task_body
|
||||
|
||||
|
||||
class MistralClientV2(MistralClientBase):
|
||||
|
||||
_version = 2
|
||||
|
||||
def create_workbook(self, name):
|
||||
post_body = '{"name": "%s", "tags": "tag"}' % name
|
||||
resp, body = self.post('workbooks', post_body)
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def update_workbook(self, name):
|
||||
post_body = '{"name": "%s", "tags": "tag"}' % (name + 'updated')
|
||||
resp, body = self.put('workbooks/{name}'.format(name=name),
|
||||
post_body)
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def get_workbook_definition(self, name):
|
||||
return self.get('workbooks/{name}'.format(name=name))
|
||||
|
||||
def upload_workbook_definition(self, name):
|
||||
text = get_resource('resources/wb_v2.yaml')
|
||||
post_body = {"name": "%s" % name,
|
||||
"tags": "tag",
|
||||
"definition": "%s" % text}
|
||||
resp, body = self.put('workbooks/{name}'.format(name=name),
|
||||
json.dumps(post_body))
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def create_workflow(self, name):
|
||||
text = get_resource('resources/wf_v2.yaml')
|
||||
post_body = {"name": "%s" % name,
|
||||
"definition": "%s" % text,
|
||||
"tags": "tag"}
|
||||
resp, body = self.post('workflows', json.dumps(post_body))
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def update_workflow(self, name):
|
||||
post_body = '{"name": "%s", "tags": "tag"}' % (name + 'updated')
|
||||
resp, body = self.put('workflows/{name}'.format(name=name),
|
||||
post_body)
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
def get_workflow_definition(self, name):
|
||||
return self.get('workflows/{name}'.format(name=name))
|
||||
|
||||
def upload_workflow_definition(self, name):
|
||||
text = get_resource('resources/wf_v2.yaml')
|
||||
post_body = {"name": "%s" % name,
|
||||
"tags": "tag",
|
||||
"definition": "%s" % text}
|
||||
resp, body = self.put('workflows/{name}'.format(name=name),
|
||||
json.dumps(post_body))
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
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)
|
||||
|
||||
return rest, 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))
|
||||
|
||||
return resp, json.loads(body)
|
||||
|
||||
|
||||
class TestCase(tempest.test.BaseTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""This method allows to initialize authentication before
|
||||
@ -182,7 +285,10 @@ class TestCase(tempest.test.BaseTestCase):
|
||||
super(TestCase, cls).setUpClass()
|
||||
|
||||
cls.mgr = clients.Manager()
|
||||
cls.client = MistralClient(cls.mgr.auth_provider)
|
||||
if cls._version == 1:
|
||||
cls.client = MistralClientV1(cls.mgr.auth_provider)
|
||||
if cls._version == 2:
|
||||
cls.client = MistralClientV2(cls.mgr.auth_provider)
|
||||
|
||||
def setUp(self):
|
||||
super(TestCase, self).setUp()
|
||||
@ -190,9 +296,9 @@ class TestCase(tempest.test.BaseTestCase):
|
||||
def tearDown(self):
|
||||
super(TestCase, self).tearDown()
|
||||
|
||||
_, workbooks = self.client.get_workbook_list()
|
||||
for wb in workbooks:
|
||||
self.client.delete_workbook(wb['name'])
|
||||
_, items = self.client.get_list_obj('workbooks')
|
||||
for i in items['workbooks']:
|
||||
self.client.delete_obj('workbooks', i['name'])
|
||||
|
||||
|
||||
class TestCaseAdvanced(TestCase):
|
||||
@ -209,12 +315,14 @@ class TestCaseAdvanced(TestCase):
|
||||
super(TestCaseAdvanced, self).setUp()
|
||||
|
||||
self.workbook_name = 'test'
|
||||
self.server_ids = []
|
||||
|
||||
self.client.create_workbook(self.workbook_name)
|
||||
|
||||
def tearDown(self):
|
||||
_, executions = self.client.get_list_obj('workbooks/test/executions')
|
||||
_, items = self.client.get_list_obj('workbooks')
|
||||
for i in items['workbooks']:
|
||||
self.client.delete_obj('workbooks', i['name'])
|
||||
|
||||
_, executions = self.client.get_list_obj('executions')
|
||||
|
||||
for ex in executions['executions']:
|
||||
self.client.delete_obj('executions', '{0}'.format(ex['id']))
|
||||
|
@ -24,6 +24,9 @@ CONF = cfg.CONF
|
||||
|
||||
|
||||
class OpenStackActionsTest(base.TestCaseAdvanced):
|
||||
|
||||
_version = 1
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(OpenStackActionsTest, cls).setUpClass()
|
||||
@ -35,7 +38,7 @@ class OpenStackActionsTest(base.TestCaseAdvanced):
|
||||
def test_nova_actions(self):
|
||||
nova_wb = base.get_resource(
|
||||
'resources/openstack/nova_actions.yaml')
|
||||
self.client.upload_workbook_definition(self.workbook_name, nova_wb)
|
||||
self.client.prepare_workbook(self.workbook_name, nova_wb)
|
||||
|
||||
context = {
|
||||
'server_name': 'mistral-test',
|
||||
@ -64,8 +67,8 @@ class OpenStackActionsTest(base.TestCaseAdvanced):
|
||||
def test_keystone_actions(self):
|
||||
keystone_wb = base.get_resource(
|
||||
'resources/openstack/keystone_actions.yaml')
|
||||
self.client.upload_workbook_definition(self.workbook_name,
|
||||
keystone_wb)
|
||||
self.client.prepare_workbook(self.workbook_name,
|
||||
keystone_wb)
|
||||
_, execution = self.client.create_execution_wait_success(
|
||||
self.workbook_name, context={}, task='get_some_endpoint')
|
||||
_, tasks = self.client.get_tasks_list(self.workbook_name,
|
||||
@ -84,8 +87,8 @@ class OpenStackActionsTest(base.TestCaseAdvanced):
|
||||
def test_glance_actions(self):
|
||||
glance_wb = base.get_resource(
|
||||
'resources/openstack/glance_actions.yaml')
|
||||
self.client.upload_workbook_definition(self.workbook_name,
|
||||
glance_wb)
|
||||
self.client.prepare_workbook(self.workbook_name,
|
||||
glance_wb)
|
||||
|
||||
_, execution = self.client.create_execution_wait_success(
|
||||
self.workbook_name, context={}, task='image_list')
|
||||
|
11
mistral/tests/resources/wb_v2.yaml
Normal file
11
mistral/tests/resources/wb_v2.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
version: "2.0"
|
||||
|
||||
workflows:
|
||||
test:
|
||||
type: direct
|
||||
tasks:
|
||||
hello:
|
||||
action: std.echo output="Hello"
|
||||
publish:
|
||||
result: $
|
9
mistral/tests/resources/wf_v2.yaml
Normal file
9
mistral/tests/resources/wf_v2.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
version: '2.0'
|
||||
|
||||
type: direct
|
||||
tasks:
|
||||
hello:
|
||||
action: std.echo output="Hello"
|
||||
publish:
|
||||
result: $
|
Loading…
Reference in New Issue
Block a user