예제 #1
0
    def _create_node(self, node_index, container=None):
        node = DockerNode(parent_cluster=self,
                          container=container,
                          ssh_login_info=dict(
                              hostname=None,
                              user=self.node_container_user,
                              key_file=self.node_container_key_file),
                          base_logdir=self.logdir,
                          node_prefix=self.node_prefix,
                          node_index=node_index)

        if container is None:
            ContainerManager.build_container_image(node, "node")

        ContainerManager.run_container(
            node,
            "node",
            seed_ip=self.nodes[0].public_ip_address if node_index else None)
        ContainerManager.wait_for_status(node, "node", status="running")
        ContainerManager.ssh_copy_id(node, "node", self.node_container_user,
                                     self.node_container_key_file)

        node.init()

        return node
예제 #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_wait_for_status(self):
        statuses = iter(("exited", "exited", "running", "mark1",
                         "running", "running", "exited", "mark2", ) +
                        ("exited", ) * 20)

        def status():
            return next(statuses)

        self.container.get_status = status

        with self.subTest("Try to get status of non-existent container"):
            self.assertRaises(NotFound, ContainerManager.wait_for_status, self.node, "c2", status="exited")

        with self.subTest("Wait for `running' status"):
            ContainerManager.wait_for_status(self.node, "c1", status="running")
            self.assertEqual(status(), "mark1")

        with self.subTest("Wait for `exited' status"):
            ContainerManager.wait_for_status(self.node, "c1", status="exited")
            self.assertEqual(status(), "mark2")

        with self.subTest("Test too many retries"):
            self.assertRaises(Retry, ContainerManager.wait_for_status, self.node, "c1", status="running")