From 4eb770a5f65a092e9542728b46832be1cf313793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?El=C5=91d=20Ill=C3=A9s?= Date: Mon, 6 Mar 2023 19:24:48 +0100 Subject: [PATCH] Fix release id fetch for validate_series_open With the new release identification / naming schema [1] (like: 2023.1 Antelope) new stable branch naming was introduced (like: stable/2023.1). This results a false warning message now when validating bobcat releases [2], as the validator searches for stable/antelope instead of stable/2023.1 stable branch. This patch fixes the validate_series_open validator to use release_id for the branch name, where that exists. Besides, the patch also refactors the release-id fetching and ensures that the release_id is always returened as string and the series name is used if there is no release_id for the given series. [1] https://governance.openstack.org/tc/reference/release-naming.html [2] validate_series_open: There is no stable/antelope branch defined in deliverables/antelope/.yaml. Is the bobcat series open? Change-Id: I71eae27f124473699c22dac0b0eb2b0b1d44b4da --- openstack_releases/cmds/list_deliverables.py | 5 +- openstack_releases/cmds/new_release.py | 5 +- .../cmds/propose_final_releases.py | 5 +- .../cmds/propose_library_branches.py | 5 +- openstack_releases/cmds/validate.py | 4 +- openstack_releases/gitutils.py | 5 +- openstack_releases/series_status.py | 2 +- openstack_releases/tests/test_redirections.py | 4 +- openstack_releases/tests/test_validate.py | 138 +++++++++++++++++- 9 files changed, 146 insertions(+), 27 deletions(-) diff --git a/openstack_releases/cmds/list_deliverables.py b/openstack_releases/cmds/list_deliverables.py index 9689b63132..ed39e3558f 100644 --- a/openstack_releases/cmds/list_deliverables.py +++ b/openstack_releases/cmds/list_deliverables.py @@ -30,10 +30,7 @@ def get_stable_branch_id(series): naming style: stable/2023.1 (versus the old style: stable/zed). """ series_status_data = series_status.SeriesStatus.default() - release_id = series_status_data[series].release_id - if release_id is None: - release_id = series - return str(release_id) + return series_status_data[series].release_id def main(): diff --git a/openstack_releases/cmds/new_release.py b/openstack_releases/cmds/new_release.py index cd25c9cf66..aca0606da4 100644 --- a/openstack_releases/cmds/new_release.py +++ b/openstack_releases/cmds/new_release.py @@ -170,10 +170,7 @@ def get_stable_branch_id(series): naming style: stable/2023.1 (versus the old style: stable/zed). """ series_status_data = series_status.SeriesStatus.default() - release_id = series_status_data[series].release_id - if release_id is None: - release_id = series - return str(release_id) + return series_status_data[series].release_id def main(): diff --git a/openstack_releases/cmds/propose_final_releases.py b/openstack_releases/cmds/propose_final_releases.py index ead5fae8a4..636bc98de0 100644 --- a/openstack_releases/cmds/propose_final_releases.py +++ b/openstack_releases/cmds/propose_final_releases.py @@ -38,10 +38,7 @@ def get_stable_branch_id(series): naming style: stable/2023.1 (versus the old style: stable/zed). """ series_status_data = series_status.SeriesStatus.default() - release_id = series_status_data[series].release_id - if release_id is None: - release_id = series - return str(release_id) + return series_status_data[series].release_id def get_prior_branch_point(workdir, repo, branch): diff --git a/openstack_releases/cmds/propose_library_branches.py b/openstack_releases/cmds/propose_library_branches.py index b00a313244..2478f8f1ee 100644 --- a/openstack_releases/cmds/propose_library_branches.py +++ b/openstack_releases/cmds/propose_library_branches.py @@ -106,10 +106,7 @@ def main(): deliverable_files = sorted(glob.glob(pattern)) series_status_data = series_status.SeriesStatus.default() - release_id = series_status_data[args.series].release_id - if release_id is None: - release_id = args.series - new_branch = 'stable/' + str(release_id) + new_branch = 'stable/' + series_status_data[args.series].release_id for filename in deliverable_files: deliverable_name = os.path.basename(filename)[:-5] diff --git a/openstack_releases/cmds/validate.py b/openstack_releases/cmds/validate.py index 58b48ad411..e0cdc18d20 100644 --- a/openstack_releases/cmds/validate.py +++ b/openstack_releases/cmds/validate.py @@ -42,6 +42,7 @@ from openstack_releases import project_config from openstack_releases import puppetutils from openstack_releases import pythonutils from openstack_releases import requirements +from openstack_releases import series_status from openstack_releases import versionutils from openstack_releases import xstaticutils @@ -236,7 +237,8 @@ def validate_series_open(deliv, context): previous_series = os.path.basename( os.path.dirname(previous_deliverable_file) ) - expected_branch = 'stable/' + previous_series + series_status_data = series_status.SeriesStatus.default() + expected_branch = 'stable/' + series_status_data[previous_series].release_id previous_deliverable = deliverable.Deliverable.read_file( previous_deliverable_file ) diff --git a/openstack_releases/gitutils.py b/openstack_releases/gitutils.py index 99532735ee..d42e52ea97 100644 --- a/openstack_releases/gitutils.py +++ b/openstack_releases/gitutils.py @@ -38,10 +38,7 @@ def get_stable_branch_id(series): naming style: stable/2023.1 (versus the old style: stable/zed). """ series_status_data = series_status.SeriesStatus.default() - release_id = series_status_data[series].release_id - if release_id is None: - release_id = series - return str(release_id) + return series_status_data[series].release_id def find_modified_deliverable_files(): diff --git a/openstack_releases/series_status.py b/openstack_releases/series_status.py index 34edc58c5f..79e3212527 100644 --- a/openstack_releases/series_status.py +++ b/openstack_releases/series_status.py @@ -45,7 +45,7 @@ class Series(object): @property def release_id(self): - return self._data.get('release-id', None) + return str(self._data.get('release-id', self.name)) @property def eol_date(self): diff --git a/openstack_releases/tests/test_redirections.py b/openstack_releases/tests/test_redirections.py index b3574a9499..00b071e4f4 100644 --- a/openstack_releases/tests/test_redirections.py +++ b/openstack_releases/tests/test_redirections.py @@ -211,7 +211,7 @@ class TestRedirections(base.BaseTestCase): deliverables = FakeDeliverables([ self.OPEN_DEVELOPMENT, ]) - self.assertEqual([dict(code=302, src=2019.1, ref_type='branch', + self.assertEqual([dict(code=302, src='2019.1', ref_type='branch', dst='master')], generate_constraints_redirections( deliverables, self.SERIES_STATUS_DATA_WITH_RELEASE_ID)) @@ -220,7 +220,7 @@ class TestRedirections(base.BaseTestCase): deliverables = FakeDeliverables([ self.OPEN_STABLE_WITH_RELEASE_ID, ]) - self.assertEqual([dict(code=301, src=2018.2, ref_type='branch', + self.assertEqual([dict(code=301, src='2018.2', ref_type='branch', dst='stable/2018.2')], generate_constraints_redirections( deliverables, self.SERIES_STATUS_DATA_WITH_RELEASE_ID)) diff --git a/openstack_releases/tests/test_validate.py b/openstack_releases/tests/test_validate.py index af1e529894..413add7e63 100644 --- a/openstack_releases/tests/test_validate.py +++ b/openstack_releases/tests/test_validate.py @@ -2628,7 +2628,19 @@ class TestValidateSeriesOpen(base.BaseTestCase): mock.Mock(return_value=True), )) - def test_series_is_open(self): + @mock.patch('openstack_releases.defaults.RELEASE', 'b') + @mock.patch('openstack_releases.series_status.SeriesStatus.default') + def test_series_is_open(self, series_data): + _series_status_data = yamlutils.loads(textwrap.dedent(''' + - name: b + status: development + initial-release: 2018-02-28 + - name: a + status: maintained + initial-release: 2017-02-22 + ''')) + series_data.return_value = series_status.SeriesStatus( + _series_status_data) series_a_dir = self.tmpdir + '/a' series_a_filename = series_a_dir + '/automaton.yaml' series_b_dir = self.tmpdir + '/b' @@ -2665,7 +2677,66 @@ class TestValidateSeriesOpen(base.BaseTestCase): self.assertEqual(0, len(self.ctx.warnings)) self.assertEqual(0, len(self.ctx.errors)) - def test_no_earlier_series(self): + @mock.patch('openstack_releases.defaults.RELEASE', 'b') + @mock.patch('openstack_releases.series_status.SeriesStatus.default') + def test_series_is_open_with_release_id(self, series_data): + _series_status_data = yamlutils.loads(textwrap.dedent(''' + - name: b + status: development + initial-release: 2018-02-28 + - name: a + status: maintained + release-id: 2017.1 + initial-release: 2017-02-22 + ''')) + series_data.return_value = series_status.SeriesStatus( + _series_status_data) + series_a_dir = self.tmpdir + '/a' + series_a_filename = series_a_dir + '/automaton.yaml' + series_b_dir = self.tmpdir + '/b' + series_b_filename = series_b_dir + '/automaton.yaml' + os.makedirs(series_a_dir) + os.makedirs(series_b_dir) + branch_data = textwrap.dedent(''' + --- + branches: + - name: stable/2017.1 + location: 1.4.0 + ''') + deliverable_data = textwrap.dedent(''' + --- + releases: + - version: 1.5.0 + projects: + - repo: openstack/automaton + hash: be2885f544637e6ee6139df7dc7bf937925804dd + ''') + with open(series_a_filename, 'w') as f: + f.write(branch_data) + with open(series_b_filename, 'w') as f: + f.write(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series='b', + name='name', + data=yamlutils.loads(deliverable_data), + ) + self.ctx.set_filename(series_b_filename) + validate.validate_series_open(deliv, self.ctx) + self.ctx.show_summary() + self.assertEqual(0, len(self.ctx.warnings)) + self.assertEqual(0, len(self.ctx.errors)) + + @mock.patch('openstack_releases.defaults.RELEASE', 'b') + @mock.patch('openstack_releases.series_status.SeriesStatus.default') + def test_no_earlier_series(self, series_data): + _series_status_data = yamlutils.loads(textwrap.dedent(''' + - name: b + status: development + initial-release: 2018-08-30 + ''')) + series_data.return_value = series_status.SeriesStatus( + _series_status_data) series_b_dir = self.tmpdir + '/b' series_b_filename = series_b_dir + '/automaton.yaml' os.makedirs(series_b_dir) @@ -2712,7 +2783,19 @@ class TestValidateSeriesOpen(base.BaseTestCase): self.assertEqual(0, len(self.ctx.warnings)) self.assertEqual(0, len(self.ctx.errors)) - def test_no_stable_branch(self): + @mock.patch('openstack_releases.defaults.RELEASE', 'b') + @mock.patch('openstack_releases.series_status.SeriesStatus.default') + def test_no_stable_branch(self, series_data): + _series_status_data = yamlutils.loads(textwrap.dedent(''' + - name: b + status: development + initial-release: 2018-08-30 + - name: a + status: maintained + initial-release: 2018-02-28 + ''')) + series_data.return_value = series_status.SeriesStatus( + _series_status_data) series_a_dir = self.tmpdir + '/a' series_a_filename = series_a_dir + '/automaton.yaml' series_b_dir = self.tmpdir + '/' + defaults.RELEASE @@ -2744,6 +2827,55 @@ class TestValidateSeriesOpen(base.BaseTestCase): validate.validate_series_open(deliv, self.ctx) self.ctx.show_summary() self.assertEqual(1, len(self.ctx.warnings)) + self.assertIn('There is no stable/a branch defined', self.ctx.warnings[0]) + self.assertEqual(0, len(self.ctx.errors)) + + @mock.patch('openstack_releases.defaults.RELEASE', 'b') + @mock.patch('openstack_releases.series_status.SeriesStatus.default') + def test_no_stable_branch_with_release_id(self, series_data): + _series_status_data = yamlutils.loads(textwrap.dedent(''' + - name: b + status: development + initial-release: 2018-08-30 + - name: a + status: maintained + release-id: 2018.1 + initial-release: 2018-02-28 + ''')) + series_data.return_value = series_status.SeriesStatus( + _series_status_data) + series_a_dir = self.tmpdir + '/a' + series_a_filename = series_a_dir + '/automaton.yaml' + series_b_dir = self.tmpdir + '/' + defaults.RELEASE + series_b_filename = series_b_dir + '/automaton.yaml' + os.makedirs(series_a_dir) + os.makedirs(series_b_dir) + branch_data = textwrap.dedent(''' + --- + ''') + deliverable_data = textwrap.dedent(''' + --- + releases: + - version: 1.5.0 + projects: + - repo: openstack/automaton + hash: be2885f544637e6ee6139df7dc7bf937925804dd + ''') + with open(series_a_filename, 'w') as f: + f.write(branch_data) + with open(series_b_filename, 'w') as f: + f.write(deliverable_data) + deliv = deliverable.Deliverable( + team='team', + series=defaults.RELEASE, + name='name', + data=yamlutils.loads(deliverable_data), + ) + self.ctx.set_filename(series_b_filename) + validate.validate_series_open(deliv, self.ctx) + self.ctx.show_summary() + self.assertEqual(1, len(self.ctx.warnings)) + self.assertIn('There is no stable/2018.1 branch defined', self.ctx.warnings[0]) self.assertEqual(0, len(self.ctx.errors))