From 51a95d00e394e4403bceedf2fe5a6762a421e504 Mon Sep 17 00:00:00 2001 From: Helga Velroyen Date: Fri, 24 May 2013 13:10:02 +0200 Subject: [PATCH 1/1] hv_xen._GetCommand: retrieve xen command from hvparams 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 Reviewed-by: Thomas Thrainer --- lib/hypervisor/hv_xen.py | 13 ++++++++++--- test/py/ganeti.hypervisor.hv_xen_unittest.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 3366d49..b7a7578 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -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 diff --git a/test/py/ganeti.hypervisor.hv_xen_unittest.py b/test/py/ganeti.hypervisor.hv_xen_unittest.py index 875fee6..9cc6575 100755 --- a/test/py/ganeti.hypervisor.hv_xen_unittest.py +++ b/test/py/ganeti.hypervisor.hv_xen_unittest.py @@ -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): -- 1.7.10.4