Пример #1
0
def setup_calico():
    # Deploy calico
    # Pinned the test manifests to v3.22. v3.23 deprecated a metric that we check for `felix_active_local_tags`
    # https://projectcalico.docs.tigera.io/archive/v3.22/reference/felix/prometheus
    run_command([
        "kubectl", "apply", "-f",
        "https://projectcalico.docs.tigera.io/archive/v3.22/manifests/calico.yaml"
    ])

    # Install calicoctl as a pod
    run_command([
        "kubectl", "apply", "-f",
        "https://projectcalico.docs.tigera.io/archive/v3.22/manifests/calicoctl.yaml"
    ])

    # Create felix metrics service
    run_command(
        ["kubectl", "apply", "-f",
         path.join(HERE, 'felix-service.yaml')])

    # Wait for pods
    run_command([
        "kubectl", "wait", "--for=condition=Ready", "pods", "--all",
        "--all-namespaces", "--timeout=300s"
    ])

    # Activate Felix
    run_command(
        """kubectl exec -i -n kube-system calicoctl -- /calicoctl patch felixConfiguration
        default --patch '{"spec":{"prometheusMetricsEnabled": true}}'""")
Пример #2
0
    def test_no_matches(self):
        compose_file = os.path.join(DOCKER_DIR, 'test_default.yaml')
        run_command(['docker-compose', '-f', compose_file, 'down'])
        check_docker_logs = CheckDockerLogs(compose_file, 'Vault server started', attempts=1)

        with pytest.raises(RetryError):
            check_docker_logs()
Пример #3
0
    def test_up(self):
        compose_file = os.path.join(DOCKER_DIR, 'test_default.yaml')

        try:
            run_command(['docker-compose', '-f', compose_file, 'up', '-d'], check=True)
            assert compose_file_active(compose_file) is True
        finally:
            run_command(['docker-compose', '-f', compose_file, 'down'], capture=True)
Пример #4
0
    def test_matches(self):
        compose_file = os.path.join(DOCKER_DIR, 'test_default.yaml')
        check_docker_logs = CheckDockerLogs(compose_file, 'Vault server started')

        try:
            run_command(['docker-compose', '-f', compose_file, 'up', '-d'], check=True)
            check_docker_logs()
        finally:
            run_command(['docker-compose', '-f', compose_file, 'down'], capture=True)
Пример #5
0
    def test_compose_file(self):
        compose_file = os.path.join(DOCKER_DIR, 'test_default.yaml')

        try:
            with docker_run(compose_file):
                assert compose_file_active(compose_file) is True
            assert compose_file_active(compose_file) is False
        finally:
            run_command(['docker-compose', '-f', compose_file, 'down'], capture=True)
Пример #6
0
    def __call__(self):
        # type: () -> Any
        result = run_command(
            ['docker', 'network', 'inspect', self._network_name], capture=True)
        network_exists = result.code == 0
        if not network_exists:
            run_command(['docker', 'network', 'create', self._network_name],
                        check=True)

        return self._compose_file_up()
Пример #7
0
def test_new_check_test():
    check_path = os.path.join(CORE_ROOT, 'my_check')

    try:
        run_command(
            [sys.executable, '-m', 'datadog_checks.dev', 'create', '-q', '-l', CORE_ROOT, 'my-check'],
            capture=True,
            check=True
        )
        run_command(
            [sys.executable, '-m', 'pip', 'install', check_path],
            capture=True,
            check=True
        )

        with chdir(check_path):
            run_command([sys.executable, '-m', 'pytest'], capture=True, check=True)

        run_command(
            [sys.executable, '-m', 'pip', 'uninstall', '-y', 'my-check'],
            capture=True,
            check=True
        )
    finally:
        remove_path(check_path)
Пример #8
0
    def test_output(self):
        result = run_command(
            '{} -c "import sys;print(sys.version)"'.format(sys.executable),
            capture='out'
        )

        assert result.stdout.strip() == sys.version.strip()
def dd_environment():
    compose_file = os.path.join(HERE, 'compose', 'docker-compose.yaml')
    # We need a custom condition to wait a bit longer
    condition = CheckDockerLogs(compose_file, 'spawning ceph --cluster ceph -w', wait=5)
    with docker_run(
        compose_file=compose_file,
        conditions=[condition],
        sleep=5,  # Let's wait just a little bit after ceph got spawned to remove flakyness
    ):
        # Clean the disk space warning
        run_command(
            ['docker', 'exec', 'dd-test-ceph', 'ceph', 'tell', 'mon.*', 'injectargs', '--mon_data_avail_warn', '5']
        )
        # Wait a bit for the change to take effect
        time.sleep(5)
        yield BASIC_CONFIG, E2E_METADATA
Пример #10
0
def run_cmd(cmd):
    r = run_command(cmd, True)
    echo_info(f'Command: {cmd}')
    if r.stdout:
        echo_info(f'stdout: {r.stdout}', True)
    if r.stderr:
        echo_warning(f'stderr: {r.stderr}', True)
    echo_info('')
Пример #11
0
    def test_env(self):
        env = dict(os.environ)
        env['DDEV_ENV_VAR'] = 'is_set'
        result = run_command(
            '{} -c "import os;print(os.getenv(\'DDEV_ENV_VAR\'))"'.format(
                sys.executable),
            capture='out',
            env=env)

        assert result.stdout.strip() == 'is_set'
Пример #12
0
def dd_environment():
    compose_file = os.path.join(HERE, 'compose', 'docker-compose.yaml')
    # We need a custom condition to wait a bit longer
    with docker_run(
            compose_file=compose_file,
            conditions=[
                CheckDockerLogs(compose_file,
                                'spawning ceph --cluster ceph -w',
                                wait=5),
                CheckDockerLogs(compose_file,
                                'Running on http://0.0.0.0:5000/'),
            ],
    ):
        # Clean the disk space warning
        run_command([
            'docker', 'exec', 'dd-test-ceph', 'ceph', 'tell', 'mon.*',
            'injectargs', '--mon_data_avail_warn', '5'
        ])
        # Wait a bit for the change to take effect
        condition = CheckDockerLogs(compose_file, 'Cluster is now healthy')
        condition()
        yield BASIC_CONFIG, E2E_METADATA
Пример #13
0
def verify_branch():
    os.chdir(EXTRAS_REPO)
    r = run_command('/usr/local/bin/git branch --show-current', True)
    branch = r.stdout.strip()
    if branch == 'master':
        abort('Change your branch!')
Пример #14
0
    def test_output(self):
        result = run_command(
            [sys.executable, '-c', 'import sys;print(sys.version)'],
            capture='out')

        assert result.stdout.strip() == sys.version.strip()
Пример #15
0
 def __call__(self):
     # type: () -> Any
     run_command(['docker', 'stop'] + self._stop_extra_containers,
                 check=True)
     return self._compose_file_down()
Пример #16
0
    def test_down(self):
        compose_file = os.path.join(DOCKER_DIR, 'test_default.yaml')
        run_command(['docker-compose', '-f', compose_file, 'down'],
                    capture=True)

        assert compose_file_active(compose_file) is False
Пример #17
0
def setup_istio():
    run_command([
        "curl",
        "-o",
        "istio.tar.gz",
        "-L",
        "https://github.com/istio/istio/releases/download/{version}/istio-{version}-linux.tar.gz"
        .format(version=VERSION),
    ])
    run_command(["tar", "xf", "istio.tar.gz"])
    run_command(["kubectl", "create", "ns", "istio-system"])
    # Istio directory name
    istio = "istio-{}".format(VERSION)
    # Install demo profile
    run_command(
        ["kubectl", "apply", "-f",
         opj(HERE, 'kind', "demo_profile.yaml")])
    # Wait for istio deployments
    run_command([
        "kubectl", "wait", "deployments", "--all", "--for=condition=Available",
        "-n", "istio-system", "--timeout=300s"
    ])
    # Enable sidecar injection
    run_command([
        "kubectl", "label", "namespace", "default", "istio-injection=enabled"
    ])
    # Install sample application
    run_command([
        "kubectl", "apply", "-f",
        opj(istio, "samples", "bookinfo", "platform", "kube", "bookinfo.yaml")
    ])
    run_command([
        "kubectl", "wait", "pods", "--all", "--for=condition=Ready",
        "--timeout=300s"
    ])

    run_command([
        "kubectl", "apply", "-f",
        opj(istio, "samples", "bookinfo", "networking",
            "bookinfo-gateway.yaml")
    ])
    run_command([
        "kubectl", "wait", "pods", "--all", "--for=condition=Ready",
        "--timeout=300s"
    ])