Skip to content

Commit

Permalink
ccmlib/scylla_repository: introduce get_manger_* functions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fruch committed Jul 9, 2023
1 parent ad16596 commit 76fa918
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
54 changes: 43 additions & 11 deletions ccmlib/scylla_repository.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@


import logging
import random
import time
from pathlib import Path
from typing import NamedTuple

import os
import tarfile
import tempfile
Expand All @@ -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 (
Expand Down Expand Up @@ -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}'
24 changes: 23 additions & 1 deletion tests/test_scylla_repository.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'

0 comments on commit 76fa918

Please sign in to comment.