Merge "Add new tests for executions and tasks"

This commit is contained in:
Jenkins 2014-06-06 04:31:14 +00:00 committed by Gerrit Code Review
commit a5c23fd49e
2 changed files with 102 additions and 28 deletions

View File

@ -16,6 +16,7 @@
import json
import os
import time
from tempest import clients
from tempest.common import rest_client
@ -68,9 +69,30 @@ class MistralClient(rest_client.RestClient):
return self.put('workbooks/{name}/definition'.format(name=name),
file, headers)
def create_execution(self, workbook, body):
return self.post('workbooks/{name}/executions'.format(name=workbook),
json.dumps(body))
def create_execution(self, workbook_name, body):
return 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))
def get_tasks_list(self, workbook_name, execution_id):
resp, body = self.get(
'/workbooks/{name}/executions/{execution}/tasks'.format(
name=workbook_name,
execution=execution_id))
return resp, json.loads(body)['tasks']
def get_task(self, workbook_name, execution_id, task_id):
resp, body = self.get(
'/workbooks/{name}/executions/{execution}/tasks/{task}'.format(
name=workbook_name,
execution=execution_id,
task=task_id))
return resp, json.loads(body)
class TestCase(tempest.test.BaseTestCase):
@ -121,5 +143,33 @@ class TestCaseAdvanced(TestCase):
for server_id in self.server_ids:
try:
self.server_client.delete_server(server_id)
self.server_client.wait_for_server_termination(server_id)
except exceptions.NotFound:
pass
def _create_execution(self, workbook_name, server_name):
nova_url = "/".join(self.server_client.base_url.split('/')[:-1])
context = {
"server_name": server_name,
"nova_url": nova_url,
"image_id": self.image_ref,
"flavor_id": self.flavor_ref
}
post_body = {
"workbook_name": workbook_name,
"task": "create-vm",
"context": json.dumps(context)
}
resp, body = self.client.create_execution(workbook_name, post_body)
while not self.server_client.list_servers()[1]['servers']:
time.sleep(2)
for server in self.server_client.list_servers()[1]['servers']:
if server['name'] == server_name:
self.server_ids.append(server['id'])
return resp, json.loads(body)

View File

@ -15,7 +15,6 @@
# under the License.
import json
import time
from tempest import exceptions
from tempest import test
@ -124,34 +123,59 @@ class SanityTests(base.TestCase):
class ExecutionTests(base.TestCaseAdvanced):
@test.attr(type='smoke')
def test_create_execution(self):
def setUp(self):
super(ExecutionTests, self).setUp()
self.client.create_obj('workbooks', 'test123')
self.obj.append(['workbooks', 'test123'])
self.client.upload_workbook_definition('test123')
nova_url = "/".join(self.server_client.base_url.split('/')[:-1])
context = {
"server_name": "aloha",
"nova_url": nova_url,
"image_id": self.image_ref,
"flavor_id": self.flavor_ref
}
post_body = {
"workbook_name": "test123",
"task": "create-vm",
"context": json.dumps(context)
}
resp, body = self.client.create_execution('test123', post_body)
body = json.loads(body)
@test.attr(type='positive')
def test_create_execution(self):
resp, body = self._create_execution('test123', 'aloha')
self.assertEqual(201, resp.status)
self.assertEqual('test123', body["workbook_name"])
while not self.server_client.list_servers()[1]['servers']:
time.sleep(2)
for server in self.server_client.list_servers()[1]['servers']:
if server['name'] == 'aloha':
self.server_ids.append(server['id'])
@test.attr(type='positive')
def test_get_execution(self):
_, execution = self._create_execution('test123', 'aloha')
resp, body = self.client.get_execution('test123', execution['id'])
body = json.loads(body)
del execution['state']
del body['state']
self.assertEqual(200, resp.status)
self.assertEqual(execution, body)
#TODO(smurashov): Need to add test which would check execution update
@test.attr(type='positive')
def test_get_tasks_list(self):
execution = self._create_execution('test123', 'aloha')[1]
resp, tasks = self.client.get_tasks_list('test123', execution['id'])
self.assertEqual(200, resp.status)
for task in tasks:
self.assertEqual(execution['id'], task['execution_id'])
self.assertEqual('test123', task['workbook_name'])
@test.attr(type='positive')
def test_get_task(self):
_, execution = self._create_execution('test123', 'aloha')
tasks = self.client.get_tasks_list('test123', execution['id'])[1]
resp, task = self.client.get_task('test123', execution['id'],
tasks[0]['id'])
del tasks[0]['state']
del task['state']
self.assertEqual(200, resp.status)
self.assertEqual(tasks[0], task)
#TODO(smurashov): Need to add test which would check task update