Commit 4f7e5a1d authored by Bernardo Dal Seno's avatar Bernardo Dal Seno
Browse files

Fix upgrade of policy in objects.Cluster

Unknown elements were silently removed on startup. This means that a
software upgrade could result in lost configuration information if
cfgupgrade wasn't run promptly.

Added unit test for Cluster.UpgradeConfig() to cover this case.
Signed-off-by: default avatarBernardo Dal Seno <>
Reviewed-by: default avatarGuido Trotter <>
parent 2477c1c5
......@@ -1616,6 +1616,12 @@ class Cluster(TaggableObject):
# we can either make sure to upgrade the ipolicy always, or only
# do it in some corner cases (e.g. missing keys); note that this
# will break any removal of keys from the ipolicy dict
wrongkeys = frozenset(self.ipolicy.keys()) - constants.IPOLICY_ALL_KEYS
if wrongkeys:
# These keys would be silently removed by FillIPolicy()
msg = ("Cluster instance policy contains spourious keys: %s" %
raise errors.ConfigurationError(msg)
self.ipolicy = FillIPolicy(constants.IPOLICY_DEFAULTS, self.ipolicy)
......@@ -215,6 +215,13 @@ class TestClusterObject(unittest.TestCase):
self.fake_cl.enabled_hypervisors = sorted(constants.HYPER_TYPES)
self.assertEqual(self.fake_cl.primary_hypervisor, constants.HT_CHROOT)
def testUpgradeConfig(self):
# FIXME: This test is incomplete
cluster = objects.Cluster()
cluster = objects.Cluster(ipolicy={"unknown_key": None})
self.assertRaises(errors.ConfigurationError, cluster.UpgradeConfig)
class TestOS(unittest.TestCase):
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