[Kimchi-devel] [PATCH] issue #447: Check download URL prior to start Task

Aline Manera alinefm at linux.vnet.ibm.com
Thu Sep 25 02:08:57 UTC 2014


When user provides an invalid donwload URL, the error message
"Unexpected exception" was displayed without any more information.

On Kimchi logs, there is:

Error in async_task 1
Traceback (most recent call last):
  File "/home/alinefm/kimchi/src/kimchi/asynctask.py", line 72, in _run_helper
    self.fn(cb, opaque)
  File "/home/alinefm/kimchi/src/kimchi/model/storagevolumes.py", line 192, in _create_volume_with_url
    with contextlib.closing(urllib2.urlopen(url)) as response:
  File "/usr/lib64/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib64/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib64/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib64/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 1224, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib64/python2.7/urllib2.py", line 1186, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno -2] Name or service not known>

It is because the download URL was not being checked prior to start the
Task and this case was not checked on Task handler.

To solver it, check if the download URL is accessible prior to start the
Task so user can change it accordingly.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py                 | 1 +
 src/kimchi/model/storagevolumes.py | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 635d6b9..67dfc11 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -190,6 +190,7 @@ messages = {
     "KCHVOL0019E": _("Create volume from %(param)s is not supported"),
     "KCHVOL0020E": _("Storage volume capacity must be an integer number."),
     "KCHVOL0021E": _("Storage volume URL must be http://, https://, ftp:// or ftps://."),
+    "KCHVOL0022E": _("Unable to access file %(url)s. Please, check it."),
 
     "KCHIFACE0001E": _("Interface %(name)s does not exist"),
 
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index ac6887a..58730ea 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -67,6 +67,14 @@ class StorageVolumesModel(object):
 
         create_param = vol_source[index_list[0]]
 
+        # Verify if the URL is valid
+        if create_param ==  'url':
+            url = params['url']
+            try:
+                urllib2.urlopen(url)
+            except:
+                raise InvalidParameter('KCHVOL0022E', {'url': url})
+
         if name is None:
             # the methods listed in 'REQUIRE_NAME_PARAMS' cannot have
             # 'name' == None
-- 
1.9.3




More information about the Kimchi-devel mailing list