Commit 3a805689 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Verify clean DATA_DIR on cluster init

A new Ganeti cluster should not inherit state from a previously existing
cluster. Therefore, on cluster initialization, verify that no dangerous
left-overs are present in the DATA_DIR. We cannot, however, insist on
the DATA_DIR being completely empty, as it is good practice to set up
the rapi user file ahead of time. What we therefore do is to verify
- the DATA_DIR, if present, only contains directory entries, and
- the QUEUE_DIR, if present, is empty.
Signed-off-by: default avatarKlaus Aehlig <>
Reviewed-by: default avatarPetr Pudlak <>
parent 3076e05c
......@@ -48,6 +48,7 @@ from ganeti import luxi
from ganeti import jstore
from ganeti import pathutils
from ganeti import runtime
from ganeti import vcluster
# ec_id for InitConfig's temporary reservation manager
......@@ -574,6 +575,22 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
raise errors.OpPrereqError("Cluster is already initialised",
data_dir = vcluster.AddNodePrefix(pathutils.DATA_DIR)
if os.path.isdir(data_dir):
for entry in os.listdir(data_dir):
if not os.path.isdir(os.path.join(data_dir, entry)):
raise errors.OpPrereqError(
"%s contains non-directory enries like %s. Remove left-overs of an"
" old cluster before initialising a new one" % (data_dir, entry),
queue_dir = vcluster.AddNodePrefix(pathutils.QUEUE_DIR)
if os.path.isdir(queue_dir) and os.listdir(queue_dir):
raise errors.OpPrereqError(
"%s not empty. Remove left-overs of an old cluster before initialising"
" a new one" % queue_dir,
if not enabled_hypervisors:
raise errors.OpPrereqError("Enabled hypervisors list must contain at"
" least one member", errors.ECODE_INVAL)
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