Example #1
0
    def get_kubectl_proxy(node: cluster.BaseNode) -> [str, int]:
        LOGGER.debug("Stop any other process listening on kubectl proxy port")
        node.remoter.run(f"sudo fuser -v4k {KUBECTL_PROXY_PORT}/tcp",
                         ignore_status=True)

        LOGGER.debug("Start kubectl proxy in detached mode")
        node.remoter.run(
            "setsid kubectl proxy --disable-filter --accept-hosts '.*' > proxy.log 2>&1 < /dev/null & sleep 1"
        )

        LOGGER.debug("Start auto_ssh for kubectl proxy")
        ContainerManager.run_container(node,
                                       KUBECTL_PROXY_CONTAINER,
                                       local_port=KUBECTL_PROXY_PORT,
                                       remote_port=get_free_port(),
                                       ssh_mode="-L")

        host = "127.0.0.1"
        port = int(
            ContainerManager.get_environ(
                node, KUBECTL_PROXY_CONTAINER)["SSH_TUNNEL_REMOTE"])

        LOGGER.debug("Waiting for port %s:%s is accepting connections", host,
                     port)
        wait_for_port(host, port)

        return host, port
Example #2
0
    def browser(self):
        ContainerManager.run_container(self.node, "web_driver")

        LOGGER.debug("Waiting for WebDriver container is up")
        ContainerManager.wait_for_status(self.node, "web_driver", "running")

        port = ContainerManager.get_container_port(self.node, "web_driver", WEB_DRIVER_REMOTE_PORT)
        LOGGER.debug("WebDriver port is %s", port)

        if self.use_tunnel:
            LOGGER.debug("Start auto_ssh for Selenium remote WebDriver")
            ContainerManager.run_container(self.node, "auto_ssh:web_driver",
                                           local_port=port,
                                           remote_port=get_free_port(),
                                           ssh_mode="-L")

            LOGGER.debug("Waiting for SSH tunnel container is up")
            ContainerManager.wait_for_status(self.node, "auto_ssh:web_driver", status="running")

            host = "127.0.0.1"
            port = int(ContainerManager.get_environ(self.node, "auto_ssh:web_driver")["SSH_TUNNEL_REMOTE"])
        else:
            host = self.node.external_address

        LOGGER.debug("Waiting for port %s:%s is accepting connections", host, port)
        wait_for_port(host, port)

        time.sleep(WEB_DRIVER_CONTAINER_START_DELAY)

        return Remote(command_executor=f"http://{host}:{port}/wd/hub", options=ChromeOptions())
    def test_get_environ(self):
        self.container.get_attrs = lambda: {"Config": {"Env": ["A", "B=1", ]}}

        with self.subTest("Try to get env for non-existent container"):
            self.assertRaises(NotFound, ContainerManager.get_environ, self.node, "c2")

        with self.subTest("Get env for existent container"):
            self.assertEqual(ContainerManager.get_environ(self.node, "c1"), {"A": None, "B": "1"})