Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccmlib/scylla_repository: introduce get_manger_* functions #474

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions ccmlib/scylla_repository.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import logging
import random
import time
from pathlib import Path
from typing import NamedTuple

import os
import tarfile
import tempfile
Expand All @@ -13,6 +7,11 @@
import sys
import glob
import urllib
import logging
import random
import time
fruch marked this conversation as resolved.
Show resolved Hide resolved
from pathlib import Path
from typing import NamedTuple, Literal

import requests
import yaml
Expand Down Expand Up @@ -566,3 +565,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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to enforce type annotations, we might need to, well, enforce it. like

def get_manager_latest_reloc_url(branch: str = "master", architecture: Optional[Architecture] = None) -> str:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mostly for documentation now, not going to enforce it with tools.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, if we want to use for document, i think we need to get it right from the very beginning.

"""
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:
fruch marked this conversation as resolved.
Show resolved Hide resolved
"""
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'