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_integration_tests( pytest_command=pytest_command, log_output_live=True, ) # 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_integration_tests( pytest_command=pytest_command, log_output_live=True, ) # 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_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_integration_tests(pytest_command=command).stdout assert str(master.public_ip_address).encode() == result.strip()
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_integration_tests( pytest_command=command, test_host=agent, ).stdout assert str(agent.public_ip_address).encode() == result.strip()
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() 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, log_output_live=False, tty=True, shell=True, env=env, transport=transport, ) except subprocess.CalledProcessError as exc: sys.exit(exc.returncode) return try: cluster.run_integration_tests( pytest_command=args, tty=True, env=env, test_host=host, transport=transport, ) except subprocess.CalledProcessError as exc: sys.exit(exc.returncode)