From a6a5092c5ef804436fcaf0d090d59a80d9e07d19 Mon Sep 17 00:00:00 2001 From: Israel Fruchter Date: Thu, 6 Jul 2023 15:25:22 +0300 Subject: [PATCH] ccmlib/scylla_repository: introduce get_manger_* functions those helper function could be user to retrive scylla manager relocatable packages, that we need in dtest for testing manager, those comes in two flavors: * one to retrive lastet version of of specific branches * one to retrive specific released versions --- ccmlib/scylla_repository.py | 54 ++++++++++++++++++++++++++------- tests/test_scylla_repository.py | 24 ++++++++++++++- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/ccmlib/scylla_repository.py b/ccmlib/scylla_repository.py index e9479706..e301d7cd 100644 --- a/ccmlib/scylla_repository.py +++ b/ccmlib/scylla_repository.py @@ -1,11 +1,3 @@ - - -import logging -import random -import time -from pathlib import Path -from typing import NamedTuple - import os import tarfile import tempfile @@ -15,12 +7,15 @@ import sys import glob import urllib - import hashlib +import logging +import random +import time +from pathlib import Path +from typing import NamedTuple, Literal + import requests import yaml - - import packaging.version from ccmlib.common import ( @@ -567,3 +562,40 @@ def run_scylla_unified_install_script(install_dir, target_dir, package_version): run('''{0}/install.sh --prefix {1} --nonroot{2}'''.format( install_dir, target_dir, install_opt), cwd=install_dir) run(f'''ln -s {install_dir}/scylla/conf conf''', cwd=target_dir) + + +Architecture = Literal['x86_64', 'aarch64'] +BASE_DOWNLOADS_URL = 'https://s3.amazonaws.com/downloads.scylladb.com' + + +def get_manager_latest_reloc_url(branch: str = "master", architecture: Architecture = None) -> str: + """ + get the latest manager relocatable version of a specific branch + """ + architecture = architecture or os.environ.get('SCYLLA_ARCH', 'x86_64') + + url = f"{BASE_DOWNLOADS_URL}/manager/relocatable/unstable/{branch}/" + # filter only specific architecture + all_packages = reversed(aws_bucket_ls(url)) + latest_package = next(filter(lambda tar: architecture in tar, all_packages)) + + # return latest + return f'{BASE_DOWNLOADS_URL}/{latest_package}' + + +def get_manager_release_url(version: str = '', architecture: Architecture = None) -> str: + """ + get latest official relocatable of manager releases of specific versions i.e. '3.1' or '3.1.1' + only works from release 3.1 and up + when version is empty string, won't return latest release (by date, so can be from older branch) + """ + architecture = architecture or os.environ.get('SCYLLA_ARCH', 'x86_64') + + url = f"{BASE_DOWNLOADS_URL}/downloads/scylla-manager/relocatable" + + version_regex = re.compile('scylla-manager_(.*)-0') + # filter only specific architecture and version + all_packages = reversed(aws_bucket_ls(url)) + latest_package = next(filter(lambda tar: architecture in tar and version in version_regex.search(tar)[0], all_packages)) + + return f'{BASE_DOWNLOADS_URL}/downloads/scylla-manager/relocatable/{latest_package}' diff --git a/tests/test_scylla_repository.py b/tests/test_scylla_repository.py index fb0bb6e6..b757a78b 100644 --- a/tests/test_scylla_repository.py +++ b/tests/test_scylla_repository.py @@ -1,8 +1,13 @@ -from unittest.mock import patch +import typing import pytest from ccmlib.scylla_repository import setup as scylla_setup +from ccmlib.scylla_repository import ( + get_manager_release_url, + get_manager_latest_reloc_url, + Architecture, +) @pytest.mark.repo_tests @@ -104,3 +109,20 @@ def test_setup_unstable_master_new_url(self): assert packages.scylla_tools_package == 'https://s3.amazonaws.com/downloads.scylladb.com/unstable/scylla/master/relocatable/2021-01-18T15:48:13Z/scylla-tools-package.tar.gz' assert packages.scylla_jmx_package == 'https://s3.amazonaws.com/downloads.scylladb.com/unstable/scylla/master/relocatable/2021-01-18T15:48:13Z/scylla-jmx-package.tar.gz' + +@pytest.mark.parametrize('architecture', argvalues=typing.get_args(Architecture)) +class TestGetManagerFunctions: + def test_get_manager_latest_reloc_url(self, architecture): + master_version = get_manager_latest_reloc_url(architecture=architecture) + assert 'relocatable/unstable/master' in master_version + assert '-dev-' in master_version + assert architecture in master_version + + branch_version = get_manager_latest_reloc_url('branch-3.1', architecture=architecture) + assert 'relocatable/unstable/branch-3.1' in branch_version + assert architecture in branch_version + + def test_get_manager_release_url(self, architecture): + specific_version = get_manager_release_url('3.1.1', architecture=architecture) + assert specific_version == 'https://s3.amazonaws.com/downloads.scylladb.com/downloads/scylla-manager/' \ + f'relocatable/scylladb-manager-3.1/scylla-manager_3.1.1-0.20230612.401edeb8_linux_{architecture}.tar.gz'