Example #1
0
def _run_host_command(host_list, command, config, prefix):
    """
    For each host in the list, make a parallelized call to make_host_runner to make the appropriate
    host and run the set of commands.

    :param list host_list: List of ip addresses to connect to
    :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 ConfigDict config: The system configuration
    :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.
    """
    if not host_list:
        return

    LOG.debug("Calling run command for %s with command %s", str(host_list),
              str(command))

    mongodb_auth_settings = mongodb_setup_helpers.mongodb_auth_settings(config)
    use_tls = mongodb_setup_helpers.mongodb_tls_settings(
        config["mongodb_setup"]["mongod_config_file"])

    thread_commands = []
    for host_info in host_list:
        thread_commands.append(
            partial(make_host_runner, host_info, command, prefix,
                    mongodb_auth_settings, use_tls))

    run_threads(thread_commands, daemon=True)
 def test_mongodb_auth_settings_enabled(self):
     config = {
         "mongodb_setup": {
             "authentication": {"enabled": True, "username": "******", "password": "******"}
         }
     }
     self.assertEqual(
         mongodb_setup_helpers.mongodb_auth_settings(config),
         mongodb_setup_helpers.MongoDBAuthSettings("username", "password"),
     )
Example #3
0
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)
Example #4
0
 def __init__(self, topology, root_config, delay_graph, is_mongos=False):
     """
     :param root_config: Root ConfigDict.
     :param topology: ConfigDict representing this node's location in the topology.
     :param delay_graph: The DelayGraph object representing this cluster's delays.
     """
     self.mongo_config = MongoConfig(root_config, topology, is_mongos)
     self.net_config = NetConfig(topology, root_config)
     self.delay_node = delay_graph.get_node(
         self.net_config.compute_host_info().private_ip)
     self.auth_settings = mongodb_setup_helpers.mongodb_auth_settings(
         root_config)
     self.use_tls = mongodb_setup_helpers.mongodb_tls_configured(
         root_config["mongodb_setup"]["mongod_config_file"])
Example #5
0
    def __init__(self, topology, root_config, delay_graph):
        """
        :param root_config: Root ConfigDict.
        :param topology: ConfigDict representing this node's location in the topology.
        :param delay_graph: The DelayGraph object representing this cluster's delays.
        """
        self.name = topology.get("id")
        if not self.name:
            self.name = "rs{}".format(ReplTopologyConfig.replsets)
            ReplTopologyConfig.replsets += 1

        self.rs_conf = topology.get("rs_conf", {})
        self.rs_conf_members = []
        self.node_opts = []
        self.configsvr = topology.get("configsvr", False)
        self.delay_graph = delay_graph
        self.auth_settings = mongodb_setup_helpers.mongodb_auth_settings(
            root_config)

        for opt in topology["mongod"]:
            # save replica set member configs
            self.rs_conf_members.append(copy_obj(opt.get("rs_conf_member",
                                                         {})))
            # Must add replSetName and clusterRole
            config_file = copy_obj(opt.get("config_file", {}))
            config_file = mongodb_setup_helpers.merge_dicts(
                config_file, {"replication": {
                    "replSetName": self.name
                }})

            mongod_opt = copy_obj(opt)
            if self.configsvr:
                config_file = mongodb_setup_helpers.merge_dicts(
                    config_file, {"sharding": {
                        "clusterRole": "configsvr"
                    }})
                # The test infrastructure does not set up a separate journal dir for
                # the config server machines.
                mongod_opt["use_journal_mnt"] = False

            mongod_opt["config_file"] = config_file
            self.node_opts.append(
                NodeTopologyConfig(topology=mongod_opt,
                                   root_config=root_config,
                                   delay_graph=delay_graph))
Example #6
0
    def __init__(self, topology, root_config, delay_graph):
        """
        :param root_config: Root ConfigDict.
        :param topology: ConfigDict representing this node's location in the topology.
        :param delay_graph: The DelayGraph object representing this cluster's delays.
        """
        self.topology = topology
        self.root_config = root_config
        self.delay_graph = delay_graph
        self.disable_balancer = topology.get("disable_balancer", True)
        self.mongos_opts = topology["mongos"]
        self.auth_settings = mongodb_setup_helpers.mongodb_auth_settings(
            root_config)

        config_type = topology.get("configsvr_type", "csrs")
        if config_type != "csrs":
            raise NotImplementedError("configsvr_type: {}".format(config_type))

        config_opt = {
            "id": DEFAULT_CSRS_NAME,
            "configsvr": True,
            "mongod": topology["configsvr"]
        }
        self.config_svr_topology = ReplTopologyConfig(topology=config_opt,
                                                      root_config=root_config,
                                                      delay_graph=delay_graph)

        # Since we must support mongo versions prior to 3.6, there may be shards
        # composed of non-replset standalone nodes.
        self.node_shards = []
        self.repl_shards = []
        for topo in topology["shard"]:
            self._create_shard_config(topology=topo,
                                      delay_graph=delay_graph,
                                      root_config=root_config)

        self.mongos_topologies = []
 def test_mongodb_auth_settings_missing_2(self):
     config = {"mongodb_setup": {"authentication": {}}}
     with self.assertRaises(KeyError):
         self.assertEqual(mongodb_setup_helpers.mongodb_auth_settings(config), None)