Exemple #1
0
    def test_basic_use(self, mock_remote_host, mock_extract_hosts):
        """
        Init DownloadMongodb with ConfigDict structure with
        mongodb_binary specified in mongodb_setup.
        """

        mock_extract_hosts.return_value = [
            HostInfo(public_ip="dummy_ip", offset=i) for i in range(10)
        ]

        DownloadMongodb(self.config)

        calls = [mock.call(HostInfo(public_ip="dummy_ip", offset=i)) for i in range(10)]
        mock_remote_host.assert_has_calls(calls=calls, any_order=True)
Exemple #2
0
def extract_hosts(key, config):
    """
    Extract a list of public IP addresses for hosts based off of the key. Valid keys are mongod,
    mongos, configsvr, workload_client, as well as the helpers all_hosts and all_servers.

    :param ConfigDict config: The system configuration
    """

    if key == "localhost":
        # `offset` is arbitrary for localhost, for other hosts, it represents the index of a node.
        return [
            HostInfo(public_ip="localhost",
                     private_ip="localhost",
                     category="localhost",
                     offset=0)
        ]
    if key == "all_servers":
        return list(
            itertools.chain.from_iterable(
                (_extract_hosts(key, config)
                 for key in ["mongod", "mongos", "configsvr"])))
    if key == "all_hosts":
        return list(
            itertools.chain.from_iterable(
                (_extract_hosts(key, config) for key in
                 ["mongod", "mongos", "configsvr", "workload_client"])))
    return _extract_hosts(key, config)
Exemple #3
0
 def compute_host_info(self):
     """Create host wrapper to run commands."""
     return HostInfo(
         public_ip=self.public_ip,
         private_ip=self.private_ip,
         ssh_user=self.ssh_user,
         ssh_key_file=self.ssh_key_file,
     )
Exemple #4
0
    def test_make_host_runner_str(self, mock_run_host_command_map):
        """ Test run RemoteHost.make_host_runner with str"""
        with patch("dsi.common.host_factory.make_host") as mock_make_host:
            mock_target_host = Mock()
            mock_make_host.return_value = mock_target_host

            dummy_host_info = HostInfo("host_info")

            command_runner.make_host_runner(dummy_host_info, "command",
                                            "test_id")
            mock_make_host.assert_called_once_with(dummy_host_info, None, None)
            mock_target_host.run.assert_called_once_with("command")
            mock_target_host.close.assert_called_once()
Exemple #5
0
    def test_make_host_runner_map(self, mock_run_host_command_map):
        """ Test run Remotecommand_runner.make_host_runner with map"""

        with patch("dsi.common.host_factory.make_host") as mock_make_host:
            command = {}
            mock_target_host = Mock()
            mock_make_host.return_value = mock_target_host

            dummy_host_info = HostInfo("host_name")

            command_runner.make_host_runner(dummy_host_info, command,
                                            "test_id")

            mock_make_host.assert_called_once_with(dummy_host_info, None, None)

            mock_run_host_command_map.assert_called_once_with(
                mock_target_host, command, "test_id")
            mock_target_host.close.assert_called_once()
Exemple #6
0
def _extract_hosts(category, config):
    """
    Extract a list of public IP addresses for hosts based off of the category.
    Valid categories are mongod, mongos, configsvr, and workload_client.

    :param str category: The category to use (mongod, mongod, ...)
    :param ConfigDict config: The system configuration
    :rtype: list of HostInfo objects
    """
    if category in config["infrastructure_provisioning"]["out"]:
        ssh_user, ssh_key_file = ssh_user_and_key_file(config)
        return [
            HostInfo(
                public_ip=host_info["public_ip"],
                private_ip=host_info["private_ip"],
                ssh_user=ssh_user,
                ssh_key_file=ssh_key_file,
                category=category,
                offset=i,
            ) for i, host_info in enumerate(
                config["infrastructure_provisioning"]["out"][category])
        ]
    return list()