Commit 48bba9de authored by Balazs Lecz's avatar Balazs Lecz
Browse files

Stash Xen config file after a failed startup

This is a fix for a minor bug.
Currently, a failed Xen VM start results in a stale config file left
behind on the filesystem.
This change introduces a new log directory, where the Xen VM config
file is moved after a failed startup.
Signed-off-by: default avatarBalazs Lecz <>
Reviewed-by: default avatarGuido Trotter <>
parent a365b47f
......@@ -414,6 +414,17 @@ class XenHypervisor(hv_base.BaseHypervisor):
def _StashConfigFile(self, instance_name):
"""Move the Xen config file to the log directory and return its new path.
old_filename = self._ConfigFileName(instance_name)
base = ("%s-%s" %
(instance_name, utils.TimestampForFilename()))
new_filename = utils.PathJoin(pathutils.LOG_XEN_DIR, base)
utils.RenameFile(old_filename, new_filename)
return new_filename
def _GetXmList(self, include_node):
"""Wrapper around module level L{_GetXmList}.
......@@ -482,9 +493,13 @@ class XenHypervisor(hv_base.BaseHypervisor):
result = self._RunXen(cmd)
if result.failed:
raise errors.HypervisorError("Failed to start instance %s: %s (%s)" %
# Move the Xen configuration file to the log directory to avoid
# leaving a stale config file behind.
stashed_config = self._StashConfigFile(
raise errors.HypervisorError("Failed to start instance %s: %s (%s). Moved"
" config file to %s" %
(, result.fail_reason,
result.output, stashed_config))
def StopInstance(self, instance, force=False, retry=False, name=None):
"""Stop an instance.
......@@ -133,6 +133,8 @@ QUERY_SOCKET = SOCKET_DIR + "/ganeti-query"
LOG_OS_DIR = LOG_DIR + "/os"
LOG_ES_DIR = LOG_DIR + "/extstorage"
#: Directory for storing Xen config files after failed instance starts
LOG_XEN_DIR = LOG_DIR + "/xen"
# Job queue paths
......@@ -195,6 +195,7 @@ def GetPaths():
(noded_log, FILE, 0600, getent.noded_uid, getent.masterd_gid, False),
(rapi_log, FILE, 0600, getent.rapi_uid, getent.masterd_gid, False),
(pathutils.LOG_OS_DIR, DIR, 0750, getent.masterd_uid, getent.daemons_gid),
(pathutils.LOG_XEN_DIR, DIR, 0750, getent.noded_uid, getent.daemons_gid),
(cleaner_log_dir, DIR, 0750, getent.noded_uid, getent.noded_gid),
(master_cleaner_log_dir, DIR, 0750, getent.masterd_uid, getent.masterd_gid),
(pathutils.INSTANCE_REASON_DIR, DIR, 0755, getent.noded_uid,
......@@ -30,6 +30,7 @@ import os
from ganeti import constants
from ganeti import objects
from ganeti import pathutils
from ganeti import hypervisor
from ganeti import utils
from ganeti import errors
......@@ -491,7 +492,6 @@ class _TestXenHypervisor(object):"Unhandled command: %s" % (cmd, ))
return self._SuccessCommand(output, cmd)
#return self._FailingCommand(cmd)
def _MakeInstance(self):
# Copy default parameters
......@@ -519,6 +519,7 @@ class _TestXenHypervisor(object):
def testStartInstance(self):
(inst, disks) = self._MakeInstance()
pathutils.LOG_XEN_DIR = self.tmpdir
for failcreate in [False, True]:
for paused in [False, True]:
......@@ -537,11 +538,12 @@ class _TestXenHypervisor(object):
if failcreate:
self.assertRaises(errors.HypervisorError, hv.StartInstance,
inst, disks, paused)
# Check whether a stale config file is left behind
hv.StartInstance(inst, disks, paused)
# Check if configuration was updated
lines = utils.ReadFile(cfgfile).splitlines()
# Check if configuration was updated
lines = utils.ReadFile(cfgfile).splitlines()
if constants.HV_VNC_PASSWORD_FILE in inst.hvparams:
self.assertTrue(("vncpasswd = '%s'" % self.vncpw) in lines)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment