def test_valid_versions(tmpdir, version_to_test):

    # mock it's a scylla dir
    (Path(tmpdir) / 'scylla').touch()

    # mock the version file
    (Path(tmpdir) / 'build').mkdir()
    with (Path(tmpdir) / 'build' / 'SCYLLA-VERSION-FILE').open(mode='w') as f:
        f.write(version_to_test)

    version = get_scylla_version(install_dir=tmpdir)
    assert version == version_to_test
def setup(version, verbose=True):
    s3_url = ''
    type_n_version = version.split(':', 1)
    if len(type_n_version) == 2:
        s3_version = type_n_version[1]
        s3_url = RELOCATABLE_URLS_BASE.format(type_n_version[0], s3_version)
        version = os.path.join(*type_n_version)

    cdir = version_directory(version)

    if cdir is None:
        tmp_download = tempfile.mkdtemp()

        url = os.environ.get('SCYLLA_CORE_PACKAGE',
                             os.path.join(s3_url, 'scylla-package.tar.gz'))
        package_version = download_version(version,
                                           verbose=verbose,
                                           url=url,
                                           target_dir=os.path.join(
                                               tmp_download,
                                               'scylla-core-package'))
        # Try the old name for backward compatibility
        url = os.environ.get("SCYLLA_TOOLS_JAVA_PACKAGE") or \
            os.environ.get("SCYLLA_JAVA_TOOLS_PACKAGE") or \
            os.path.join(s3_url, 'scylla-tools-package.tar.gz')

        download_version(version,
                         verbose=verbose,
                         url=url,
                         target_dir=os.path.join(tmp_download,
                                                 'scylla-tools-java'))

        url = os.environ.get('SCYLLA_JMX_PACKAGE',
                             os.path.join(s3_url, 'scylla-jmx-package.tar.gz'))
        download_version(version,
                         verbose=verbose,
                         url=url,
                         target_dir=os.path.join(tmp_download, 'scylla-jmx'))

        cdir = directory_name(version)

        shutil.move(tmp_download, cdir)

        # install using scylla install.sh
        run_scylla_install_script(os.path.join(cdir, 'scylla-core-package'),
                                  cdir, package_version)
    setup_scylla_manager()

    return cdir, get_scylla_version(cdir)
 def test_get_scylla_version(self, relocatable_cluster):
     install_dir = relocatable_cluster.get_install_dir()
     assert get_scylla_version(install_dir) == '3.0'
Beispiel #4
0
def setup(version, verbose=True):
    """
    :param version:
            Supported version values (examples):
            1. Unstable versions:
              - unstable/master:2020-12-20T00:11:59Z
              - unstable/enterprise:2020-08-18T14:49:18Z
              - unstable/branch-4.1:2020-05-30T08:27:59Z
            2. Official version (released):
              - release:4.3
              - release:4.2.1
              - release:2020.1 (SCYLLA_PRODUCT='enterprise')
              - release:2020.1.5 (SCYLLA_PRODUCT='enterprise')

    """
    s3_url = ''
    type_n_version = version.split(':', 1)
    scylla_product = os.environ.get('SCYLLA_PRODUCT', 'scylla')

    packages = None
    if len(type_n_version) == 2:
        s3_version = type_n_version[1]
        packages = None

        if type_n_version[0] == 'release':
            if 'enterprise' in scylla_product:
                s3_url = ENTERPRISE_RELEASE_RELOCATABLE_URLS_BASE
            else:
                s3_url = RELEASE_RELOCATABLE_URLS_BASE
            packages, type_n_version[1] = release_packages(s3_url=s3_url, version=s3_version)
        else:
            _, branch = type_n_version[0].split("/")
            if 'enterprise' in scylla_product:
                s3_url = get_relocatable_s3_url(branch, s3_version, ENTERPRISE_RELOCATABLE_URLS_BASE)
            else:
                s3_url = get_relocatable_s3_url(branch, s3_version, RELOCATABLE_URLS_BASE)

            packages = RelocatablePackages(scylla_jmx_package=os.path.join(s3_url,
                                                                           f'{scylla_product}-jmx-package.tar.gz'),
                                           scylla_tools_package=os.path.join(s3_url,
                                                                             f'{scylla_product}-tools-package.tar.gz'),
                                           scylla_package=os.path.join(s3_url,
                                                                       f'{scylla_product}-package.tar.gz'))

        version = os.path.join(*type_n_version)

    version_dir = version_directory(version)

    if version_dir is None:
        # Create version folder and add placeholder file to prevent parallel downloading from another test.
        version_dir = directory_name(version)
        download_in_progress_file = Path(version_dir) / DOWNLOAD_IN_PROGRESS_FILE

        # Give a chance not to start few downloads in the exactly same second
        time.sleep(random.randint(0, 5))

        # If another parallel downloading has been started already, wait while it will be completed
        if download_in_progress_file.exists():
            print(f"Another download running into '{version_dir}'. Waiting for parallel downloading finished")
            wait_for_parallel_download_finish(placeholder_file=download_in_progress_file.absolute())
        else:
            try:
                os.makedirs(version_dir)
            except FileExistsError as exc:
                # If parallel process created the folder first, let to the parallel download to finish
                print(f"Another download running into '{version_dir}'. Waiting for parallel downloading finished")
                wait_for_parallel_download_finish(placeholder_file=download_in_progress_file.absolute())
            else:
                download_in_progress_file.touch()
                try:
                    package_version = download_packages(version_dir=version_dir, packages=packages, s3_url=s3_url,
                                                        scylla_product=scylla_product, version=version, verbose=verbose)
                except requests.HTTPError as err:
                    if '404' in err.args[0]:
                        packages_x86_64 = RelocatablePackages(
                            scylla_jmx_package=os.path.join(s3_url, f'{scylla_product}-jmx-package.tar.gz'),
                            scylla_tools_package=os.path.join(s3_url, f'{scylla_product}-tools-package.tar.gz'),
                            scylla_package=os.path.join(s3_url, f'{scylla_product}-x86_64-package.tar.gz')
                        )
                        package_version = download_packages(version_dir=version_dir, packages=packages_x86_64,
                                                            s3_url=s3_url, scylla_product=scylla_product,
                                                            version=version, verbose=verbose)
                    else:
                        raise

                download_in_progress_file.touch()

                # install using scylla install.sh
                run_scylla_install_script(install_dir=os.path.join(version_dir, CORE_PACKAGE_DIR_NAME),
                                          target_dir=version_dir,
                                          package_version=package_version)
                print(f"Completed to install Scylla in the folder '{version_dir}'")
                download_in_progress_file.unlink()

    scylla_ext_opts = os.environ.get('SCYLLA_EXT_OPTS', '')
    scylla_manager_package = os.environ.get('SCYLLA_MANAGER_PACKAGE')
    if scylla_manager_package:
        manager_install_dir = setup_scylla_manager(scylla_manager_package)
        scylla_ext_opts += ' --scylla-manager={}'.format(manager_install_dir)
        os.environ['SCYLLA_EXT_OPTS'] = scylla_ext_opts

    return version_dir, get_scylla_version(version_dir)