コード例 #1
0
ファイル: command_runner.py プロジェクト: mongodb/dsi
def make_host_runner(host_info,
                     command,
                     prefix,
                     mongodb_auth_settings=None,
                     use_tls=None):
    """
    For the host, make an appropriate RemoteHost or LocalHost Object and run the set of commands.

    :param host_info HostInfo
    :param command: The command to execute. If str, run that command. If dict, type is one of
    upload_repo_files, upload_files, retrieve_files, exec, or exec_mongo_shell.
    :type command: str, dict
    :param str prefix: The id for the test related to the current command. If there
    is not a specific test related to the current command, the value of prefix should reflect the
    hook that the command belongs to, such as between_tests, post_task, and so on.
    """

    # Create the appropriate host type
    target_host = host_factory.make_host(host_info, mongodb_auth_settings,
                                         use_tls)
    try:
        # If command is a string, pass it directly to run
        if isinstance(command, str):
            target_host.run(command)

        # If command is a dictionary, parse it
        elif isinstance(command, MutableMapping):
            _run_host_command_map(target_host, command, prefix)
    finally:
        target_host.close()
コード例 #2
0
 def host(self):
     """Access to remote or local host."""
     if self._host is None:
         host_info = self.client_config.compute_host_info()
         self._host = host_factory.make_host(
             host_info, use_tls=self.client_config.use_tls)
     return self._host
コード例 #3
0
ファイル: jstests.py プロジェクト: mongodb/dsi
def _remote_exists(config):
    """
    Check on remote workload_client whether jstests_dir exists.
    """
    host_info = extract_hosts("workload_client", config)[0]
    remote_host = make_host(host_info)
    remote_command = [
        "[ -e {} ]".format(config["test_control"]["jstests_dir"])
    ]
    return remote_host.run(remote_command)
コード例 #4
0
ファイル: command_runner.py プロジェクト: mongodb/dsi
def make_workload_runner_host(config):
    """
    Convenience function to make a host to connect to the workload runner node.

    :param ConfigDict config: The system configuration
    """
    host_info = host_utils.extract_hosts("workload_client", config)[0]
    mongodb_auth_settings = mongodb_setup_helpers.mongodb_auth_settings(config)
    use_tls = mongodb_setup_helpers.mongodb_tls_configured(
        config["mongodb_setup"]["mongod_config_file"])
    return host_factory.make_host(host_info, mongodb_auth_settings, use_tls)
コード例 #5
0
    def test_make_host(self, mock_ssh):
        """ Test make host """

        my_host_info = host_info.HostInfo(public_ip="53.1.1.1",
                                          offset=0,
                                          ssh_user="******",
                                          ssh_key_file="ssh_key_file")

        my_host_info.category = "mongod"
        mongod = host_factory.make_host(my_host_info)
        self.assertEqual(mongod.alias, "mongod.0", "alias not set as expected")

        my_host_info.category = "mongos"
        my_host_info.offset = 1
        mongos = host_factory.make_host(my_host_info)
        self.assertEqual(mongos.alias, "mongos.1", "alias not set as expected")

        my_host_info.category = "localhost"
        for my_ip in ["localhost", "127.0.0.1", "0.0.0.0"]:
            my_host_info.public_ip = my_ip
            localhost = host_factory.make_host(my_host_info)
            self.assertEqual(localhost.alias, "localhost.1",
                             "alias not set as expected")
コード例 #6
0
def _write_hosts_file_thread(host_info, output):
    timestamp = datetime.datetime.now().isoformat("T")
    upload_file = "/tmp/hosts.new." + timestamp
    bak_file = "/etc/hosts.bak." + timestamp
    argv = [
        ["sudo", "cp", "/etc/hosts", bak_file],
        ["sudo", "bash", "-c", "'cat {} >> /etc/hosts'".format(upload_file)],
    ]

    file_contents = "###### BELOW GENERATED BY DSI ####################\n"
    file_contents += "\n".join(output) + "\n"
    target_host = host_factory.make_host(host_info)
    assert isinstance(target_host,
                      RemoteHost), "/etc/hosts writer must be a RemoteHost"
    target_host.create_file(upload_file, file_contents)
    target_host.run(argv)
コード例 #7
0
ファイル: download_mongodb.py プロジェクト: mongodb/dsi
    def __init__(self, config):

        self.config = config
        self.mongodb_binary_archive = config["mongodb_setup"].get(
            "mongodb_binary_archive", "")

        # If mongodb_binary_archive is set in runtime, use it instead. Previously we only did that
        # if the mongodb_binary_archive was "", but we have since added a useable default value.
        # This second if statement is necessary for backwards compatibility after changes
        # introducted in PERF-1044. It may be removed after all verions of system_perf.yml,
        # longevity.yml specify the mongodb_binary_archive in bootstrap.yml instead of runtime.yml.

        if "runtime" in list(config.keys()):
            self.mongodb_binary_archive = config["runtime"].get(
                "mongodb_binary_archive", self.mongodb_binary_archive)
        LOG.info("Download url is %s", self.mongodb_binary_archive)

        self.hosts = []
        for host_info in host_utils.extract_hosts("all_hosts", self.config):
            self.hosts.append(host_factory.make_host(host_info))

        if self.mongodb_binary_archive:
            LOG.debug("DownloadMongodb initialized with url: %s",
                      self.mongodb_binary_archive)