Signed-off-by: Christy Perez <christy(a)linux.vnet.ibm.com>
---
tests/test_authorization.py | 23 +++++++++++-------
tests/test_mockmodel.py | 12 +++++++---
tests/test_model.py | 46 +++++++++++++++++++++++++----------
tests/test_rest.py | 58 ++++++++++++++++++++++++++++++++++-----------
4 files changed, 100 insertions(+), 39 deletions(-)
diff --git a/tests/test_authorization.py b/tests/test_authorization.py
index 4fcc496..eae837c 100644
--- a/tests/test_authorization.py
+++ b/tests/test_authorization.py
@@ -26,7 +26,7 @@
import kimchi.mockmodel
from iso_gen import construct_fake_iso
from utils import get_free_port, patch_auth, request
-from utils import run_server
+from utils import run_server, wait_task
test_server = None
@@ -118,19 +118,24 @@ def test_nonroot_access(self):
# Non-root users can only get vms authorized to them
model.templates_create({'name': u'test', 'cdrom':
fake_iso})
- model.vms_create({'name': u'test-me', 'template':
'/templates/test'})
+ task_info = model.vms_create({'name': u'test-me',
+ 'template': '/templates/test'})
+ wait_task(model.task_lookup, task_info['id'])
+
model.vm_update(u'test-me',
{'users': [kimchi.mockmodel.fake_user.keys()[0]],
'groups': []})
- model.vms_create({'name': u'test-usera',
- 'template': '/templates/test'})
+ task_info = model.vms_create({'name': u'test-usera',
+ 'template': '/templates/test'})
+ wait_task(model.task_lookup, task_info['id'])
non_root = list(set(model.users_get_list()) - set(['root']))[0]
model.vm_update(u'test-usera', {'users': [non_root],
'groups': []})
- model.vms_create({'name': u'test-groupa',
- 'template': '/templates/test'})
+ task_info = model.vms_create({'name': u'test-groupa',
+ 'template': '/templates/test'})
+ wait_task(model.task_lookup, task_info['id'])
a_group = model.groups_get_list()[0]
model.vm_update(u'test-groupa', {'groups': [a_group]})
@@ -143,9 +148,9 @@ def test_nonroot_access(self):
self.assertEquals(403, resp.status)
# Create a vm using mockmodel directly to test Resource access
- model.vms_create({'name': 'kimchi-test',
- 'template': '/templates/test'})
-
+ task_info = model.vms_create({'name': 'kimchi-test',
+ 'template': '/templates/test'})
+ wait_task(model.task_lookup, task_info['id'])
resp = self.request('/vms/kimchi-test', '{}', 'PUT')
self.assertEquals(403, resp.status)
resp = self.request('/vms/kimchi-test', '{}', 'DELETE')
diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
index aa48dd1..a731579 100644
--- a/tests/test_mockmodel.py
+++ b/tests/test_mockmodel.py
@@ -66,7 +66,9 @@ def test_screenshot_refresh(self):
req = json.dumps({'name': 'test', 'cdrom': fake_iso})
request(host, ssl_port, '/templates', req, 'POST')
req = json.dumps({'name': 'test-vm', 'template':
'/templates/test'})
- request(host, ssl_port, '/vms', req, 'POST')
+ resp = request(host, ssl_port, '/vms', req, 'POST')
+ task = json.loads(resp.read())
+ wait_task(model.task_lookup, task['id'])
# Test screenshot refresh for running vm
request(host, ssl_port, '/vms/test-vm/start', '{}',
'POST')
@@ -94,7 +96,9 @@ def test_vm_list_sorted(self):
def add_vm(name):
# Create a VM
req = json.dumps({'name': name, 'template':
'/templates/test'})
- request(host, ssl_port, '/vms', req, 'POST')
+ task = json.loads(request(host, ssl_port, '/vms', req,
+ 'POST').read())
+ wait_task(model.task_lookup, task['id'])
vms = [u'abc', u'bca', u'cab', u'xba']
for vm in vms:
@@ -106,7 +110,9 @@ def add_vm(name):
def test_vm_info(self):
model.templates_create({'name': u'test',
'cdrom': fake_iso})
- model.vms_create({'name': u'test-vm', 'template':
'/templates/test'})
+ task = model.vms_create({'name': u'test-vm',
+ 'template': '/templates/test'})
+ wait_task(model.task_lookup, task['id'])
vms = model.vms_get_list()
self.assertEquals(2, len(vms))
self.assertIn(u'test-vm', vms)
diff --git a/tests/test_model.py b/tests/test_model.py
index ad0dccd..7e6090e 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -129,8 +129,11 @@ def test_vm_lifecycle(self):
rollback.prependDefer(inst.template_delete, 'test')
params = {'name': 'kimchi-vm', 'template':
'/templates/test'}
- inst.vms_create(params)
+ task = inst.vms_create(params)
rollback.prependDefer(inst.vm_delete, 'kimchi-vm')
+ inst.task_wait(task['id'], 10)
+ task = inst.task_lookup(task['id'])
+ self.assertEquals('finished', task['status'])
vms = inst.vms_get_list()
self.assertTrue('kimchi-vm' in vms)
@@ -267,7 +270,8 @@ def test_image_based_template(self):
session.store('template', tmpl_name, tmpl_info)
params = {'name': 'kimchi-vm', 'template':
'/templates/img-tmpl'}
- inst.vms_create(params)
+ task = inst.vms_create(params)
+ inst.task_wait(task['id'])
rollback.prependDefer(inst.vm_delete, 'kimchi-vm')
vms = inst.vms_get_list()
@@ -286,7 +290,8 @@ def test_vm_graphics(self):
inst.templates_create(params)
with RollbackContext() as rollback:
params = {'name': 'kimchi-vnc', 'template':
'/templates/test'}
- inst.vms_create(params)
+ task1 = inst.vms_create(params)
+ inst.task_wait(task1['id'])
rollback.prependDefer(inst.vm_delete, 'kimchi-vnc')
info = inst.vm_lookup('kimchi-vnc')
@@ -296,7 +301,8 @@ def test_vm_graphics(self):
graphics = {'type': 'spice', 'listen':
'127.0.0.1'}
params = {'name': 'kimchi-spice', 'template':
'/templates/test',
'graphics': graphics}
- inst.vms_create(params)
+ task2 = inst.vms_create(params)
+ inst.task_wait(task2['id'])
rollback.prependDefer(inst.vm_delete, 'kimchi-spice')
info = inst.vm_lookup('kimchi-spice')
@@ -312,6 +318,10 @@ def test_vm_ifaces(self):
params = {'name': 'test', 'disks': [],
'cdrom': UBUNTU_ISO}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
+ params = {'name': 'kimchi-ifaces', 'template':
'/templates/test'}
+ task = inst.vms_create(params)
+ inst.task_wait(task['id'])
+ rollback.prependDefer(inst.vm_delete, 'kimchi-ifaces')
# Create a network
net_name = 'test-network'
@@ -422,7 +432,8 @@ def _attach_disk(expect_bus=modern_disk_bus):
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
params = {'name': vm_name, 'template':
'/templates/test'}
- inst.vms_create(params)
+ task1 = inst.vms_create(params)
+ inst.task_wait(task1['id'])
rollback.prependDefer(inst.vm_delete, vm_name)
prev_count = len(inst.vmstorages_get_list(vm_name))
@@ -465,7 +476,8 @@ def _attach_disk(expect_bus=modern_disk_bus):
rollback.prependDefer(inst.template_delete, 'old_distro_template')
params = {'name': vm_name,
'template': '/templates/old_distro_template'}
- inst.vms_create(params)
+ task2 = inst.vms_create(params)
+ inst.task_wait(task2['id'])
rollback.prependDefer(inst.vm_delete, vm_name)
# Need to check the right disk_bus for old distro
@@ -486,7 +498,8 @@ def test_vm_cdrom(self):
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
params = {'name': vm_name, 'template':
'/templates/test'}
- inst.vms_create(params)
+ task = inst.vms_create(params)
+ inst.task_wait(task['id'])
rollback.prependDefer(inst.vm_delete, vm_name)
prev_count = len(inst.vmstorages_get_list(vm_name))
@@ -575,7 +588,8 @@ def test_vm_storage_provisioning(self):
rollback.prependDefer(inst.template_delete, 'test')
params = {'name': 'test-vm-1', 'template':
'/templates/test'}
- inst.vms_create(params)
+ task = inst.vms_create(params)
+ inst.task_wait(task['id'])
rollback.prependDefer(inst.vm_delete, 'test-vm-1')
vm_info = inst.vm_lookup(params['name'])
@@ -596,10 +610,12 @@ def test_vm_edit(self):
with RollbackContext() as rollback:
params_1 = {'name': 'kimchi-vm1', 'template':
'/templates/test'}
params_2 = {'name': 'kimchi-vm2', 'template':
'/templates/test'}
- inst.vms_create(params_1)
+ task1 = inst.vms_create(params_1)
+ inst.task_wait(task1['id'])
rollback.prependDefer(utils.rollback_wrapper, inst.vm_delete,
'kimchi-vm1')
- inst.vms_create(params_2)
+ task2 = inst.vms_create(params_2)
+ inst.task_wait(task2['id'])
rollback.prependDefer(utils.rollback_wrapper, inst.vm_delete,
'kimchi-vm2')
@@ -778,11 +794,13 @@ def test_delete_running_vm(self):
rollback.prependDefer(inst.template_delete, 'test')
params = {'name': u'kīмсhī-∨м', 'template':
u'/templates/test'}
- inst.vms_create(params)
+ task = inst.vms_create(params)
+ inst.task_wait(task['id'])
rollback.prependDefer(utils.rollback_wrapper, inst.vm_delete,
u'kīмсhī-∨м')
inst.vm_start(u'kīмсhī-∨м')
+ self.assertEquals(inst.vm_lookup(u'kīмсhī-∨м')['state'],
'running')
rollback.prependDefer(utils.rollback_wrapper, inst.vm_poweroff,
u'kīмсhī-∨м')
@@ -801,7 +819,8 @@ def test_vm_list_sorted(self):
rollback.prependDefer(inst.template_delete, 'test')
params = {'name': 'kimchi-vm', 'template':
'/templates/test'}
- inst.vms_create(params)
+ task = inst.vms_create(params)
+ inst.task_wait(task['id'])
rollback.prependDefer(inst.vm_delete, 'kimchi-vm')
vms = inst.vms_get_list()
@@ -873,7 +892,8 @@ def test_use_test_host(self):
params = {'name': 'kimchi-vm',
'template': '/templates/test'}
- inst.vms_create(params)
+ task = inst.vms_create(params)
+ inst.task_wait(task['id'])
rollback.prependDefer(inst.vm_delete, 'kimchi-vm')
vms = inst.vms_get_list()
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 65c3db5..8826424 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -112,7 +112,9 @@ def test_get_vms(self):
req = json.dumps({'name': name, 'template':
'/templates/test',
'users': test_users, 'groups':
test_groups})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
vms = json.loads(self.request('/vms').read())
self.assertEquals(11, len(vms))
@@ -130,7 +132,9 @@ def test_edit_vm(self):
req = json.dumps({'name': 'vm-1', 'template':
'/templates/test'})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
vm = json.loads(self.request('/vms/vm-1').read())
self.assertEquals('vm-1', vm['name'])
@@ -247,7 +251,9 @@ def test_vm_lifecycle(self):
# Create a VM
req = json.dumps({'name': 'test-vm', 'template':
'/templates/test'})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
+ self.assertEquals(202, resp.status)
# Verify the VM
vm = json.loads(self.request('/vms/test-vm').read())
@@ -429,7 +435,9 @@ def test_vm_graphics(self):
# Create a VM with default args
req = json.dumps({'name': 'test-vm', 'template':
'/templates/test'})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Verify the VM
vm = json.loads(self.request('/vms/test-vm').read())
self.assertEquals('127.0.0.1', vm['graphics']['listen'])
@@ -443,7 +451,9 @@ def test_vm_graphics(self):
req = json.dumps({'name': 'test-vm', 'template':
'/templates/test',
'graphics': graphics})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Verify the VM
vm = json.loads(self.request('/vms/test-vm').read())
self.assertEquals('127.0.0.1', vm['graphics']['listen'])
@@ -457,7 +467,9 @@ def test_vm_graphics(self):
req = json.dumps({'name': 'test-vm', 'template':
'/templates/test',
'graphics': graphics})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Verify the VM
vm = json.loads(self.request('/vms/test-vm').read())
self.assertEquals('fe00::0', vm['graphics']['listen'])
@@ -471,7 +483,9 @@ def test_vm_graphics(self):
req = json.dumps({'name': 'test-vm', 'template':
'/templates/test',
'graphics': graphics})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Verify the VM
vm = json.loads(self.request('/vms/test-vm').read())
self.assertEquals('127.0.0.1', vm['graphics']['listen'])
@@ -513,7 +527,9 @@ def test_vm_storage_devices(self):
req = json.dumps({'name': 'test-vm',
'template': '/templates/test'})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Delete the VM
rollback.prependDefer(self.request,
'/vms/test-vm', '{}',
'DELETE')
@@ -658,7 +674,9 @@ def test_vm_iface(self):
req = json.dumps({'name': 'test-vm',
'template': '/templates/test'})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Delete the VM
rollback.prependDefer(self.request,
'/vms/test-vm', '{}',
'DELETE')
@@ -738,7 +756,10 @@ def test_vm_customise_storage(self):
req = json.dumps({'name': 'test-vm', 'template':
'/templates/test',
'storagepool': '/storagepools/alt'})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
+ resp = self.request('/vms/test-vm', {}, 'GET')
vm_info = json.loads(resp.read())
# Test template not changed after vm customise its pool
@@ -791,7 +812,9 @@ def test_scsi_fc_storage(self):
req = json.dumps({'name': 'test-vm',
'template': '/templates/test_fc_pool'})
resp = self.request('/vms', req, 'POST')
- self.assertEquals(201, resp.status)
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Start the VM
resp = self.request('/vms/test-vm/start', '{}', 'POST')
@@ -816,8 +839,10 @@ def test_unnamed_vms(self):
# Create 5 unnamed vms from this template
for i in xrange(1, 6):
req = json.dumps({'template': '/templates/test'})
- vm = json.loads(self.request('/vms', req, 'POST').read())
- self.assertEquals('test-vm-%i' % i, vm['name'])
+ task = json.loads(self.request('/vms', req, 'POST').read())
+ wait_task(self._task_lookup, task['id'])
+ resp = self.request('/vms/test-vm-%i' % i, {}, 'GET')
+ self.assertEquals(resp.status, 200)
count = len(json.loads(self.request('/vms').read()))
self.assertEquals(6, count)
@@ -849,7 +874,10 @@ def test_create_vm_with_img_based_template(self):
self.assertEquals(201, resp.status)
req = json.dumps({'template': '/templates/test'})
- json.loads(self.request('/vms', req, 'POST').read())
+ resp = self.request('/vms', req, 'POST')
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Test storage volume created with backing store of base file
resp = json.loads(
@@ -939,6 +967,8 @@ def test_screenshot_refresh(self):
resp = self.request('/templates', req, 'POST')
req = json.dumps({'name': 'test-vm', 'template':
'/templates/test'})
resp = self.request('/vms', req, 'POST')
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
# Test screenshot for shut-off state vm
resp = self.request('/vms/test-vm/screenshot')
--
2.1.0