From 587460bac1d709d075373061b20bbc0b649282f3 Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Thu, 5 Jul 2018 11:22:40 +1000 Subject: [PATCH] Support cloning one freeze to multiple The idea behind the version-map code is to work around a lack of a node that has multiple python3 versions by taking a freeze from one version (say python-3.5) and cloning that to another (say python-3,4). This was written to facilitate the transition from trusty (3.4) to xenial (3.5). With the transition from xenial (3.5) to bionic (3.6) we need to do something similar. To aid the transition it'd be nice to be able to duplicate a 3.5 freeze to both 3.4 *and* 3.6. The current version_map doesn't allow for that. Enhance the version_map code to accommodate this situation. The idea would be to backport this as far as Ocata[1] [1] We need to look again at separating the requirements code from the data Change-Id: I8784509bc162eb6f2e80261bc2d81dbe63ce7989 --- openstack_requirements/cmds/generate.py | 15 +++++------ openstack_requirements/tests/test_generate.py | 25 ++++++++++++++++--- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/openstack_requirements/cmds/generate.py b/openstack_requirements/cmds/generate.py index 9bd50f7092..4c6d21ec3b 100644 --- a/openstack_requirements/cmds/generate.py +++ b/openstack_requirements/cmds/generate.py @@ -139,12 +139,12 @@ def _clone_versions(freezes, options): for freeze_data in freezes: versions = [v for v, d in freezes] version, freeze = freeze_data - if (version in options.version_map and - options.version_map[version] not in versions): - print("Duplicating %s freeze to %s" % - (version, options.version_map[version]), - file=sys.stderr) - freezes.append((options.version_map[version], copy.copy(freeze))) + if version in options.version_map: + for dst_version in sorted(options.version_map[version]): + if dst_version not in versions: + print("Duplicating %s freeze to %s" % + (version, dst_version), file=sys.stderr) + freezes.append((dst_version, copy.copy(freeze))) # -- untested UI glue from here down. @@ -177,7 +177,8 @@ def _validate_options(options): "Invalid version-map entry %(map_entry)s" % dict(map_entry=map_entry)) src, dst = map_entry.split(':') - version_map[src] = dst + version_map.setdefault(src, set()) + version_map[src].add(dst) options.version_map = version_map diff --git a/openstack_requirements/tests/test_generate.py b/openstack_requirements/tests/test_generate.py index 9a33124336..ebc0332ef0 100644 --- a/openstack_requirements/tests/test_generate.py +++ b/openstack_requirements/tests/test_generate.py @@ -110,7 +110,8 @@ class TestClone(testtools.TestCase): def test_py34_clone_py35(self): # Simulate an environment where we have python 3.4 data and need to # clone that to python 3.5 - options = Namespace(version_map={'3.4': '3.5', '3.5': '3.4'}) + options = Namespace(version_map={'3.4': set(['3.5']), + '3.5': set(['3.4'])}) freeze_27 = ('2.7', [('dnspython', '1.15.0')]) freeze_34 = ('3.4', [('dnspython3', '1.12.0')]) freeze_35 = ('3.5', [('dnspython3', '1.12.0')]) @@ -125,7 +126,8 @@ class TestClone(testtools.TestCase): def test_py34_noclone_py35(self): # Simulate an environment where we have python 3.4 and python 3.5 data # so there is no need to clone. - options = Namespace(version_map={'3.4': '3.5', '3.5': '3.4'}) + options = Namespace(version_map={'3.4': set(['3.5']), + '3.5': set(['3.4'])}) freeze_27 = ('2.7', [('dnspython', '1.15.0')]) freeze_34 = ('3.4', [('dnspython3', '1.12.0')]) freeze_35 = ('3.5', [('other-pkg', '1.0.0')]) @@ -140,7 +142,8 @@ class TestClone(testtools.TestCase): def test_py35_clone_py34(self): # Simulate an environment where we have python 3.5 data and need to # clone that to python 3.4 - options = Namespace(version_map={'3.4': '3.5', '3.5': '3.4'}) + options = Namespace(version_map={'3.4': set(['3.5']), + '3.5': set(['3.4'])}) freeze_27 = ('2.7', [('dnspython', '1.15.0')]) freeze_34 = ('3.4', [('dnspython3', '1.12.0')]) freeze_35 = ('3.5', [('dnspython3', '1.12.0')]) @@ -151,3 +154,19 @@ class TestClone(testtools.TestCase): generate._clone_versions(freezes, options) self.assertEqual(expected_freezes, freezes) + + def test_py35_clone_py34_py36(self): + # Simulate an environment where we have python 3.5 data and need to + # clone that to python 3.4 + options = Namespace(version_map={'3.5': set(['3.4', '3.6'])}) + freeze_27 = ('2.7', [('dnspython', '1.15.0')]) + freeze_34 = ('3.4', [('dnspython3', '1.12.0')]) + freeze_35 = ('3.5', [('dnspython3', '1.12.0')]) + freeze_36 = ('3.6', [('dnspython3', '1.12.0')]) + + freezes = [freeze_27, freeze_35] + expected_freezes = [freeze_27, freeze_35, freeze_34, freeze_36] + + generate._clone_versions(freezes, options) + + self.assertEqual(expected_freezes, freezes)