예제 #1
0
    def test_validate_delays(self):
        blacklisted_configs = ["mongodb_setup.atlas.yml"]  # Some configs don't have topologies.
        directory = whereami.dsi_repo_path("configurations", "mongodb_setup")
        errors = []

        # There are a few files that aren't configuration files.
        names = [name for name in os.listdir(directory) if name.startswith("mongodb_setup")]

        # We need references to provisioning output
        infrastructure_provisioning = whereami.dsi_repo_path(
            "docs/config-specs/infrastructure_provisioning.out.yml"
        )
        with copied_file(infrastructure_provisioning, "infrastructure_provisioning.out.yml"):

            for conf_name in names:
                if conf_name in blacklisted_configs:
                    continue
                with copied_file(os.path.join(directory, conf_name), "mongodb_setup.yml"):
                    config = ConfigDict("mongodb_setup")
                    config.load()

                    topologies = config["mongodb_setup"]["topology"]
                    network_delays = config["mongodb_setup"]["network_delays"]
                    delay_configs = network_delays["clusters"]

                    try:
                        # The DelayNodes throw exceptions when given bad delays, so we
                        # can validate the configuration by simply constructing a DelayGraph
                        # pylint: disable=unused-variable
                        DelayGraph.client_ip = config["infrastructure_provisioning"]["out"][
                            "workload_client"
                        ][0]["private_ip"]

                        version_flag = str_to_version_flag(
                            network_delays.get("version_flag", "default")
                        )
                        DelayGraph.client_node = DelayNode(version_flag)
                        delays = DelayGraph.from_topologies(topologies, delay_configs, version_flag)
                    # pylint: disable=broad-except
                    except Exception as e:
                        errors.append(e)

        # Reset the delay graph's client variables.
        DelayGraph.client_node = DelayNode()
        DelayGraph.client_ip = "workload_client"
        self.assertEqual(errors, [])
예제 #2
0
    def parse_cluster(self):
        """Create cluster for each topology and delay"""

        inf_prov_out = self.config["infrastructure_provisioning"]
        client_config = inf_prov_out["out"]["workload_client"][0]
        client_ip = client_config["private_ip"]
        DelayGraph.client_ip = client_ip

        topologies = self.mongodb_setup.get("topology", [])
        network_delays = self.mongodb_setup.get("network_delays", {})
        delay_configs = network_delays.get("clusters", [])
        version_flag = str_to_version_flag(
            network_delays.get("version_flag", "default"))
        DelayGraph.client_node = DelayNode(version_flag)
        delays = DelayGraph.from_topologies(topologies, delay_configs,
                                            version_flag)
        client_config = ClientConfig(self.config)
        self.client = Client(client_config)

        # pylint: disable=consider-using-enumerate
        for i in range(len(topologies)):
            self.clusters.append(
                mongodb_cluster.create_cluster(topologies[i], delays[i],
                                               self.config))