diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 2752592a6b95980b62f9c1b26350b66fba70aaf4..c601c441e4233b0766cf2c757069b4c806e8ebaa 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -541,6 +541,7 @@ class LUInitCluster(LogicalUnit): ss.SetKey(ss.SS_MASTER_NETDEV, self.op.master_netdev) ss.SetKey(ss.SS_CLUSTER_NAME, clustername.name) ss.SetKey(ss.SS_FILE_STORAGE_DIR, self.op.file_storage_dir) + ss.SetKey(ss.SS_CONFIG_VERSION, constants.CONFIG_VERSION) # set up the inter-node password and certificate _InitGanetiServerSetup(ss) diff --git a/lib/config.py b/lib/config.py index 9180b33340127c90fda9b2d7d721b159c4bab4da..bf06d4849e81081026e74661d8763fc8dfd97d50 100644 --- a/lib/config.py +++ b/lib/config.py @@ -43,6 +43,17 @@ from ganeti import constants from ganeti import rpc from ganeti import objects from ganeti import serializer +from ganeti import ssconf + + +def ValidateConfig(): + sstore = ssconf.SimpleStore() + + if sstore.GetConfigVersion() != constants.CONFIG_VERSION: + raise errors.ConfigurationError("Cluster configuration version" + " mismatch, got %s instead of %s" % + (sstore.GetConfigVersion(), + constants.CONFIG_VERSION)) class ConfigWriter: @@ -505,6 +516,10 @@ class ConfigWriter: self._config_inode == st.st_ino): # data is current, so skip loading of config file return + + # Make sure the configuration has the right version + ValidateConfig() + f = open(self._cfg_file, 'r') try: try: @@ -514,14 +529,9 @@ class ConfigWriter: finally: f.close() if (not hasattr(data, 'cluster') or - not hasattr(data.cluster, 'config_version')): + not hasattr(data.cluster, 'rsahostkeypub')): raise errors.ConfigurationError("Incomplete configuration" - " (missing cluster.config_version)") - if data.cluster.config_version != constants.CONFIG_VERSION: - raise errors.ConfigurationError("Cluster configuration version" - " mismatch, got %s instead of %s" % - (data.cluster.config_version, - constants.CONFIG_VERSION)) + " (missing cluster.rsahostkeypub)") self._config_data = data self._config_time = st.st_mtime self._config_size = st.st_size @@ -602,8 +612,7 @@ class ConfigWriter: """ hu_port = constants.FIRST_DRBD_PORT - 1 - globalconfig = objects.Cluster(config_version=constants.CONFIG_VERSION, - serial_no=1, + globalconfig = objects.Cluster(serial_no=1, rsahostkeypub=hostkeypub, highest_used_port=hu_port, mac_prefix=mac_prefix, diff --git a/lib/constants.py b/lib/constants.py index 907f6171255b60d75c37c63293ae499e3cfbc7f1..0f68b2fb48399c38f1c1df293bf677a9fd99f2c3 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -24,12 +24,27 @@ from ganeti import _autoconf # various versions -CONFIG_VERSION = 3 PROTOCOL_VERSION = 12 RELEASE_VERSION = _autoconf.PACKAGE_VERSION OS_API_VERSION = 5 EXPORT_VERSION = 0 +# Format for CONFIG_VERSION: +# 01 03 0123 = 01030123 +# ^^ ^^ ^^^^ +# | | + Configuration version/revision +# | + Minor version +# + Major version +# +# It stored as an integer. Make sure not to write an octal number. +# +CONFIG_MAJOR = int(_autoconf.VERSION_MAJOR) +CONFIG_MINOR = int(_autoconf.VERSION_MINOR) +CONFIG_REVISION = 0 +CONFIG_VERSION = ( + 1000000 * CONFIG_MAJOR + + 10000 * CONFIG_MINOR + + 1 * CONFIG_REVISION) # file paths DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"