def run_demo_script_up(exit_cond=exit_cond):
            test_env = os.environ.copy()
            test_env[
                "DOCKER_COMPOSE_PROJECT_NAME"] = running_custom_production_setup.name

            # the infra layer sets MENDER_TESTPREFIX for the compose command on first run
            # but here we're running the setup manually (the test does multiple ups/downs)
            # the prefix is lost here, so re-set it to the correct value
            test_env[
                "MENDER_TESTPREFIX"] = running_custom_production_setup.name

            args = [
                "./demo",
                "--client",
                "-p",
                running_custom_production_setup.name,
            ]
            args += self.EXTRA_ARGS
            args.append("up")

            proc = subprocess.Popen(
                args,
                cwd="..",
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                env=test_env,
            )
            logger.info("Started the demo script")
            password = ""

            for line in proc.stdout:
                line = line.decode()
                logger.info(line)
                if exit_cond in line.strip():
                    if exit_cond == "Login password:"******":")[-1].strip()
                        logger.info("The login password:")
                        logger.info(password)
                        self.auth.password = password
                        assert len(password) == 12
                    break
            wait_until_healthy(running_custom_production_setup.name)
            return proc
示例#2
0
 def _wait_for_containers(self, expected_containers):
     files_args = "".join([" -f %s" % file for file in self.docker_compose_files])
     running_countainers_count = 0
     for _ in range(60 * 5):
         out = subprocess.check_output(
             "docker-compose -p %s %s ps -q" % (self.name, files_args), shell=True
         )
         running_countainers_count = len(out.split())
         if running_countainers_count == expected_containers:
             wait_until_healthy(self.name)
             return
         else:
             time.sleep(1)
     logger.info(
         "%s: running countainers mismatch, list of currently running: %s"
         % (self.name, out)
     )
     raise Exception(
         "timeout: running containers count: %d, expected: %d for docker-compose project: %s"
         % (running_countainers_count, expected_containers, self.name)
     )
示例#3
0
 def _wait_for_containers(self):
     wait_until_healthy(self.name, timeout=60 * 5)
示例#4
0
import pytest
import subprocess

from urllib.parse import urlparse

# See https://docs.pytest.org/en/latest/writing_plugins.html#assertion-rewriting
pytest.register_assert_rewrite("testutils")

from requests.packages import urllib3
from testutils.common import wait_until_healthy
from testutils.infra.container_manager.kubernetes_manager import isK8S
from testutils.api.client import get_free_tcp_port, wait_for_port

urllib3.disable_warnings()

wait_until_healthy("backend-tests")


@pytest.fixture(scope="session")
def get_endpoint_url():
    processes = {}

    def _get_endpoint_url(url):
        global forward_port
        if isK8S() and url.startswith("http://mender-"):
            url_parsed = urlparse(url)
            host = url_parsed.hostname
            port = url_parsed.port
            _, host_forward_port = processes.get(host, (None, None))
            if host_forward_port is None:
                host_forward_port = get_free_tcp_port()