From 440351f888dea59762e95702a0d3bd24ac14b8ce Mon Sep 17 00:00:00 2001
From: Andrea Spadaccini <spadaccio@google.com>
Date: Tue, 9 Aug 2011 12:16:49 +0100
Subject: [PATCH] Removed code duplication for calls to _GetKVMVersion

Signed-off-by: Andrea Spadaccini <spadaccio@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/hypervisor/hv_kvm.py | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index 8373b4009..f03dfecfb 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -518,11 +518,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     """Generate KVM information to start an instance.
 
     """
-    kvm_version = self._GetKVMVersion()
-    if kvm_version:
-      _, v_major, v_min, _ = kvm_version
-    else:
-      raise errors.HypervisorError("Unable to get KVM version")
+    _, v_major, v_min, _ = self._GetKVMVersion()
 
     pidfile  = self._InstancePidFile(instance.name)
     kvm = constants.KVM_PATH
@@ -816,11 +812,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     kvm_cmd, kvm_nics, up_hvp = kvm_runtime
     up_hvp = objects.FillDict(conf_hvp, up_hvp)
 
-    kvm_version = self._GetKVMVersion()
-    if kvm_version:
-      _, v_major, v_min, _ = kvm_version
-    else:
-      raise errors.HypervisorError("Unable to get KVM version")
+    _, v_major, v_min, _ = self._GetKVMVersion()
 
     # We know it's safe to run as a different user upon migration, so we'll use
     # the latest conf, from conf_hvp.
@@ -962,15 +954,16 @@ class KVMHypervisor(hv_base.BaseHypervisor):
   def _GetKVMVersion(cls):
     """Return the installed KVM version
 
-    @return: (version, v_maj, v_min, v_rev), or None
+    @return: (version, v_maj, v_min, v_rev)
+    @raise: L{errors.HypervisorError}
 
     """
     result = utils.RunCmd([constants.KVM_PATH, "--help"])
     if result.failed:
-      return None
+      raise errors.HypervisorError("Unable to get KVM version")
     match = cls._VERSION_RE.search(result.output.splitlines()[0])
     if not match:
-      return None
+      raise errors.HypervisorError("Unable to get KVM version")
 
     return (match.group(0), int(match.group(1)), int(match.group(2)),
             int(match.group(3)))
-- 
GitLab