hv_xen._GetCommand: retrieve xen command from hvparams
authorHelga Velroyen <helgav@google.com>
Fri, 24 May 2013 11:10:02 +0000 (13:10 +0200)
committerHelga Velroyen <helgav@google.com>
Wed, 12 Jun 2013 07:17:05 +0000 (09:17 +0200)
This patch adds a (so far optional) hvparams parameter
to the '_GetCommand' function. This dictionary is used
to retrieve the xen command (xm or xl). It is optional
for now to make the refactoring possible without breaking
everything at once.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/hypervisor/hv_xen.py
test/py/ganeti.hypervisor.hv_xen_unittest.py

index 3366d49..b7a7578 100644 (file)
@@ -335,13 +335,20 @@ class XenHypervisor(hv_base.BaseHypervisor):
 
     self._cmd = _cmd
 
-  def _GetCommand(self):
+  def _GetCommand(self, hvparams=None):
     """Returns Xen command to use.
 
+    @type hvparams: dict of strings
+    @param hvparams: hypervisor parameters
+
     """
     if self._cmd is None:
-      # TODO: Make command a hypervisor parameter
-      cmd = constants.XEN_CMD
+      if hvparams is not None:
+        cmd = hvparams[constants.HV_XEN_CMD]
+      else:
+        # TODO: Remove autoconf option once retrieving the command from
+        # the hvparams is fully implemented.
+        cmd = constants.XEN_CMD
     else:
       cmd = self._cmd
 
index 875fee6..9cc6575 100755 (executable)
@@ -97,6 +97,22 @@ class TestGetCommand(testutils.GanetiTestCase):
     hv = hv_xen.XenHypervisor(_cmd="invalidcommand")
     self.assertRaises(errors.ProgrammerError, hv._GetCommand, None)
 
+  def testCommandHvparams(self):
+    expected_cmd = "xl"
+    test_hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL}
+    hv = hv_xen.XenHypervisor()
+    self.assertEqual(hv._GetCommand(hvparams=test_hvparams), expected_cmd)
+
+  def testCommandHvparamsInvalid(self):
+    test_hvparams = {}
+    hv = hv_xen.XenHypervisor()
+    self.assertRaises(KeyError, hv._GetCommand, test_hvparams)
+
+  def testCommandHvparamsCmdInvalid(self):
+    test_hvparams = {constants.HV_XEN_CMD: "invalidcommand"}
+    hv = hv_xen.XenHypervisor()
+    self.assertRaises(errors.ProgrammerError, hv._GetCommand, test_hvparams)
+
 
 class TestParseXmList(testutils.GanetiTestCase):
   def test(self):