
Reviewed-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> On 12/11/2014 05:05 AM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
When disk os cannot be decided by libguestfs, it will leave it to 'unknown' distro and version. But if no boot information available, ImageFormatError is left unhandled and this will introduce 500 error when disk os info is absent. Handle this error to fix this.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/vmtemplate.py | 6 +++++- tests/test_model.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index 8582d48..3266e7b 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -29,6 +29,7 @@ from lxml.builder import E from kimchi import imageinfo from kimchi import osinfo from kimchi.exception import InvalidParameter, IsoFormatError, MissingParameter +from kimchi.exception import ImageFormatError, OperationFailed from kimchi.isoinfo import IsoImage from kimchi.utils import check_url_path, pool_name_from_uri from kimchi.xmlutils.disk import get_disk_xml @@ -51,7 +52,10 @@ class VMTemplate(object): self.fc_host_support = args.get('fc_host_support')
# Fetch defaults based on the os distro and version - distro, version = self._get_os_info(args, scan) + try: + distro, version = self._get_os_info(args, scan) + except ImageFormatError as e: + raise OperationFailed('KCHTMPL0020E', {'err': e.message}) os_distro = args.get('os_distro', distro) os_version = args.get('os_version', version) entry = osinfo.lookup(os_distro, os_version) diff --git a/tests/test_model.py b/tests/test_model.py index aa2a1bb..2bcb075 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -196,7 +196,7 @@ class ModelTests(unittest.TestCase): vol_path = inst.storagevolume_lookup('default', vol)['path']
params = {'name': 'test', 'disks': [{'base': vol_path}]} - self.assertRaises(ImageFormatError, inst.templates_create, params) + self.assertRaises(OperationFailed, 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