Exemple #1
0
    def test_run_pytest(self, cluster: Cluster) -> None:
        """
        Integration tests can be run with `pytest`.
        Errors are raised from `pytest`.
        """
        # No error is raised with a successful command.
        pytest_command = ['pytest', '-vvv', '-s', '-x', 'test_auth.py']
        cluster.run_with_test_environment(
            args=pytest_command,
            output=Output.CAPTURE,
        )

        # An error is raised with an unsuccessful command.
        with pytest.raises(CalledProcessError) as excinfo:
            pytest_command = ['pytest', 'test_no_such_file.py']
            result = cluster.run_with_test_environment(
                args=pytest_command,
                output=Output.CAPTURE,
            )
            # This result will not be printed if the test passes, but it
            # may provide useful debugging information.
            logging.debug(str(result))  # pragma: no cover

        # `pytest` results in an exit code of 4 when no tests are
        # collected.
        # See https://docs.pytest.org/en/latest/usage.html.
        assert excinfo.value.returncode == 4
def test_calico_ipip_container_connectivity(calico_ipip_cluster: Cluster) -> None:

        environment_variables = {
            "DCOS_LOGIN_UNAME":
            superuser_username,
            "DCOS_LOGIN_PW":
            superuser_password,
            "MASTER_PUBLIC_IP":
            list(calico_ipip_cluster.masters)[0].public_ip_address,
            "MASTERS_PRIVATE_IPS":
            [node.private_ip_address for node in calico_ipip_cluster.masters],
            "PUBLIC_AGENTS_PRIVATE_IPS":
            [node.public_ip_address for node in calico_ipip_cluster.public_agents],
            "PRIVATE_AGENTS_PRIVATE_IPS":
            [node.private_ip_address for node in calico_ipip_cluster.agents],
        }

        pytest_command = [
            "pytest",
            "-vvv",
            "-s",
            "-x",
            "test_networking.py",
            "-k",
            "test_calico",
        ]
        calico_ipip_cluster.run_with_test_environment(
            args=pytest_command,
            env=environment_variables,
            output=Output.LOG_AND_CAPTURE,
        )
Exemple #3
0
 def test_default_node(self, cluster: Cluster) -> None:
     """
     By default commands are run on an arbitrary master node.
     """
     (master, ) = cluster.masters
     command = ['/opt/mesosphere/bin/detect_ip']
     result = cluster.run_with_test_environment(args=command).stdout
     assert str(master.public_ip_address).encode() == result.strip()
Exemple #4
0
 def test_custom_node(self, cluster: Cluster) -> None:
     """
     It is possible to run commands on any node.
     """
     (agent, ) = cluster.agents
     command = ['/opt/mesosphere/bin/detect_ip']
     result = cluster.run_with_test_environment(args=command, node=agent)
     assert str(agent.public_ip_address).encode() == result.stdout.strip()
Exemple #5
0
def run_command(
    args: List[str],
    cluster: Cluster,
    host: Node,
    transport: Transport,
    use_test_env: bool,
    dcos_login_uname: str,
    dcos_login_pw: str,
    env: Dict[str, str],
) -> None:
    """
    Run a command on a given cluster / host.

    Args:
        args: The arguments to run on a node.
        cluster: The cluster to run a command on.
        host: the node to run a command on.
        transport: The transport to use to communicate with the cluster.
        use_test_env: Whether to use the DC/OS integration test environment to
            run the command in.
        dcos_login_uname: The DC/OS login username. This is only used if using
            the test environment and DC/OS Enterprise.
        dcos_login_pw: The DC/OS login password. This is only used if using
            the test environment and DC/OS Enterprise.
        env: Environment variables to set before running the command.
    """
    columns, rows = click.get_terminal_size()
    tty = sys.stdout.isatty()

    env = {
        # LINES and COLUMNS are needed if using the ``DOCKER_EXEC`` transport.
        # See https://github.com/moby/moby/issues/35407.
        'COLUMNS': str(columns),
        'LINES': str(rows),
        'DCOS_LOGIN_UNAME': dcos_login_uname,
        'DCOS_LOGIN_PW': dcos_login_pw,
        **env,
    }

    if not use_test_env:
        try:
            host.run(
                args=args,
                output=Output.NO_CAPTURE,
                tty=tty,
                shell=True,
                env=env,
                transport=transport,
            )
        except subprocess.CalledProcessError as exc:
            sys.exit(exc.returncode)

        return

    try:
        cluster.run_with_test_environment(
            args=args,
            tty=tty,
            env=env,
            node=host,
            transport=transport,
            output=Output.NO_CAPTURE,
        )
    except subprocess.CalledProcessError as exc:
        sys.exit(exc.returncode)