Ejemplo n.º 1
0
    def run(self, force: bool = False) -> str:
        if not force and AWS_MOCK_IP_FILE.exists():
            LOGGER.warning(
                "%s found, don't run a new container and return AWS Mock IP from it",
                AWS_MOCK_IP_FILE)
            return AWS_MOCK_IP_FILE.read_text(encoding="utf-8")

        container = ContainerManager.run_container(self, "aws_mock")
        res = container.exec_run([
            "bash", "-cxe",
            dedent("""\
            mkdir -p /src/s3/scylla-qa-keystore
            ssh-keygen -q -b 2048 -t rsa -N "" -C aws_mock -f /src/s3/scylla-qa-keystore/scylla-qa-ec2
            chown -R nginx:nginx /src/s3/scylla-qa-keystore
            useradd ubuntu
            mkdir -m 700 -p /home/ubuntu/.ssh
            cp /src/s3/scylla-qa-keystore/scylla-qa-ec2.pub /home/ubuntu/.ssh/authorized_keys
            chown -R ubuntu:ubuntu /home/ubuntu/.ssh
        """)
        ])
        if res.exit_code:
            raise DockerException(f"{container}: {res.output.decode('utf-8')}")

        aws_mock_ip = ContainerManager.get_ip_address(self, "aws_mock")
        AWS_MOCK_IP_FILE.write_text(aws_mock_ip, encoding="utf-8")

        return aws_mock_ip
    def test_get_ip_address(self):
        no_ip_address = dict(NetworkSettings=dict(IPAddress=""))
        ip_address = dict(NetworkSettings=dict(IPAddress="10.0.0.1"))
        ip_addresses = iter((no_ip_address, no_ip_address, ip_address, "mark", ) + (no_ip_address, ) * 10)

        def attrs():
            return next(ip_addresses)

        self.container.get_attrs = attrs

        with self.subTest("Try to get IP address of non-existent container"):
            self.assertRaises(NotFound, ContainerManager.get_ip_address, self.node, "c2")

        with self.subTest("Get IP address"):
            self.assertEqual(ContainerManager.get_ip_address(self.node, "c1"), "10.0.0.1")
            self.assertEqual(attrs(), "mark")

        with self.subTest("Test too many retries"):
            self.assertRaises(Retry, ContainerManager.get_ip_address, self.node, "c1")
Ejemplo n.º 3
0
 def _get_public_ip_address(self) -> Optional[str]:
     return ContainerManager.get_ip_address(self, "node")
Ejemplo n.º 4
0
 def public_ip_address(self):
     return ContainerManager.get_ip_address(self, "node")