Revision 398fd4f6 test/py/ganeti.hypervisor.hv_xen_unittest.py
b/test/py/ganeti.hypervisor.hv_xen_unittest.py | ||
---|---|---|
78 | 78 |
|
79 | 79 |
|
80 | 80 |
class TestGetCommand(testutils.GanetiTestCase): |
81 |
def testDefault(self): |
|
82 |
expected_cmd = "xm" |
|
83 |
hv = hv_xen.XenHypervisor() |
|
84 |
self.assertEqual(hv._GetCommand(), expected_cmd) |
|
85 |
|
|
86 | 81 |
def testCommandExplicit(self): |
87 | 82 |
"""Test the case when the command is given as class parameter explicitly. |
88 | 83 |
|
89 | 84 |
""" |
90 | 85 |
expected_cmd = "xl" |
91 | 86 |
hv = hv_xen.XenHypervisor(_cmd=constants.XEN_CMD_XL) |
92 |
self.assertEqual(hv._GetCommand(), expected_cmd) |
|
87 |
self.assertEqual(hv._GetCommand(None), expected_cmd)
|
|
93 | 88 |
|
94 | 89 |
def testCommandInvalid(self): |
95 | 90 |
"""Test the case an invalid command is given as class parameter explicitly. |
... | ... | |
102 | 97 |
expected_cmd = "xl" |
103 | 98 |
test_hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL} |
104 | 99 |
hv = hv_xen.XenHypervisor() |
105 |
self.assertEqual(hv._GetCommand(hvparams=test_hvparams), expected_cmd)
|
|
100 |
self.assertEqual(hv._GetCommand(test_hvparams), expected_cmd) |
|
106 | 101 |
|
107 | 102 |
def testCommandHvparamsInvalid(self): |
108 | 103 |
test_hvparams = {} |
109 | 104 |
hv = hv_xen.XenHypervisor() |
110 |
self.assertRaises(KeyError, hv._GetCommand, test_hvparams)
|
|
105 |
self.assertRaises(errors.HypervisorError, hv._GetCommand, test_hvparams)
|
|
111 | 106 |
|
112 | 107 |
def testCommandHvparamsCmdInvalid(self): |
113 | 108 |
test_hvparams = {constants.HV_XEN_CMD: "invalidcommand"} |
... | ... | |
347 | 342 |
hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented, |
348 | 343 |
_run_cmd_fn=NotImplemented, |
349 | 344 |
_cmd=cmd) |
350 |
self.assertRaises(errors.ProgrammerError, hv._RunXen, []) |
|
345 |
self.assertRaises(errors.ProgrammerError, hv._RunXen, [], None)
|
|
351 | 346 |
|
352 |
def testCommandValid(self): |
|
353 |
xen_cmd = "xm" |
|
354 |
mock_run_cmd = mock.Mock() |
|
347 |
def testCommandNoHvparams(self): |
|
355 | 348 |
hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented, |
356 |
_run_cmd_fn=mock_run_cmd) |
|
357 |
hv._RunXen([self.XEN_SUB_CMD]) |
|
358 |
mock_run_cmd.assert_called_with([xen_cmd, self.XEN_SUB_CMD]) |
|
349 |
_run_cmd_fn=NotImplemented) |
|
350 |
hvparams = None |
|
351 |
self.assertRaises(errors.HypervisorError, hv._RunXen, [self.XEN_SUB_CMD], |
|
352 |
hvparams) |
|
359 | 353 |
|
360 | 354 |
def testCommandFromHvparams(self): |
361 | 355 |
expected_xen_cmd = "xl" |
... | ... | |
372 | 366 |
RESULT_OK = utils.RunResult(0, None, "", "", "", None, None) |
373 | 367 |
XEN_LIST = "list" |
374 | 368 |
|
375 |
def testOk(self):
|
|
369 |
def testNoHvparams(self):
|
|
376 | 370 |
expected_xen_cmd = "xm" |
377 | 371 |
mock_run_cmd = mock.Mock( return_value=self.RESULT_OK ) |
378 | 372 |
hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented, |
379 | 373 |
_run_cmd_fn=mock_run_cmd) |
380 |
hv._GetInstanceList(True) |
|
381 |
mock_run_cmd.assert_called_with([expected_xen_cmd, self.XEN_LIST]) |
|
374 |
self.assertRaises(errors.HypervisorError, hv._GetInstanceList, True, None) |
|
382 | 375 |
|
383 | 376 |
def testFromHvparams(self): |
384 | 377 |
expected_xen_cmd = "xl" |
... | ... | |
386 | 379 |
mock_run_cmd = mock.Mock( return_value=self.RESULT_OK ) |
387 | 380 |
hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented, |
388 | 381 |
_run_cmd_fn=mock_run_cmd) |
389 |
hv._GetInstanceList(True, hvparams=hvparams)
|
|
382 |
hv._GetInstanceList(True, hvparams) |
|
390 | 383 |
mock_run_cmd.assert_called_with([expected_xen_cmd, self.XEN_LIST]) |
391 | 384 |
|
392 | 385 |
|
... | ... | |
395 | 388 |
RESULT_OK = utils.RunResult(0, None, "", "", "", None, None) |
396 | 389 |
XEN_LIST = "list" |
397 | 390 |
|
398 |
def testDefaultXm(self):
|
|
391 |
def testNoHvparams(self):
|
|
399 | 392 |
expected_xen_cmd = "xm" |
400 | 393 |
mock_run_cmd = mock.Mock( return_value=self.RESULT_OK ) |
401 | 394 |
hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented, |
402 | 395 |
_run_cmd_fn=mock_run_cmd) |
403 |
hv.ListInstances() |
|
404 |
mock_run_cmd.assert_called_with([expected_xen_cmd, self.XEN_LIST]) |
|
396 |
self.assertRaises(errors.HypervisorError, hv.ListInstances) |
|
405 | 397 |
|
406 | 398 |
def testHvparamsXl(self): |
407 | 399 |
expected_xen_cmd = "xl" |
Also available in: Unified diff