コード例 #1
0
    def __init__(self, download_options, install_dir="", link_dir="", mv_platform=None,
                 edition=None, architecture=None, use_latest=None, versions=None,
                 evergreen_config=None, github_oauth_token=None, debug=None,
                 ignore_failed_push=False):
        """Initialize."""
        setup_logging(debug)
        self.install_dir = os.path.abspath(install_dir)
        self.link_dir = os.path.abspath(link_dir)

        self.edition = edition.lower() if edition else None
        self.platform = mv_platform.lower() if mv_platform else None
        self.architecture = architecture.lower() if architecture else None
        self.use_latest = use_latest
        self.versions = versions
        self.ignore_failed_push = ignore_failed_push

        self.download_binaries = download_options.download_binaries
        self.download_symbols = download_options.download_symbols
        self.download_artifacts = download_options.download_artifacts
        self.download_python_venv = download_options.download_python_venv

        self.evg_api = evergreen_conn.get_evergreen_api(evergreen_config)
        # In evergreen github oauth token is stored as `token ******`, so we remove the leading part
        self.github_oauth_token = github_oauth_token.replace("token ",
                                                             "") if github_oauth_token else None
        with open(config.SETUP_MULTIVERSION_CONFIG) as file_handle:
            raw_yaml = yaml.safe_load(file_handle)
        self.config = config.SetupMultiversionConfig(raw_yaml)

        self._is_windows = is_windows()
        self._windows_bin_install_dirs = []
コード例 #2
0
    def setup_mongodb(artifacts_url, binaries_url, symbols_url, python_venv_url, install_dir,
                      bin_suffix=None, link_dir=None, install_dir_list=None):
        # pylint: disable=too-many-arguments
        """Download, extract and symlink."""

        for url in [artifacts_url, binaries_url, symbols_url, python_venv_url]:
            if url is not None:

                def try_download(download_url):
                    tarball = download.download_from_s3(download_url)
                    download.extract_archive(tarball, install_dir)
                    os.remove(tarball)

                try:
                    try_download(url)
                except Exception as err:  # pylint: disable=broad-except
                    LOGGER.warning("Setting up tarball failed with error, retrying once...",
                                   error=err)
                    time.sleep(1)
                    try_download(url)

        if binaries_url is not None:
            if not link_dir:
                raise ValueError("link_dir must be specified if downloading binaries")

            if not is_windows():
                link_dir = download.symlink_version(bin_suffix, install_dir, link_dir)
            else:
                LOGGER.info(
                    "Linking to install_dir on Windows; executable have to live in different working"
                    " directories to avoid DLLs for different versions clobbering each other")
                link_dir = download.symlink_version(bin_suffix, install_dir, None)
            install_dir_list.append(link_dir)
コード例 #3
0
def get_backports_required_hash_for_shell_version(mongo_shell_path=None):
    """Parse the old shell binary to get the commit hash."""
    env_vars = os.environ.copy()
    paths = get_path_env_var(env_vars=env_vars)
    env_vars["PATH"] = os.pathsep.join(paths)

    mongo_shell = mongo_shell_path
    if is_windows():
        mongo_shell = mongo_shell_path + ".exe"

    shell_version = check_output(f"{mongo_shell} --version",
                                 shell=True,
                                 env=env_vars).decode('utf-8')
    for line in shell_version.splitlines():
        if "gitVersion" in line:
            version_line = line.split(':')[1]
            # We identify the commit hash as the string enclosed by double quotation marks.
            result = re.search(r'"(.*?)"', version_line)
            if result:
                commit_hash = result.group().strip('"')
                if not commit_hash.isalnum():
                    raise ValueError(
                        f"Error parsing commit hash. Expected an "
                        f"alpha-numeric string but got: {commit_hash}")
                return commit_hash
            else:
                break
    raise ValueError(
        f"Could not find a valid commit hash from the {mongo_shell_path} mongo binary."
    )
コード例 #4
0
 def do_test(self, file_name):
     """Execute file test that are known to fail in shutil.rmtree."""
     if not utils.is_windows():
         print("Skipping ShutilWindowsRmtreeFileTests on non-Windows platforms")
         return
     temp_dir = tempfile.mkdtemp(dir=self.temp_dir_root)
     os.chdir(temp_dir)
     create_file(file_name)
     os.chdir(self.temp_dir_root)
     with self.assertRaises(WindowsError):  # pylint: disable=undefined-variable
         shutil.rmtree(temp_dir)
コード例 #5
0
 def do_test(self, file_name):
     """Execute file test that are known to fail in shutil.rmtree."""
     if not utils.is_windows():
         print(
             "Skipping ShutilWindowsRmtreeFileTests on non-Windows platforms"
         )
         return
     temp_dir = tempfile.mkdtemp(dir=self.temp_dir_root)
     os.chdir(temp_dir)
     create_file(file_name)
     os.chdir(self.temp_dir_root)
     with self.assertRaises(WindowsError):  # pylint: disable=undefined-variable
         shutil.rmtree(temp_dir)