Revision 396672cd
b/test/py/ganeti.hypervisor.hv_xen_unittest.py | ||
---|---|---|
403 | 403 |
hv = self._GetHv(run_cmd=self._FailingCommand) |
404 | 404 |
self.assertTrue("failed:" in hv.Verify()) |
405 | 405 |
|
406 |
def _StartInstanceCommand(self, inst, paused, failcreate, cmd): |
|
407 |
if cmd == [self.CMD, "info"]: |
|
408 |
output = testutils.ReadTestData("xen-xm-info-4.0.1.txt") |
|
409 |
elif cmd == [self.CMD, "list"]: |
|
410 |
output = testutils.ReadTestData("xen-xm-list-4.0.1-dom0-only.txt") |
|
411 |
elif cmd[:2] == [self.CMD, "create"]: |
|
412 |
args = cmd[2:] |
|
413 |
cfgfile = utils.PathJoin(self.tmpdir, inst.name) |
|
414 |
|
|
415 |
if paused: |
|
416 |
self.assertEqual(args, ["-p", cfgfile]) |
|
417 |
else: |
|
418 |
self.assertEqual(args, [cfgfile]) |
|
419 |
|
|
420 |
if failcreate: |
|
421 |
return self._FailingCommand(cmd) |
|
422 |
|
|
423 |
output = "" |
|
424 |
else: |
|
425 |
self.fail("Unhandled command: %s" % (cmd, )) |
|
426 |
|
|
427 |
return self._SuccessCommand(output, cmd) |
|
428 |
#return self._FailingCommand(cmd) |
|
429 |
|
|
430 |
def _MakeInstance(self): |
|
431 |
# Copy default parameters |
|
432 |
bep = objects.FillDict(constants.BEC_DEFAULTS, {}) |
|
433 |
hvp = objects.FillDict(constants.HVC_DEFAULTS[self.HVNAME], {}) |
|
434 |
|
|
435 |
# Override default VNC password file path |
|
436 |
if constants.HV_VNC_PASSWORD_FILE in hvp: |
|
437 |
hvp[constants.HV_VNC_PASSWORD_FILE] = self.vncpw_path |
|
438 |
|
|
439 |
disks = [ |
|
440 |
(objects.Disk(dev_type=constants.LD_LV, mode=constants.DISK_RDWR), |
|
441 |
utils.PathJoin(self.tmpdir, "disk0")), |
|
442 |
(objects.Disk(dev_type=constants.LD_LV, mode=constants.DISK_RDONLY), |
|
443 |
utils.PathJoin(self.tmpdir, "disk1")), |
|
444 |
] |
|
445 |
|
|
446 |
inst = objects.Instance(name="server01.example.com", |
|
447 |
hvparams=hvp, beparams=bep, |
|
448 |
osparams={}, nics=[], os="deb1", |
|
449 |
disks=map(compat.fst, disks)) |
|
450 |
inst.UpgradeConfig() |
|
451 |
|
|
452 |
return (inst, disks) |
|
453 |
|
|
454 |
def testStartInstance(self): |
|
455 |
(inst, disks) = self._MakeInstance() |
|
456 |
|
|
457 |
for failcreate in [False, True]: |
|
458 |
for paused in [False, True]: |
|
459 |
run_cmd = compat.partial(self._StartInstanceCommand, |
|
460 |
inst, paused, failcreate) |
|
461 |
|
|
462 |
hv = self._GetHv(run_cmd=run_cmd) |
|
463 |
|
|
464 |
# Ensure instance is not listed |
|
465 |
self.assertTrue(inst.name not in hv.ListInstances()) |
|
466 |
|
|
467 |
# Remove configuration |
|
468 |
cfgfile = utils.PathJoin(self.tmpdir, inst.name) |
|
469 |
utils.RemoveFile(cfgfile) |
|
470 |
|
|
471 |
if failcreate: |
|
472 |
self.assertRaises(errors.HypervisorError, hv.StartInstance, |
|
473 |
inst, disks, paused) |
|
474 |
else: |
|
475 |
hv.StartInstance(inst, disks, paused) |
|
476 |
|
|
477 |
# Check if configuration was updated |
|
478 |
lines = utils.ReadFile(cfgfile).splitlines() |
|
479 |
|
|
480 |
if constants.HV_VNC_PASSWORD_FILE in inst.hvparams: |
|
481 |
self.assertTrue(("vncpasswd = '%s'" % self.vncpw) in lines) |
|
482 |
else: |
|
483 |
extra = inst.hvparams[constants.HV_KERNEL_ARGS] |
|
484 |
self.assertTrue(("extra = '%s'" % extra) in lines) |
|
485 |
|
|
406 | 486 |
|
407 | 487 |
def _MakeTestClass(cls, cmd): |
408 | 488 |
"""Makes a class for testing. |
Also available in: Unified diff