Revision 664b392d test/py/ganeti.hypervisor.hv_xen_unittest.py
b/test/py/ganeti.hypervisor.hv_xen_unittest.py | ||
---|---|---|
483 | 483 |
extra = inst.hvparams[constants.HV_KERNEL_ARGS] |
484 | 484 |
self.assertTrue(("extra = '%s'" % extra) in lines) |
485 | 485 |
|
486 |
def _StopInstanceCommand(self, instance_name, force, fail, cmd): |
|
487 |
if ((force and cmd[:2] == [self.CMD, "destroy"]) or |
|
488 |
(not force and cmd[:2] == [self.CMD, "shutdown"])): |
|
489 |
self.assertEqual(cmd[2:], [instance_name]) |
|
490 |
output = "" |
|
491 |
else: |
|
492 |
self.fail("Unhandled command: %s" % (cmd, )) |
|
493 |
|
|
494 |
if fail: |
|
495 |
# Simulate a failing command |
|
496 |
return self._FailingCommand(cmd) |
|
497 |
else: |
|
498 |
return self._SuccessCommand(output, cmd) |
|
499 |
|
|
500 |
def testStopInstance(self): |
|
501 |
name = "inst4284.example.com" |
|
502 |
cfgfile = utils.PathJoin(self.tmpdir, name) |
|
503 |
cfgdata = "config file content\n" |
|
504 |
|
|
505 |
for force in [False, True]: |
|
506 |
for fail in [False, True]: |
|
507 |
utils.WriteFile(cfgfile, data=cfgdata) |
|
508 |
|
|
509 |
run_cmd = compat.partial(self._StopInstanceCommand, name, force, fail) |
|
510 |
|
|
511 |
hv = self._GetHv(run_cmd=run_cmd) |
|
512 |
|
|
513 |
self.assertTrue(os.path.isfile(cfgfile)) |
|
514 |
|
|
515 |
if fail: |
|
516 |
try: |
|
517 |
hv._StopInstance(name, force) |
|
518 |
except errors.HypervisorError, err: |
|
519 |
self.assertTrue(str(err).startswith("Failed to stop instance")) |
|
520 |
else: |
|
521 |
self.fail("Exception was not raised") |
|
522 |
self.assertEqual(utils.ReadFile(cfgfile), cfgdata, |
|
523 |
msg=("Configuration was removed when stopping" |
|
524 |
" instance failed")) |
|
525 |
else: |
|
526 |
hv._StopInstance(name, force) |
|
527 |
self.assertFalse(os.path.exists(cfgfile)) |
|
528 |
|
|
486 | 529 |
|
487 | 530 |
def _MakeTestClass(cls, cmd): |
488 | 531 |
"""Makes a class for testing. |
Also available in: Unified diff