Example #1
0
    def __set_up_proxy_server(cls, cluster: Cluster,
                              cluster_config: ClusterConfig, proxy_server):
        proxy = cls.get_proxy(cluster.nodes, cluster_config, proxy_server,
                              models.Proxy)

        cluster.set_proxy_values(proxy_values=proxy)
        install_config = cluster.get_install_config()
        proxy_details = install_config.get("proxy") or install_config.get(
            "Proxy")
        assert proxy_details, str(install_config)
        assert (
            proxy_details.get("httpsProxy") == proxy.https_proxy
        ), f"{proxy_details.get('httpsProxy')} should equal {proxy.https_proxy}"
Example #2
0
    def test_delete_clusters(self, api_client: InventoryClient,
                             cluster_configuration):
        """Delete all clusters or single cluster if CLUSTER_ID is given"""

        cluster_id = cluster_configuration.cluster_id
        clusters = api_client.clusters_list() if not cluster_id else [{
            "id":
            cluster_id
        }]

        for cluster_info in clusters:
            cluster = Cluster(api_client,
                              ClusterConfig(cluster_id=cluster_info["id"]),
                              InfraEnvConfig())
            cluster.delete()

        log.info(f"Successfully deleted {len(clusters)} clusters")
Example #3
0
    def cluster(
        self,
        api_client: InventoryClient,
        request: FixtureRequest,
        infra_env_configuration: InfraEnvConfig,
        proxy_server,
        prepare_nodes_network: Nodes,
        cluster_configuration: ClusterConfig,
    ):
        log.debug(
            f"--- SETUP --- Creating cluster for test: {request.node.name}\n")
        cluster = Cluster(
            api_client=api_client,
            config=cluster_configuration,
            infra_env_config=infra_env_configuration,
            nodes=prepare_nodes_network,
        )

        if self._does_need_proxy_server(prepare_nodes_network):
            self._set_up_proxy_server(cluster, cluster_configuration,
                                      proxy_server)

        yield cluster

        if self._is_test_failed(request):
            log.info(
                f"--- TEARDOWN --- Collecting Logs for test: {request.node.name}\n"
            )
            self.collect_test_logs(cluster, api_client, request, cluster.nodes)

            if global_variables.test_teardown:
                if cluster.is_installing() or cluster.is_finalizing():
                    cluster.cancel_install()

        if global_variables.test_teardown:
            with SuppressAndLog(ApiException):
                cluster.deregister_infraenv()

            with suppress(ApiException):
                log.info(
                    f"--- TEARDOWN --- deleting created cluster {cluster.id}\n"
                )
                cluster.delete()
Example #4
0
        def set_iptables_rules_for_nodes(
            cluster: Cluster,
            iptables_rules: List[IptableRule],
            given_nodes=None,
        ):
            given_node_ips = []
            given_nodes = given_nodes or cluster.nodes.nodes

            if cluster.enable_image_download:
                cluster.generate_and_download_infra_env(
                    iso_download_path=cluster.iso_download_path)
            cluster.nodes.start_given(given_nodes)
            for node in given_nodes:
                given_node_ips.append(node.ips[0])
            cluster.nodes.shutdown_given(given_nodes)

            log.info(f"Given node ips: {given_node_ips}")

            for _rule in iptables_rules:
                _rule.add_sources(given_node_ips)
                rules.append(_rule)
                _rule.insert()
Example #5
0
    def _set_up_proxy_server(cluster: Cluster, cluster_config: ClusterConfig,
                             proxy_server):
        proxy_name = "squid-" + cluster_config.cluster_name.suffix
        port = utils.scan_for_free_port(consts.DEFAULT_PROXY_SERVER_PORT)

        machine_cidr = cluster.get_primary_machine_cidr()
        host_ip = str(IPNetwork(machine_cidr).ip + 1)

        no_proxy = []
        no_proxy += [
            str(cluster_network.cidr)
            for cluster_network in cluster_config.cluster_networks
        ]
        no_proxy += [
            str(service_network.cidr)
            for service_network in cluster_config.service_networks
        ]
        no_proxy += [machine_cidr]
        no_proxy += [f".{str(cluster_config.cluster_name)}.redhat.com"]
        no_proxy = ",".join(no_proxy)

        proxy = proxy_server(name=proxy_name,
                             port=port,
                             dir=proxy_name,
                             host_ip=host_ip,
                             is_ipv6=cluster.nodes.is_ipv6)
        cluster_proxy_values = models.Proxy(http_proxy=proxy.address,
                                            https_proxy=proxy.address,
                                            no_proxy=no_proxy)
        cluster.set_proxy_values(proxy_values=cluster_proxy_values)
        install_config = cluster.get_install_config()
        proxy_details = install_config.get("proxy") or install_config.get(
            "Proxy")
        assert proxy_details, str(install_config)
        assert (
            proxy_details.get("httpsProxy") == proxy.address
        ), f"{proxy_details.get('httpsProxy')} should equal {proxy.address}"
Example #6
0
        def get_cluster_func(nodes: Nodes,
                             cluster_config: ClusterConfig) -> Cluster:
            log.debug(
                f"--- SETUP --- Creating cluster for test: {request.node.name}\n"
            )
            _cluster = Cluster(api_client=api_client,
                               config=cluster_config,
                               nodes=nodes,
                               infra_env_config=infra_env_configuration)

            if self._does_need_proxy_server(nodes):
                self.__set_up_proxy_server(_cluster, cluster_config,
                                           proxy_server)

            clusters.append(_cluster)
            return _cluster
Example #7
0
    def cluster(
        self,
        api_client: InventoryClient,
        request: FixtureRequest,
        infra_env_configuration: InfraEnvConfig,
        proxy_server,
        prepare_nodes_network: Nodes,
        cluster_configuration: ClusterConfig,
        ipxe_server: Callable,
        tang_server: Callable,
    ):
        log.debug(
            f"--- SETUP --- Creating cluster for test: {request.node.name}\n")
        if cluster_configuration.disk_encryption_mode == consts.DiskEncryptionMode.TANG:
            self._start_tang_server(tang_server, cluster_configuration)

        cluster = Cluster(
            api_client=api_client,
            config=cluster_configuration,
            infra_env_config=infra_env_configuration,
            nodes=prepare_nodes_network,
        )

        if self._does_need_proxy_server(prepare_nodes_network):
            self.__set_up_proxy_server(cluster, cluster_configuration,
                                       proxy_server)

        if global_variables.ipxe_boot:
            infra_env = cluster.generate_infra_env()
            ipxe_server_controller = ipxe_server(name="ipxe_controller",
                                                 api_client=cluster.api_client)
            ipxe_server_controller.run(infra_env_id=infra_env.id,
                                       cluster_name=cluster.name)
            cluster_configuration.iso_download_path = utils.get_iso_download_path(
                infra_env_configuration.entity_name.get())

        yield cluster

        if self._is_test_failed(request):
            log.info(
                f"--- TEARDOWN --- Collecting Logs for test: {request.node.name}\n"
            )
            self.collect_test_logs(cluster, api_client, request, cluster.nodes)

            if global_variables.test_teardown:
                if cluster.is_installing() or cluster.is_finalizing():
                    cluster.cancel_install()

        if global_variables.test_teardown:
            with SuppressAndLog(ApiException):
                cluster.deregister_infraenv()

            with suppress(ApiException):
                log.info(
                    f"--- TEARDOWN --- deleting created cluster {cluster.id}\n"
                )
                cluster.delete()
Example #8
0
    def cluster(
        self,
        api_client: InventoryClient,
        request: FixtureRequest,
        infra_env_configuration: InfraEnvConfig,
        proxy_server,
        prepare_nodes_network: Nodes,
        cluster_configuration: ClusterConfig,
        ipxe_server,
    ):
        log.debug(
            f"--- SETUP --- Creating cluster for test: {request.node.name}\n")
        cluster = Cluster(
            api_client=api_client,
            config=cluster_configuration,
            infra_env_config=infra_env_configuration,
            nodes=prepare_nodes_network,
        )

        if self._does_need_proxy_server(prepare_nodes_network):
            self.__set_up_proxy_server(cluster, cluster_configuration,
                                       proxy_server)

        if global_variables.ipxe_boot:
            infra_env = cluster.generate_infra_env()
            ipxe_server_controller = ipxe_server(name="ipxe_controller",
                                                 api_client=cluster.api_client)
            ipxe_server_controller.start(infra_env_id=infra_env.id,
                                         cluster_name=cluster.name)

            ipxe_server_url = f"http://{consts.DEFAULT_IPXE_SERVER_IP}:{consts.DEFAULT_IPXE_SERVER_PORT}/{cluster.name}"
            network_name = cluster.nodes.get_cluster_network()
            libvirt_controller = LibvirtController(
                config=cluster.nodes.controller,
                entity_config=cluster_configuration)
            libvirt_controller.set_ipxe_url(network_name=network_name,
                                            ipxe_url=ipxe_server_url)

        yield cluster

        if self._is_test_failed(request):
            log.info(
                f"--- TEARDOWN --- Collecting Logs for test: {request.node.name}\n"
            )
            self.collect_test_logs(cluster, api_client, request, cluster.nodes)

            if global_variables.test_teardown:
                if cluster.is_installing() or cluster.is_finalizing():
                    cluster.cancel_install()

        if global_variables.test_teardown:
            with SuppressAndLog(ApiException):
                cluster.deregister_infraenv()

            with suppress(ApiException):
                log.info(
                    f"--- TEARDOWN --- deleting created cluster {cluster.id}\n"
                )
                cluster.delete()