Example #1
0
    def check(self):
        if not parse_bool(
                os.environ.get("AMBASSADOR_PYTEST_INGRESS_TEST", "false")):
            pytest.xfail('AMBASSADOR_PYTEST_INGRESS_TEST not set, xfailing...')

        if sys.platform == 'darwin':
            pytest.xfail('not supported on Darwin')

        for r in self.results:
            if r.backend:
                assert r.backend.name == self.target.path.k8s, (
                    r.backend.name, self.target.path.k8s)
                assert r.backend.request.headers['x-envoy-original-path'][
                    0] == f'/{self.name}/'

        # check for Ingress IP here
        ingress_cmd = [
            "kubectl", "get", "-n", "default", "-o", "json", "ingress",
            self.path.k8s
        ]
        ingress_run = subprocess.Popen(ingress_cmd, stdout=subprocess.PIPE)
        ingress_out, _ = ingress_run.communicate()
        ingress_json = json.loads(ingress_out)
        assert ingress_json[
            'status'] == self.status_update, f"Expected Ingress status to be {self.status_update}, got {ingress_json['status']} instead"
Example #2
0
    def load_secret(self, resource: 'IRResource', secret_name: str,
                    namespace: str) -> Optional[SecretInfo]:
        # Allow an environment variable to state whether we're in Edge Stack. But keep the
        # existing condition as sufficient, so that there is less of a chance of breaking
        # things running in a container with this file present.
        if parse_bool(os.environ.get(
                'EDGE_STACK',
                'false')) or os.path.exists('/ambassador/.edge_stack'):
            if ((secret_name == "fallback-self-signed-cert")
                    and (namespace == Config.ambassador_namespace)):
                # This is Edge Stack. Force the fake TLS secret.

                self.logger.info(
                    f"MockSecretHandler: mocking fallback secret {secret_name}.{namespace}"
                )
                return SecretInfo(secret_name,
                                  namespace,
                                  "mocked-fallback-secret",
                                  "-fallback-cert-",
                                  "-fallback-key-",
                                  decode_b64=False)

        self.logger.debug(
            f"MockSecretHandler: cannot load {secret_name}.{namespace}")
        return None
Example #3
0
def test_knative():
    if not parse_bool(os.environ.get("AMBASSADOR_PYTEST_KNATIVE_TEST",
                                     "false")):
        pytest.xfail("AMBASSADOR_PYTEST_KNATIVE_TEST is not set, xfailing...")

    if is_knative_compatible():
        knative_test = KnativeTesting()
        knative_test.test_knative()
    else:
        pytest.xfail("Knative is not supported")
Example #4
0
    def check(self):
        if not parse_bool(os.environ.get("AMBASSADOR_PYTEST_INGRESS_TEST", "false")):
            pytest.xfail('AMBASSADOR_PYTEST_INGRESS_TEST not set, xfailing...')

        # check for Ingress IP here
        ingress_cmd = ["kubectl", "get", "-n", "default", "-o", "json", "ingress", self.path.k8s]
        ingress_run = subprocess.Popen(ingress_cmd, stdout=subprocess.PIPE)
        ingress_out, _ = ingress_run.communicate()
        ingress_json = json.loads(ingress_out)
        assert ingress_json['status'] == self.status_update, f"Expected Ingress status to be {self.status_update}, got {ingress_json['status']} instead"
Example #5
0
    def check(self):
        if not parse_bool(os.environ.get("AMBASSADOR_PYTEST_INGRESS_TEST", "false")):
            pytest.xfail('AMBASSADOR_PYTEST_INGRESS_TEST not set, xfailing...')

        if False and sys.platform == 'darwin':
            pytest.xfail('not supported on Darwin')

        for namespace in ['same-ingress-1', 'same-ingress-2']:
            # check for Ingress IP here
            ingress_cmd = ["kubectl", "get", "-n", "default", "-o", "json", "ingress", self.path.k8s, "-n", namespace]
            ingress_run = subprocess.Popen(ingress_cmd, stdout=subprocess.PIPE)
            ingress_out, _ = ingress_run.communicate()
            ingress_json = json.loads(ingress_out)
            assert ingress_json['status'] == self.status_update, f"Expected Ingress status to be {self.status_update}, got {ingress_json['status']} instead"
    if arg == '--k8s':
        # Already set up.
        pass
    elif arg == '--watt':
        url_type = 'watt'
    elif arg == '--fs':
        url_type = 'fs'
        arg_key = 'path'
    else:
        usage(program)

if len(args) != 1:
    usage(program)

urls = [ f'{base_host}/{base_path}/{url_type}' ]

if parse_bool(os.environ.get('EDGE_STACK', 'false')) or os.path.exists('/ambassador/.edge_stack'):
    urls.append(f'{sidecar_host}/{sidecar_path}/{url_type}')

exitcode = 0

for url in urls:
    r = requests.post(url, params={ arg_key: args[0] })

    if r.status_code != 200:
        sys.stderr.write("failed to update %s: %d: %s" % (r.url, r.status_code, r.text))
        exitcode = 1

sys.exit(exitcode)