Commit fa166f67 authored by Bernardo Dal Seno's avatar Bernardo Dal Seno
Browse files

Split functions in cfupgrade unit tests



This makes easier to test real configurations.
Signed-off-by: default avatarBernardo Dal Seno <bdalseno@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent e94fc80c
...@@ -156,6 +156,11 @@ class TestCfgupgrade(unittest.TestCase): ...@@ -156,6 +156,11 @@ class TestCfgupgrade(unittest.TestCase):
"instances": {}, "instances": {},
"nodegroups": {}, "nodegroups": {},
} }
self._TestUpgradeFromData(cfg, dry_run)
def _TestUpgradeFromData(self, cfg, dry_run):
assert "version" in cfg
from_version = cfg["version"]
self._CreateValidConfigDir() self._CreateValidConfigDir()
utils.WriteFile(self.config_path, data=serializer.DumpJson(cfg)) utils.WriteFile(self.config_path, data=serializer.DumpJson(cfg))
...@@ -350,22 +355,29 @@ class TestCfgupgrade(unittest.TestCase): ...@@ -350,22 +355,29 @@ class TestCfgupgrade(unittest.TestCase):
def testUpgradeCurrent(self): def testUpgradeCurrent(self):
self._TestSimpleUpgrade(constants.CONFIG_VERSION, False) self._TestSimpleUpgrade(constants.CONFIG_VERSION, False)
def testDowngrade(self): def _RunDowngradeUpgrade(self):
self._TestSimpleUpgrade(constants.CONFIG_VERSION, False)
oldconf = self._LoadConfig() oldconf = self._LoadConfig()
_RunUpgrade(self.tmpdir, False, True, downgrade=True) _RunUpgrade(self.tmpdir, False, True, downgrade=True)
_RunUpgrade(self.tmpdir, False, True) _RunUpgrade(self.tmpdir, False, True)
newconf = self._LoadConfig() newconf = self._LoadConfig()
self.assertEqual(oldconf, newconf) self.assertEqual(oldconf, newconf)
def testDowngradeTwice(self): def testDowngrade(self):
self._TestSimpleUpgrade(constants.CONFIG_VERSION, False) self._TestSimpleUpgrade(constants.CONFIG_VERSION, False)
self._RunDowngradeUpgrade()
def _RunDowngradeTwice(self):
"""Make sure that downgrade is idempotent."""
_RunUpgrade(self.tmpdir, False, True, downgrade=True) _RunUpgrade(self.tmpdir, False, True, downgrade=True)
oldconf = self._LoadConfig() oldconf = self._LoadConfig()
_RunUpgrade(self.tmpdir, False, True, downgrade=True) _RunUpgrade(self.tmpdir, False, True, downgrade=True)
newconf = self._LoadConfig() newconf = self._LoadConfig()
self.assertEqual(oldconf, newconf) self.assertEqual(oldconf, newconf)
def testDowngradeTwice(self):
self._TestSimpleUpgrade(constants.CONFIG_VERSION, False)
self._RunDowngradeTwice()
def testUpgradeDryRunFrom_2_0(self): def testUpgradeDryRunFrom_2_0(self):
self._TestSimpleUpgrade(constants.BuildVersion(2, 0, 0), True) self._TestSimpleUpgrade(constants.BuildVersion(2, 0, 0), True)
......
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