Revision 48bba9de

b/lib/hypervisor/hv_xen.py
414 414
    """
415 415
    utils.RemoveFile(self._ConfigFileName(instance_name))
416 416

  
417
  def _StashConfigFile(self, instance_name):
418
    """Move the Xen config file to the log directory and return its new path.
419

  
420
    """
421
    old_filename = self._ConfigFileName(instance_name)
422
    base = ("%s-%s" %
423
            (instance_name, utils.TimestampForFilename()))
424
    new_filename = utils.PathJoin(pathutils.LOG_XEN_DIR, base)
425
    utils.RenameFile(old_filename, new_filename)
426
    return new_filename
427

  
417 428
  def _GetXmList(self, include_node):
418 429
    """Wrapper around module level L{_GetXmList}.
419 430

  
......
482 493

  
483 494
    result = self._RunXen(cmd)
484 495
    if result.failed:
485
      raise errors.HypervisorError("Failed to start instance %s: %s (%s)" %
496
      # Move the Xen configuration file to the log directory to avoid
497
      # leaving a stale config file behind.
498
      stashed_config = self._StashConfigFile(instance.name)
499
      raise errors.HypervisorError("Failed to start instance %s: %s (%s). Moved"
500
                                   " config file to %s" %
486 501
                                   (instance.name, result.fail_reason,
487
                                    result.output))
502
                                    result.output, stashed_config))
488 503

  
489 504
  def StopInstance(self, instance, force=False, retry=False, name=None):
490 505
    """Stop an instance.
b/lib/pathutils.py
133 133

  
134 134
LOG_OS_DIR = LOG_DIR + "/os"
135 135
LOG_ES_DIR = LOG_DIR + "/extstorage"
136
#: Directory for storing Xen config files after failed instance starts
137
LOG_XEN_DIR = LOG_DIR + "/xen"
136 138

  
137 139
# Job queue paths
138 140
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
b/lib/tools/ensure_dirs.py
195 195
    (noded_log, FILE, 0600, getent.noded_uid, getent.masterd_gid, False),
196 196
    (rapi_log, FILE, 0600, getent.rapi_uid, getent.masterd_gid, False),
197 197
    (pathutils.LOG_OS_DIR, DIR, 0750, getent.masterd_uid, getent.daemons_gid),
198
    (pathutils.LOG_XEN_DIR, DIR, 0750, getent.noded_uid, getent.daemons_gid),
198 199
    (cleaner_log_dir, DIR, 0750, getent.noded_uid, getent.noded_gid),
199 200
    (master_cleaner_log_dir, DIR, 0750, getent.masterd_uid, getent.masterd_gid),
200 201
    (pathutils.INSTANCE_REASON_DIR, DIR, 0755, getent.noded_uid,
b/test/py/ganeti.hypervisor.hv_xen_unittest.py
30 30

  
31 31
from ganeti import constants
32 32
from ganeti import objects
33
from ganeti import pathutils
33 34
from ganeti import hypervisor
34 35
from ganeti import utils
35 36
from ganeti import errors
......
491 492
      self.fail("Unhandled command: %s" % (cmd, ))
492 493

  
493 494
    return self._SuccessCommand(output, cmd)
494
    #return self._FailingCommand(cmd)
495 495

  
496 496
  def _MakeInstance(self):
497 497
    # Copy default parameters
......
519 519

  
520 520
  def testStartInstance(self):
521 521
    (inst, disks) = self._MakeInstance()
522
    pathutils.LOG_XEN_DIR = self.tmpdir
522 523

  
523 524
    for failcreate in [False, True]:
524 525
      for paused in [False, True]:
......
537 538
        if failcreate:
538 539
          self.assertRaises(errors.HypervisorError, hv.StartInstance,
539 540
                            inst, disks, paused)
541
          # Check whether a stale config file is left behind
542
          self.assertFalse(os.path.exists(cfgfile))
540 543
        else:
541 544
          hv.StartInstance(inst, disks, paused)
542

  
543
        # Check if configuration was updated
544
        lines = utils.ReadFile(cfgfile).splitlines()
545
          # Check if configuration was updated
546
          lines = utils.ReadFile(cfgfile).splitlines()
545 547

  
546 548
        if constants.HV_VNC_PASSWORD_FILE in inst.hvparams:
547 549
          self.assertTrue(("vncpasswd = '%s'" % self.vncpw) in lines)

Also available in: Unified diff