From a002ed795e14572d8f06c7ecca3805a4fb6b2b5e Mon Sep 17 00:00:00 2001 From: Agata Murawska <agatamurawska@google.com> Date: Thu, 20 Oct 2011 12:20:02 +0200 Subject: [PATCH] Check for qemu-img in configure and Makefile Signed-off-by: Agata Murawska <agatamurawska@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- Makefile.am | 1 + configure.ac | 8 ++++++++ lib/constants.py | 3 +++ lib/ovf.py | 12 ++++++++++++ 4 files changed, 24 insertions(+) diff --git a/Makefile.am b/Makefile.am index 98d8a4f9e..fd31cd313 100644 --- a/Makefile.am +++ b/Makefile.am @@ -985,6 +985,7 @@ lib/_autoconf.py: Makefile | lib/.dir echo "NODED_USER = '$(NODED_USER)'"; \ echo "NODED_GROUP = '$(NODED_GROUP)'"; \ echo "DISK_SEPARATOR = '$(DISK_SEPARATOR)'"; \ + echo "QEMUIMG_PATH = '$(QEMUIMG_PATH)'"; \ if [ "$(HTOOLS)" ]; then \ echo "HTOOLS = True"; \ else \ diff --git a/configure.ac b/configure.ac index 52587437a..6d47a54ba 100644 --- a/configure.ac +++ b/configure.ac @@ -335,6 +335,14 @@ fi if test "$enable_htools" != "no"; then +# Check for qemu-img +AC_ARG_VAR(QEMUIMG_PATH, [qemu-img path]) +AC_PATH_PROG(QEMUIMG_PATH, [qemu-img], []) +if test -z "$QEMUIMG_PATH" +then + AC_MSG_WARN([qemu-img not found, using ovfconverter will not be possible]) +fi + # Check for ghc AC_ARG_VAR(GHC, [ghc path]) AC_PATH_PROG(GHC, [ghc], []) diff --git a/lib/constants.py b/lib/constants.py index 003774c58..18c3f4d03 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -1700,6 +1700,9 @@ VALID_ALLOC_POLICIES = [ # Temporary external/shared storage parameters BLOCKDEV_DRIVER_MANUAL = "manual" +# qemu-img path, required for ovfconverter +QEMUIMG_PATH = _autoconf.QEMUIMG_PATH + # Whether htools was enabled at compilation time HTOOLS = _autoconf.HTOOLS # The hail iallocator diff --git a/lib/ovf.py b/lib/ovf.py index eabc71a8e..ac0a70969 100644 --- a/lib/ovf.py +++ b/lib/ovf.py @@ -143,6 +143,15 @@ DISK_FORMAT = { COW: "http://www.gnome.org/~markmc/qcow-image-format.html", } +def CheckQemuImg(): + """ Make sure that qemu-img is present before performing operations. + + @raise errors.OpPrereqError: when qemu-img was not found in the system + + """ + if not constants.QEMUIMG_PATH: + raise errors.OpPrereqError("qemu-img not found at build time, unable" + " to continue") def LinkFile(old_path, prefix=None, suffix=None, directory=None): """Create link with a given prefix and suffix. @@ -916,6 +925,7 @@ class Converter(object): @raise errors.OpPrereqError: convertion of the disk failed """ + CheckQemuImg() disk_file = os.path.basename(disk_path) (disk_name, disk_extension) = os.path.splitext(disk_file) if disk_extension != disk_format: @@ -953,6 +963,7 @@ class Converter(object): @raise errors.OpPrereqError: format information cannot be retrieved """ + CheckQemuImg() args = ["qemu-img", "info", disk_path] run_result = utils.RunCmd(args, cwd=os.getcwd()) if run_result.failed: @@ -1317,6 +1328,7 @@ class OVFImporter(Converter): information or size information is invalid or creation failed """ + CheckQemuImg() assert self.options.disks results = {} for (disk_id, disk_desc) in self.options.disks: -- GitLab