[Kimchi-devel] [PATCH] issue #437: Only allow a bootable image file to be used on template
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Sep 24 00:29:47 UTC 2014
While creating a template from a image file, the latter must be a
bootable image.
As probe_image() does all the verifications regarding the image file,
the exception must be raised in order to inform user about the problem.
Also update the test case accordingly.
Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
src/kimchi/vmtemplate.py | 8 ++------
tests/test_model.py | 29 +++++++++++++++++++++++------
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index 4994a5f..5f22db9 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -29,8 +29,7 @@ from distutils.version import LooseVersion
from kimchi import osinfo
-from kimchi.exception import InvalidParameter, IsoFormatError, ImageFormatError
-from kimchi.exception import MissingParameter
+from kimchi.exception import InvalidParameter, IsoFormatError, MissingParameter
from kimchi.imageinfo import probe_image, probe_img_info
from kimchi.isoinfo import IsoImage
from kimchi.utils import check_url_path, pool_name_from_uri
@@ -96,10 +95,7 @@ class VMTemplate(object):
if 'base' in d.keys():
base_imgs.append(d)
if scan:
- try:
- distro, version = probe_image(d['base'])
- except ImageFormatError:
- pass
+ distro, version = probe_image(d['base'])
if 'size' not in d.keys():
d['size'] = probe_img_info(d['base'])['virtual-size']
diff --git a/tests/test_model.py b/tests/test_model.py
index d458478..63be20e 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -37,8 +37,8 @@ import kimchi.objectstore
import utils
from kimchi import netinfo
from kimchi.config import paths
-from kimchi.exception import InvalidOperation, InvalidParameter
-from kimchi.exception import NotFoundError, OperationFailed
+from kimchi.exception import ImageFormatError, InvalidOperation
+from kimchi.exception import InvalidParameter, NotFoundError, OperationFailed
from kimchi.iscsi import TargetClient
from kimchi.model import model
from kimchi.rollbackcontext import RollbackContext
@@ -126,10 +126,27 @@ class ModelTests(unittest.TestCase):
rollback.prependDefer(inst.storagevolume_delete, 'default', vol)
params = {'name': 'test', 'disks': [{'base': vol_path}]}
- inst.templates_create(params)
- rollback.prependDefer(inst.template_delete, 'test')
-
- params = {'name': 'kimchi-vm', 'template': '/templates/test'}
+ self.assertRaises(ImageFormatError, inst.templates_create, params)
+
+ # Hack the model objstore to add a new template
+ # It is needed as the image file must be a bootable image when
+ # using model
+ # As it is difficult to create one on test runtime, inject a
+ # template with an empty image file to the objstore to test the
+ # feature
+ tmpl_name = "img-tmpl"
+ tmpl_info = {"cpus": 1, "cdrom": "",
+ "graphics": {"type": "vnc", "listen": "127.0.0.1"},
+ "networks": ["default"], "memory": 1024, "folder": [],
+ "icon": "images/icon-vm.png",
+ "os_distro": "unknown", "os_version": "unknown",
+ "disks": [{"base": vol_path, "size": 10}],
+ "storagepool": "/storagepools/default"}
+
+ with inst.objstore as session:
+ session.store('template', tmpl_name, tmpl_info)
+
+ params = {'name': 'kimchi-vm', 'template': '/templates/img-tmpl'}
inst.vms_create(params)
rollback.prependDefer(inst.vm_delete, 'kimchi-vm')
--
1.9.3
More information about the Kimchi-devel
mailing list