[Kimchi-devel] [PATCH] Issue#536: raise proper error message when disk os info absent

Aline Manera alinefm at linux.vnet.ibm.com
Wed Dec 10 14:59:38 UTC 2014


You need to update the tests cases accordingly:

======================================================================
ERROR: test_image_based_template (test_model.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "test_model.py", line 199, in test_image_based_template
     self.assertRaises(ImageFormatError, inst.templates_create, params)
   File "/usr/lib64/python2.7/unittest/case.py", line 513, in assertRaises
     callableObj(*args, **kwargs)
   File "/home/alinefm/kimchi/src/kimchi/model/templates.py", line 93, 
in create
     t = LibvirtVMTemplate(params, scan=True)
   File "/home/alinefm/kimchi/src/kimchi/model/templates.py", line 230, 
in __init__
     VMTemplate.__init__(self, args, scan)
   File "/home/alinefm/kimchi/src/kimchi/vmtemplate.py", line 58, in 
__init__
     raise OperationFailed('KCHTMPL0020E', {'err': e.message})
OperationFailed: KCHTMPL0020E: Unable to create template due error: 
KCHIMG0002E: No OS information found in given image.

======================================================================


On 12/10/2014 11:23 AM, lvroyce0210 at gmail.com wrote:
> From: Royce Lv <lvroyce at 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 at linux.vnet.ibm.com>
> ---
>   src/kimchi/vmtemplate.py | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> 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)




More information about the Kimchi-devel mailing list