[Kimchi-devel] [PATCH V2] [Kimchi] Handle URLError exception when creating Template.

pvital at linux.vnet.ibm.com pvital at linux.vnet.ibm.com
Tue Jun 21 20:05:27 UTC 2016


From: Paulo Vital <pvital at linux.vnet.ibm.com>

urllib2 raised URLError when could not access a remote file due to unauthorized
access, for example. This patch gives to IsoImage the ability to handle this
exception and raises a relevant error message to user.

This patch fixes Issue #959

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 i18n.py    |  1 +
 isoinfo.py | 15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/i18n.py b/i18n.py
index 2d8390f..b33c6ec 100644
--- a/i18n.py
+++ b/i18n.py
@@ -52,6 +52,7 @@ messages = {
                      "to file access control lists for '%(user)s' user if possible, or add the "
                      "'%(user)s' to the ISO path group, or (not recommended) 'chmod -R o+x 'path_to_iso'."
                      "Details: %(err)s" ),
+    "KCHISO0009E": _("Unable to access remote ISO. Details: %(err)s"),

     "KCHIMG0001E": _("An error occurred when probing image OS information."),
     "KCHIMG0003E": _("Unable to read image file %(filename)s"),
diff --git a/isoinfo.py b/isoinfo.py
index 4cb0209..7c000b7 100644
--- a/isoinfo.py
+++ b/isoinfo.py
@@ -28,7 +28,7 @@ import sys
 import urllib2


-from wok.exception import IsoFormatError
+from wok.exception import IsoFormatError, OperationFailed
 from wok.plugins.kimchi.utils import check_url_path
 from wok.utils import wok_log

@@ -419,11 +419,14 @@ lang=en#!/wiki/W51a7ffcf4dfd_4b40_9d82_446ebc23c550/page/PowerLinux\

     def _get_iso_data(self, offset, size):
         if self.remote:
-            request = urllib2.Request(self.path)
-            range_header = "bytes=%d-%d" % (offset, offset + size - 1)
-            request.add_header("range", range_header)
-            with contextlib.closing(urllib2.urlopen(request)) as response:
-                data = response.read()
+            try:
+                request = urllib2.Request(self.path)
+                range_header = "bytes=%d-%d" % (offset, offset + size - 1)
+                request.add_header("range", range_header)
+                with contextlib.closing(urllib2.urlopen(request)) as response:
+                    data = response.read()
+            except urllib2.URLError as e:
+                raise OperationFailed("KCHISO0009E", {'err': e})
         else:
             with open(self.path) as fd:
                 fd.seek(offset)
--
2.5.5




More information about the Kimchi-devel mailing list