[jenkins-ci PATCH] lcitool: check for virt-install existing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This improves:

  $ ./lcitool install libvirt-fedora-29
  ./lcitool: Failed to install 'libvirt-fedora-29': [Errno 2] No such file or directory

To

  $ ./lcitool install libvirt-fedora-29
  ./lcitool: Cannot find virt-install in $PATH

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 guests/lcitool | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/guests/lcitool b/guests/lcitool
index 0f60704..3be16c8 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -37,6 +37,23 @@ except ImportError:
 
 class Util:
 
+    @staticmethod
+    def which(program):
+        def is_exe(fpath):
+            return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+        fpath, fname = os.path.split(program)
+        if fpath:
+            if is_exe(program):
+                return program
+        else:
+            for path in os.environ["PATH"].split(os.pathsep):
+                exe_file = os.path.join(path, program)
+                if is_exe(exe_file):
+                    return exe_file
+
+        return None
+
     @staticmethod
     def get_base():
         return os.path.dirname(os.path.abspath(__file__))
@@ -534,8 +551,12 @@ class Application:
             # a kernel argument
             extra_arg = "console=ttyS0 ks=file:/{}".format(install_config)
 
+            vipath = Util.which("virt-install")
+            if vipath is None:
+                raise Exception("Cannot find virt-install in $PATH")
+
             cmd = [
-                "virt-install",
+                vipath,
                 "--name", host,
                 "--location", facts["install_url"],
                 "--virt-type", facts["install_virt_type"],
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux