From 4f2d12ae757777864f3d1fa514fa7656f4fbd523 Mon Sep 17 00:00:00 2001 From: Andrea Barbadoro Date: Mon, 16 Jan 2023 17:06:24 +0100 Subject: [PATCH] tests/RedpandaInstaller release_range method this method creates a list of versions to install to simulate an upgrade path. each version is either the latest for its line, or one from the provided do_not_skip list the list starts with the "earliest" parameter (default oldest line) and the "latest" parameter (default to HEAD) --- tests/rptest/services/redpanda_installer.py | 66 +++++++++++++++++++++ tests/setup.py | 3 +- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/rptest/services/redpanda_installer.py b/tests/rptest/services/redpanda_installer.py index d5035daeec5fd..5d0e8a69d4a8a 100644 --- a/tests/rptest/services/redpanda_installer.py +++ b/tests/rptest/services/redpanda_installer.py @@ -8,6 +8,7 @@ # by the Apache License, Version 2.0 import errno +import copy import json import os import re @@ -17,6 +18,7 @@ import requests from ducktape.utils.util import wait_until +from more_itertools import unique_justseen # Match any version that may result from a redpanda binary, which may not be a # released version. @@ -411,6 +413,70 @@ def latest_for_line(self, release_line: tuple[int, int]): assert False, f"no downloadable versions in {versions_in_line[0:2]} for {release_line=}" + def release_range( + self, + *, + earliest: typing.Optional[typing.Union[tuple[int, int], + tuple[int, int, int]]] = None, + latest: typing.Optional[typing.Union[str, tuple[int, int], + tuple[int, int, int]]] = None, + do_not_skip: list[tuple[int, int, int]] = [] + ) -> list[tuple[int, int, int]]: + """ + returns a list of version to implement an upgrade path. for each line, it will return the latest for the line, + from earliest up to latest line. + versions in the do_not_skip list will be integrated in the upgrade path + e.g release_range(earliest=(21, 2), latest=RedpandaInstaller.HEAD, do_not_skip=[(22, 2, 7)]) -> + [(21, 2, 8), (21, 3, 9), (22, 1, 7), (22, 2, 7), (22, 2, 8), (22, 3, 9), (23, 1, 0)] + + :param earliest: first version or line to install DEFAULT the oldest line + :param latest: last version or line or HEAD to install DEFAULT RedpandaInstallerHEAD + :param do_not_skip: versions to integrate in the list DEFAULT empty + :return: a list of version in the range [earliest, latest], + each being a) the latest from its line or b) one from do_not_skip. + """ + + self.start() + self._initialize_released_versions() + + # default to oldest + if not earliest: + earliest = self._released_versions[-1][0:2] + + # convert to specific version + if len(earliest) == 2: + earliest, _ = self.latest_for_line(earliest) + + # default to _head_version + if not latest or latest == RedpandaInstaller.HEAD: + latest = self._head_version + + # convert to specific version + if len(latest) == 2: + latest, _ = self.latest_for_line(latest) + + # setup a copy (we are going to modify it) + rel_range = copy.deepcopy(self._released_versions) + + # glue head in front, as the most recent version + rel_range.insert(0, self._head_version) + + # clamp to [latest, earliest] + rel_range = rel_range[rel_range.index(latest + ):rel_range.index(earliest) + 1] + + # keep one version per release line (needs to reintegrate earliest) + rel_range = list(unique_justseen(rel_range, key=lambda v: v[0:2])) + rel_range.insert(0, earliest) + + # integrate versions that needs to be in + rel_range.extend(do_not_skip) + # put them in order + rel_range = sorted(rel_range, reverse=True) + + # final unique pass, to remove duplicates + sort them in upgrade order + return sorted(unique_justseen(rel_range)) + def install(self, nodes, version: typing.Union[str, tuple[int, int], tuple[int, int, int]]): """ diff --git a/tests/setup.py b/tests/setup.py index ab6c6859bdb80..b334d217bbd1a 100644 --- a/tests/setup.py +++ b/tests/setup.py @@ -19,7 +19,8 @@ 'xxhash==2.0.2', 'protobuf==3.19.5', 'fastavro==1.4.9', 'psutil==5.9.0', 'numpy==1.22.3', 'pygal==3.0', 'pytest==7.1.2', 'jump-consistent-hash==3.2.0', 'azure-storage-blob==12.14.1', - 'kafkatest@git+https://github.com/apache/kafka.git@058589b03db686803b33052d574ce887fb5cfbd1#egg=kafkatest&subdirectory=tests' + 'kafkatest@git+https://github.com/apache/kafka.git@058589b03db686803b33052d574ce887fb5cfbd1#egg=kafkatest&subdirectory=tests', + 'more-itertools>=9.0.0' ], scripts=[], )