Commit 9dae41ad authored by Guido Trotter's avatar Guido Trotter

Create runtime dir in bootstrap

Some hypervisors (KVM) need RUN_GANETI_DIR to exist even at cluster init
time. This patch creates it in InitCluster just before hv parameter
checking. Since the code to make list of directories is already repeated
twice in the code, and this would be the third time, we abstract it into
an utils.EnsureDirs function and we call that one from ganti-noded,
ganeti-masterd and bootstrap.

Reviewed-by: iustinp
parent cc9e1230
......@@ -463,15 +463,7 @@ def main():
dirs = [(constants.RUN_GANETI_DIR, constants.RUN_DIRS_MODE),
(constants.SOCKET_DIR, constants.SOCKET_DIR_MODE),
]
for dir_name, mode in dirs:
try:
os.mkdir(dir_name, mode)
except EnvironmentError, err:
if err.errno != errno.EEXIST:
raise errors.GenericError("Cannot create needed directory"
" '%s': %s" % (constants.SOCKET_DIR, err))
if not os.path.isdir(dir_name):
raise errors.GenericError("%s is not a directory" % dir_name)
utils.EnsureDirs(dirs)
# This is safe to do as the pid file guarantees against
# concurrent execution.
......
......@@ -735,31 +735,6 @@ def ParseOptions():
return options, args
def EnsureRuntimeEnvironment():
"""Ensure our run-time environment is complete.
Currently this creates directories which could be missing, either
due to directories being on a tmpfs mount, or due to incomplete
packaging.
"""
dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
dirs.append((constants.LOG_OS_DIR, 0750))
dirs.append((constants.LOCK_DIR, 1777))
for dir_name, dir_mode in dirs:
if not os.path.exists(dir_name):
try:
os.mkdir(dir_name, dir_mode)
except EnvironmentError, err:
if err.errno != errno.EEXIST:
print ("Node setup wrong, cannot create directory '%s': %s" %
(dir_name, err))
sys.exit(5)
if not os.path.isdir(dir_name):
print ("Node setup wrong, '%s' is not a directory" % dir_name)
sys.exit(5)
def main():
"""Main function for the node daemon.
......@@ -783,7 +758,10 @@ def main():
print "Cluster configuration incomplete: '%s'" % str(err)
sys.exit(5)
EnsureRuntimeEnvironment()
dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
dirs.append((constants.LOG_OS_DIR, 0750))
dirs.append((constants.LOCK_DIR, 1777))
utils.EnsureDirs(dirs)
# become a daemon
if options.fork:
......
......@@ -205,6 +205,9 @@ def InitCluster(cluster_name, mac_prefix, def_bridge,
raise errors.OpPrereqError("Init.d script '%s' missing or not"
" executable." % constants.NODE_INITD_SCRIPT)
dirs = [(constants.RUN_GANETI_DIR, constants.RUN_DIRS_MODE)]
utils.EnsureDirs(dirs)
utils.ForceDictType(beparams, constants.BES_PARAMETER_TYPES)
# hvparams is a mapping of hypervisor->hvparams dict
for hv_name, hv_params in hvparams.iteritems():
......
......@@ -1182,6 +1182,24 @@ def GenerateSecret():
return sha.new(os.urandom(64)).hexdigest()
def EnsureDirs(dirs):
"""Make required directories, if they don't exist.
@param dirs: list of tuples (dir_name, dir_mode)
@type dirs: list of (string, integer)
"""
for dir_name, dir_mode in dirs:
try:
os.mkdir(dir_name, mode)
except EnvironmentError, err:
if err.errno != errno.EEXIST:
raise errors.GenericError("Cannot create needed directory"
" '%s': %s" % (dir_name, err))
if not os.path.isdir(dir_name):
raise errors.GenericError("%s is not a directory" % dir_name)
def ReadFile(file_name, size=None):
"""Reads a file.
......
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