From: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
This patch adds the 'migrate' API in mockmodel.py, allowing
it to be tested in test_rest.py.
A new test called 'test_vm_migrate' was added in test_rest.py.
Signed-off-by: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
---
mockmodel.py | 17 ++++++++++++++++-
tests/test_rest.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/mockmodel.py b/mockmodel.py
index 43ef1be..9e27d3f 100644
--- a/mockmodel.py
+++ b/mockmodel.py
@@ -1,7 +1,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -411,6 +411,21 @@ class MockModel(Model):
MockModel._mock_snapshots[new_name] = snapshots
return self._model_vm_clone(name)
+ def _mock_vm_migrate(self, name, remote_host, user=None, password=None,
+ enable_rdma=None):
+
+ if enable_rdma is None:
+ enable_rdma = False
+
+ params = {'remote_host': remote_host, 'enable_rdma':
enable_rdma}
+ taskid = AsyncTask(u'/plugins/kimchi/vms/%s/migrate' % name,
+ self._vmmigrate_create_task,
+ params).id
+ return self.task_lookup(taskid)
+
+ def _vmmigrate_create_task(self, cb, params):
+ cb('OK', True)
+
def _mock_vmvirtviewerfile_lookup(self, vm_name):
file_name = 'plugins/kimchi/data/virtviewerfiles/%s' %\
os.path.basename(self.virtviewerfile_tmp.name)
diff --git a/tests/test_rest.py b/tests/test_rest.py
index f25a693..56b8a89 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2013-2016
+# Copyright IBM Corp, 2013-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -1248,6 +1248,52 @@ class RestTests(unittest.TestCase):
resp = json.loads(resp.read())
self.assertIn(u"KCHVM0012E", resp['reason'])
+ def test_vm_migrate(self):
+ with RollbackContext() as rollback:
+ req = json.dumps({'name': 'test-migrate',
+ 'source_media': {'type': 'disk',
+ 'path': fake_iso}})
+ resp = self.request('/plugins/kimchi/templates', req,
'POST')
+ self.assertEquals(201, resp.status)
+ rollback.prependDefer(self.request,
+ '/plugins/kimchi/templates/test-migrate',
+ '{}', 'DELETE')
+
+ req = json.dumps(
+ {'name': 'test-vm-migrate',
+ 'template': '/plugins/kimchi/templates/test-migrate'}
+ )
+ resp = self.request('/plugins/kimchi/vms', req, 'POST')
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
+ rollback.prependDefer(self.request, '/plugins/kimchi/vms/test-vm',
+ '{}', 'DELETE')
+
+ params = {'remote_host': 'destination_host'}
+ resp = self.request(
+ '/plugins/kimchi/vms/test-vm-migrate/migrate',
+ json.dumps(params), 'POST')
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
+ task = json.loads(
+ self.request('/plugins/kimchi/tasks/%s' %
task['id']).read()
+ )
+ self.assertEquals('finished', task['status'])
+
+ params = {'remote_host': 'rdma_host', 'enable_rdma':
True}
+ resp = self.request(
+ '/plugins/kimchi/vms/test-vm-migrate/migrate',
+ json.dumps(params), 'POST')
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
+ task = json.loads(
+ self.request('/plugins/kimchi/tasks/%s' %
task['id']).read()
+ )
+ self.assertEquals('finished', task['status'])
+
def test_create_vm_with_img_based_template(self):
resp = json.loads(
self.request(
--
2.7.4