From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
update test_rest.py and test_model.py
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
tests/test_model.py | 16 ++++++++++++++++
tests/test_rest.py | 15 +++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/tests/test_model.py b/tests/test_model.py
index bf6f27a..859f7bd 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -441,6 +441,22 @@ class ModelTests(unittest.TestCase):
self.assertEquals(params[key], info[key])
@unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
+ def test_template_clone(self):
+ inst = model.Model('qemu:///system',
+ objstore_loc=self.tmp_store)
+ with RollbackContext() as rollback:
+ orig_params = {'name': 'test-template', 'memory':
1024, 'cpus': 1}
+ inst.templates_create(orig_params)
+ orig_temp = inst.template_lookup(orig_params['name'])
+
+ ident = inst.template_clone('test-template')
+ clone_temp = inst.template_lookup(ident)
+
+ clone_temp['name'] = orig_temp['name']
+ for key in clone_temp.keys():
+ self.assertEquals(clone_temp[key], orig_temp[key])
+
+ @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
def test_template_update(self):
inst = model.Model('qemu:///system',
objstore_loc=self.tmp_store)
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 0e6a253..5aac211 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -949,6 +949,21 @@ class RestTests(unittest.TestCase):
res = json.loads(self.request('/templates/test').read())
verify_template(t, res)
+ # clone a template
+ resp = self.request('/templates/%s/clone' % t['name'],
'{}', 'POST')
+ self.assertEquals(303, resp.status)
+
+ # Verify the clone template
+ res = json.loads(self.request('/templates/%s-clone1' %
+ t['name']).read())
+ old_temp = t['name']
+ t['name'] = res['name']
+ verify_template(t, res)
+ # Delete the clone template
+ resp = self.request('/templates/%s' % t['name'], '{}',
'DELETE')
+ self.assertEquals(204, resp.status)
+ t['name'] = old_temp
+
# Create a template with same name fails with 400
t = {'name': 'test', 'os_distro': 'ImagineOS',
'os_version': '1.0', 'memory': 1024, 'cpus':
1,
--
1.8.4.2