[Kimchi-devel] [PATCH] [Kimchi 1/2] Modified code, to return distro and version as unknown, if guestfs import failed.

archus at linux.vnet.ibm.com archus at linux.vnet.ibm.com
Tue Aug 9 08:53:22 UTC 2016


From: Archana Singh <archus at linux.vnet.ibm.com>

guestfs is used to get the distro and version, if guestfs is not installed
distro and version returned as unknown.

Signed-off-by: Archana Singh <archus at linux.vnet.ibm.com>
---
 imageinfo.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/imageinfo.py b/imageinfo.py
index 8874917..30c08ae 100644
--- a/imageinfo.py
+++ b/imageinfo.py
@@ -17,7 +17,6 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
-import guestfs
 import json
 import os
 import sys
@@ -48,11 +47,14 @@ def probe_image(image_path):
     if not os.access(image_path, os.R_OK):
         raise ImageFormatError("KCHIMG0003E", {'filename': image_path})
 
-    g = guestfs.GuestFS(python_return_dict=True)
-    g.add_drive_opts(image_path, readonly=1)
-    g.launch()
     try:
+        import guestfs
+        g = guestfs.GuestFS(python_return_dict=True)
+        g.add_drive_opts(image_path, readonly=1)
+        g.launch()
         roots = g.inspect_os()
+    except ImportError:
+        return ("unknown", "unknown")
     except:
         raise ImageFormatError("KCHIMG0001E")
 
-- 
2.7.4




More information about the Kimchi-devel mailing list