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 that - the DATA_DIR, if present, only contains directory entries, and - the QUEUE_DIR, if present, is empty.
Signed-off-by: Klaus Aehlig <[email protected]> --- lib/bootstrap.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index e5da02b..0140916 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -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", errors.ECODE_STATE) + 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), + errors.ECODE_STATE) + + 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, + errors.ECODE_STATE) + if not enabled_hypervisors: raise errors.OpPrereqError("Enabled hypervisors list must contain at" " least one member", errors.ECODE_INVAL) -- 2.1.0.rc2.206.gedb03e5
