On 04/20/2016 05:22 PM, pvital(a)linux.vnet.ibm.com wrote:
From: Paulo Vital <pvital(a)linux.vnet.ibm.com>
Update test cases to support the creation of netboot templates and creation of
guests without cdrom.
This is part of solution to Issue #372.
Signed-off-by: Paulo Vital <pvital(a)linux.vnet.ibm.com>
---
tests/test_authorization.py | 4 +++-
tests/test_mockmodel.py | 15 ++++++++-----
tests/test_model.py | 43 +++++++++++++++++++++---------------
tests/test_rest.py | 37 +++++++++++++++++++++----------
tests/test_template.py | 53 ++++++++++++++++++++++++++++++++++-----------
tests/test_vmtemplate.py | 18 +++++++++++++++
6 files changed, 122 insertions(+), 48 deletions(-)
diff --git a/tests/test_authorization.py b/tests/test_authorization.py
index 7cf8da2..cbeca04 100644
--- a/tests/test_authorization.py
+++ b/tests/test_authorization.py
@@ -100,7 +100,9 @@ class AuthorizationTests(unittest.TestCase):
self.assertEquals(403, resp.status)
# Non-root users can only get vms authorized to them
- model.templates_create({'name': u'test', 'source_media':
fake_iso})
+ model.templates_create({'name': u'test',
+ 'source_media': {'type':
'disk',
+ 'path': fake_iso}})
task_info = model.vms_create({
'name': u'test-me',
diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
index 41156f9..d5fffb4 100644
--- a/tests/test_mockmodel.py
+++ b/tests/test_mockmodel.py
@@ -66,7 +66,8 @@ class MockModelTests(unittest.TestCase):
def test_screenshot_refresh(self):
# Create a VM
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': fake_iso}})
request(host, ssl_port, '/plugins/kimchi/templates', req,
'POST')
req = json.dumps({'name': 'test-vm',
'template':
'/plugins/kimchi/templates/test'})
@@ -96,7 +97,8 @@ class MockModelTests(unittest.TestCase):
resp.getheader('last-modified'))
def test_vm_list_sorted(self):
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': fake_iso}})
request(host, ssl_port, '/plugins/kimchi/templates', req,
'POST')
def add_vm(name):
@@ -116,7 +118,8 @@ class MockModelTests(unittest.TestCase):
def test_memory_window_changes(self):
model.templates_create({'name': u'test',
- 'source_media': fake_iso})
+ 'source_media': {'type':
'disk',
+ 'path': fake_iso}})
task = model.vms_create({'name': u'test-vm',
'template':
'/plugins/kimchi/templates/test'})
wait_task(model.task_lookup, task['id'])
@@ -128,7 +131,8 @@ class MockModelTests(unittest.TestCase):
def test_hotplug_3D_card(self):
model.templates_create({'name': u'test',
- 'source_media': fake_iso})
+ 'source_media': {'type':
'disk',
+ 'path': fake_iso}})
task = model.vms_create({'name': u'test-vm',
'template':
'/plugins/kimchi/templates/test'})
wait_task(model.task_lookup, task['id'])
@@ -148,7 +152,8 @@ class MockModelTests(unittest.TestCase):
def test_vm_info(self):
model.templates_create({'name': u'test',
- 'source_media': fake_iso})
+ 'source_media': {'type':
'disk',
+ 'path': fake_iso}})
task = model.vms_create({'name': u'test-vm',
'template':
'/plugins/kimchi/templates/test'})
wait_task(model.task_lookup, task['id'])
diff --git a/tests/test_model.py b/tests/test_model.py
index 0804228..edab447 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -136,7 +136,8 @@ class ModelTests(unittest.TestCase):
task = inst.task_lookup(task['id'])
self.assertEquals('finished', task['status'])
- params = {'name': 'test', 'source_media':
UBUNTU_ISO}
+ params = {'name': 'test',
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
@@ -269,7 +270,7 @@ class ModelTests(unittest.TestCase):
"networks": ["default"],
"memory": {'current': 1024},
"folder": [], "icon":
"images/icon-vm.png",
"os_distro": "unknown",
"os_version": "unknown",
- "source_media": vol_path}
+ "source_media": {'type': 'disk',
'path': vol_path}}
inst.templates_create(tmpl_info)
rollback.prependDefer(inst.template_delete, tmpl_name)
@@ -296,7 +297,8 @@ class ModelTests(unittest.TestCase):
@unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
def test_vm_graphics(self):
inst = model.Model(objstore_loc=self.tmp_store)
- params = {'name': 'test', 'source_media': UBUNTU_ISO}
+ params = {'name': 'test',
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
with RollbackContext() as rollback:
params = {'name': 'kimchi-vnc',
@@ -326,7 +328,8 @@ class ModelTests(unittest.TestCase):
@unittest.skipUnless(utils.running_as_root(), "Must be run as root")
def test_vm_serial(self):
inst = model.Model(objstore_loc=self.tmp_store)
- params = {'name': 'test', 'source_media': UBUNTU_ISO}
+ params = {'name': 'test',
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
with RollbackContext() as rollback:
params = {'name': 'kimchi-serial',
@@ -347,7 +350,8 @@ class ModelTests(unittest.TestCase):
def test_vm_ifaces(self):
inst = model.Model(objstore_loc=self.tmp_store)
with RollbackContext() as rollback:
- params = {'name': 'test', 'source_media':
UBUNTU_ISO}
+ params = {'name': 'test',
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
@@ -463,7 +467,8 @@ class ModelTests(unittest.TestCase):
inst.task_wait(task_id)
vm_name = 'kimchi-cdrom'
- params = {'name': 'test', 'disks': [],
'source_media': UBUNTU_ISO}
+ params = {'name': 'test', 'disks': [],
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
params = {'name': vm_name,
@@ -507,7 +512,7 @@ class ModelTests(unittest.TestCase):
vm_name = 'kimchi-ide-bus-vm'
params = {'name': 'old_distro_template', 'disks':
[],
- 'source_media': old_distro_iso}
+ 'source_media': {'type': 'disk',
'path': old_distro_iso}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'old_distro_template')
params = {
@@ -532,7 +537,8 @@ class ModelTests(unittest.TestCase):
inst = model.Model(objstore_loc=self.tmp_store)
with RollbackContext() as rollback:
vm_name = 'kimchi-cdrom'
- params = {'name': 'test', 'disks': [],
'source_media': UBUNTU_ISO}
+ params = {'name': 'test', 'disks': [],
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
params = {'name': vm_name,
@@ -623,7 +629,7 @@ class ModelTests(unittest.TestCase):
with RollbackContext() as rollback:
params = {'name': 'test', 'disks':
[{'size': 1, 'pool': {
'name':
'/plugins/kimchi/storagepools/default'}}],
- 'source_media': UBUNTU_ISO}
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
@@ -683,7 +689,7 @@ class ModelTests(unittest.TestCase):
params = {'name': 'test', 'disks':
[{'size': 1, 'pool': {
'name':
'/plugins/kimchi/storagepools/default'}}],
- 'source_media': UBUNTU_ISO}
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
@@ -711,7 +717,7 @@ class ModelTests(unittest.TestCase):
params = {'name': 'test', 'disks': [{
'size': 1, 'format': user_vol,
'pool': {'name':
'/plugins/kimchi/storagepools/default'}}],
- 'source_media': UBUNTU_ISO}
+ 'source_media': {'type': 'disk', 'path':
UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
@@ -737,7 +743,7 @@ class ModelTests(unittest.TestCase):
params = {'name': 'test', 'disks':
[{'size': 1, 'pool': {
'name':
'/plugins/kimchi/storagepools/default'}}],
- 'source_media': UBUNTU_ISO}
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
@@ -757,7 +763,7 @@ class ModelTests(unittest.TestCase):
inst = model.Model(None, objstore_loc=self.tmp_store)
orig_params = {'name': 'test',
'memory': {'current': 1024, 'maxmemory':
3072},
- 'source_media': UBUNTU_ISO}
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(orig_params)
with RollbackContext() as rollback:
@@ -794,7 +800,8 @@ class ModelTests(unittest.TestCase):
# only supports this format
orig_params = {
'name': 'test', 'memory': {'current':
1024},
- 'cpu_info': {'vcpus': 1}, 'source_media':
UBUNTU_ISO,
+ 'cpu_info': {'vcpus': 1},
+ 'source_media': {'type': 'disk', 'path':
UBUNTU_ISO},
'disks': [{'size': 1, 'format': 'qcow2',
'pool': {
'name':
'/plugins/kimchi/storagepools/default'}}]}
inst.templates_create(orig_params)
@@ -1033,7 +1040,8 @@ class ModelTests(unittest.TestCase):
inst = model.Model(objstore_loc=self.tmp_store)
with RollbackContext() as rollback:
- params = {'name': u'test', 'disks': [],
'source_media': UBUNTU_ISO}
+ params = {'name': u'test', 'disks': [],
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
@@ -1059,7 +1067,8 @@ class ModelTests(unittest.TestCase):
inst = model.Model(objstore_loc=self.tmp_store)
with RollbackContext() as rollback:
- params = {'name': 'test', 'disks': [],
'source_media': UBUNTU_ISO}
+ params = {'name': 'test', 'disks': [],
+ 'source_media': {'type': 'disk',
'path': UBUNTU_ISO}}
inst.templates_create(params)
rollback.prependDefer(inst.template_delete, 'test')
@@ -1130,7 +1139,7 @@ class ModelTests(unittest.TestCase):
with RollbackContext() as rollback:
params = {
'name': 'test',
- 'source_media': UBUNTU_ISO,
+ 'source_media': {'type': 'disk', 'path':
UBUNTU_ISO},
'domain': 'test',
'arch': 'i686',
'disks': []
diff --git a/tests/test_rest.py b/tests/test_rest.py
index a009ed3..cf86926 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -106,7 +106,8 @@ class RestTests(unittest.TestCase):
self.assertEquals(1, len(vms))
# Create a template as a base for our VMs
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': fake_iso}})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -133,7 +134,8 @@ class RestTests(unittest.TestCase):
self.assertEquals([], vm['groups'])
def test_edit_vm(self):
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': fake_iso}})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -290,7 +292,8 @@ class RestTests(unittest.TestCase):
def test_vm_lifecycle(self):
# Create a Template
- req = json.dumps({'name': 'test', 'source_media':
fake_iso,
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': fake_iso},
'disks': DISKS,
'icon':
'plugins/kimchi/images/icon-debian.png'})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
@@ -517,7 +520,8 @@ class RestTests(unittest.TestCase):
def test_vm_graphics(self):
# Create a Template
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': fake_iso}})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -611,7 +615,9 @@ class RestTests(unittest.TestCase):
with RollbackContext() as rollback:
# Create a template as a base for our VMs
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
+ 'path': fake_iso}})
resp = self.request('/plugins/kimchi/templates', req,
'POST')
self.assertEquals(201, resp.status)
# Delete the template
@@ -784,7 +790,9 @@ class RestTests(unittest.TestCase):
with RollbackContext() as rollback:
# Create a template as a base for our VMs
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
+ 'path': fake_iso}})
resp = self.request('/plugins/kimchi/templates', req,
'POST')
self.assertEquals(201, resp.status)
# Delete the template
@@ -891,7 +899,7 @@ class RestTests(unittest.TestCase):
def test_vm_customise_storage(self):
# Create a Template
req = json.dumps({'name': 'test', 'disks': DISKS,
- 'source_media': fake_iso})
+ 'source_media': {'type': 'disk',
'path': fake_iso}})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -953,7 +961,8 @@ class RestTests(unittest.TestCase):
# Create template fails because SCSI volume is missing
tmpl_params = {
- 'name': 'test_fc_pool', 'source_media': fake_iso,
+ 'name': 'test_fc_pool',
+ 'source_media': {'type': 'disk', 'path':
fake_iso},
'disks': [{'pool':
{'name':
'/plugins/kimchi/storagepools/scsi_fc_pool'}}]}
@@ -998,7 +1007,8 @@ class RestTests(unittest.TestCase):
def test_unnamed_vms(self):
# Create a Template
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': fake_iso}})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -1040,7 +1050,8 @@ class RestTests(unittest.TestCase):
# Create a Template
mock_base = '/tmp/mock.img'
os.system("qemu-img create -f qcow2 %s 10M" % mock_base)
- req = json.dumps({'name': 'test', 'source_media':
mock_base})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': mock_base}})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -1110,7 +1121,8 @@ class RestTests(unittest.TestCase):
# In real model os distro/version can be omitted
# as we will scan the iso
req = json.dumps({'name': 'test',
- 'source_media': storagevolume['path'],
+ 'source_media': {'type': 'disk',
+ 'path':
storagevolume['path']},
'os_distro': storagevolume['os_distro'],
'os_version': storagevolume['os_version']})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
@@ -1148,7 +1160,8 @@ class RestTests(unittest.TestCase):
def test_screenshot_refresh(self):
# Create a VM
- req = json.dumps({'name': 'test', 'source_media':
fake_iso})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': fake_iso}})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
req = json.dumps({'name': 'test-vm',
'template':
'/plugins/kimchi/templates/test'})
diff --git a/tests/test_template.py b/tests/test_template.py
index 158bbeb..71835ae 100644
--- a/tests/test_template.py
+++ b/tests/test_template.py
@@ -80,8 +80,26 @@ class TemplateTests(unittest.TestCase):
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(400, resp.status)
+ # Create a netboot template
+ t = {'name': 'test-netboot', 'source_media':
{'type': 'netboot'}}
+ req = json.dumps(t)
+ resp = self.request('/plugins/kimchi/templates', req, 'POST')
+ self.assertEquals(201, resp.status)
+
+ # Verify the netboot template
+ tmpl = json.loads(
+ self.request('/plugins/kimchi/templates/test-netboot').read()
+ )
+ self.assertIsNone(tmpl['cdrom'])
+
Please, create a vm using the netboot template and start/stop it just to
make sure the vm created has a valid XML configuration for netboot.
+ # Delete the netboot template
+ resp = self.request('/plugins/kimchi/templates/test-netboot',
'{}',
+ 'DELETE')
+ self.assertEquals(204, resp.status)
+
# Create a template
- t = {'name': 'test', 'source_media': MOCK_ISO}
+ t = {'name': 'test',
+ 'source_media': {'type': 'disk', 'path':
MOCK_ISO}}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -93,7 +111,7 @@ class TemplateTests(unittest.TestCase):
self.request('/plugins/kimchi/templates/test').read()
)
self.assertEquals(sorted(tmpl.keys()), sorted(keys))
- self.assertEquals(t['source_media'], tmpl["cdrom"])
+ self.assertEquals(t['source_media']['path'],
tmpl["cdrom"])
disk_keys = ['index', 'pool', 'size',
'format']
disk_pool_keys = ['name', 'type']
self.assertEquals(sorted(tmpl['disks'][0].keys()), sorted(disk_keys))
@@ -119,22 +137,25 @@ class TemplateTests(unittest.TestCase):
self.assertEquals(204, resp.status)
# Create a template with same name fails with 400
- req = json.dumps({'name': 'test', 'source_media':
MOCK_ISO})
+ req = json.dumps({'name': 'test',
+ 'source_media': {'type': 'disk',
'path': MOCK_ISO}})
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(400, resp.status)
# Create an image based template
os.system("qemu-img create -f qcow2 %s 10G" %
'/tmp/mock.img')
- t = {'name': 'test_img_template', 'source_media':
'/tmp/mock.img'}
+ t = {'name': 'test_img_template',
+ 'source_media': {'type': 'disk', 'path':
'/tmp/mock.img'}}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
os.remove('/tmp/mock.img')
# Test disk format
- t = {'name': 'test-format', 'source_media': MOCK_ISO,
'disks': [{
- 'size': 10, 'format': 'vmdk', 'pool': {
- 'name': DEFAULT_POOL}}]}
+ t = {'name': 'test-format',
+ 'source_media': {'type': 'disk', 'path':
MOCK_ISO},
+ 'disks': [{'size': 10, 'format': 'vmdk',
+ 'pool': {'name': DEFAULT_POOL}}]}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
@@ -150,7 +171,8 @@ class TemplateTests(unittest.TestCase):
else:
max_mem = (psutil.TOTAL_PHYMEM >> 10 >> 10)
memory = max_mem + 1024
- t = {'name': 'test-maxmem', 'source_media': MOCK_ISO,
+ t = {'name': 'test-maxmem',
+ 'source_media': {'type': 'disk', 'path':
MOCK_ISO},
'memory': {'current': memory}}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
@@ -159,7 +181,8 @@ class TemplateTests(unittest.TestCase):
def test_customized_tmpl(self):
# Create a template
- t = {'name': 'test', 'source_media': MOCK_ISO}
+ t = {'name': 'test',
+ 'source_media': {'type': 'disk', 'path':
MOCK_ISO}}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -329,7 +352,8 @@ class TemplateTests(unittest.TestCase):
def test_customized_network(self):
# Create a template
- t = {'name': 'test', 'source_media': MOCK_ISO}
+ t = {'name': 'test',
+ 'source_media': {'type': 'disk', 'path':
MOCK_ISO}}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -365,7 +389,8 @@ class TemplateTests(unittest.TestCase):
def test_customized_storagepool(self):
# Create a template
- t = {'name': 'test', 'source_media': MOCK_ISO}
+ t = {'name': 'test',
+ 'source_media': {'type': 'disk', 'path':
MOCK_ISO}}
req = json.dumps(t)
resp = self.request('/plugins/kimchi/templates', req, 'POST')
self.assertEquals(201, resp.status)
@@ -456,8 +481,10 @@ class TemplateTests(unittest.TestCase):
self.request(pool_uri + '/activate', '{}', 'POST')
# Create a template using the custom network and pool
- t = {'name': 'test', 'source_media': mock_iso2,
- 'networks': ['nat-network'], 'disks':
[{'pool': {
+ t = {'name': 'test',
+ 'source_media': {'type': 'disk', 'path':
mock_iso2},
+ 'networks': ['nat-network'],
+ 'disks': [{'pool': {
'name': '/plugins/kimchi/storagepools/dir-pool'},
'size': 2,
'format': 'qcow2'}]}
diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py
index 503d34a..772093e 100644
--- a/tests/test_vmtemplate.py
+++ b/tests/test_vmtemplate.py
@@ -135,3 +135,21 @@ class VMTemplateTests(unittest.TestCase):
self.assertEquals(['foo'], t.info.get('networks'))
self.assertEquals(self.iso, t.info.get('cdrom'))
self.assertEquals(graphics, t.info.get('graphics'))
+
+ def test_netboot_vmtemplate(self):
+ disk_bus = get_template_default('old', 'disk_bus')
+ memory = get_template_default('old', 'memory')
+ nic_model = get_template_default('old', 'nic_model')
+ fields = (('name', 'test'), ('os_distro',
'unknown'),
+ ('os_version', 'unknown'),
+ ('cpu_info', {'vcpus': 1, 'maxvcpus': 1}),
+ ('memory', memory), ('networks',
['default']),
+ ('disk_bus', disk_bus), ('nic_model', nic_model),
+ ('graphics', {'type': 'vnc', 'listen':
'127.0.0.1'}))
+
+ args = {'name': 'test', 'source_media': {'type':
'netboot'}}
+ t = VMTemplate(args)
+ for name, val in fields:
+ self.assertEquals(val, t.info.get(name))
+
+ self.assertNotIn('cdrom', t.info.keys())