...

Text file src/github.com/datawire/ambassador/v2/python/tests/kat/t_plain.py

Documentation: github.com/datawire/ambassador/v2/python/tests/kat

     1from typing import Generator, Tuple, Union
     2
     3from abstract_tests import AmbassadorTest, MappingTest, Node
     4from kat.harness import EDGE_STACK, Query, variants
     5from tests.integration.manifests import namespace_manifest
     6
     7# Plain is the place that all the MappingTests get pulled in.
     8
     9
    10class Plain(AmbassadorTest):
    11    single_namespace = True
    12    namespace = "plain-namespace"
    13
    14    @classmethod
    15    def variants(cls) -> Generator[Node, None, None]:
    16        yield cls(variants(MappingTest))
    17
    18    def manifests(self) -> str:
    19        m = (
    20            namespace_manifest("plain-namespace")
    21            + namespace_manifest("evil-namespace")
    22            + """
    23---
    24kind: Service
    25apiVersion: v1
    26metadata:
    27  name: plain-simplemapping-http-all-http
    28  namespace: evil-namespace
    29  annotations:
    30    getambassador.io/config: |
    31      ---
    32      apiVersion: getambassador.io/v3alpha1
    33      kind: Mapping
    34      name: SimpleMapping-HTTP-all
    35      hostname: "*"
    36      prefix: /SimpleMapping-HTTP-all/
    37      service: http://plain-simplemapping-http-all-http.plain
    38      ambassador_id: [plain]
    39      ---
    40      apiVersion: getambassador.io/v3alpha1
    41      kind: Host
    42      name: cleartext-host-{self.path.k8s}
    43      ambassador_id: [ "plain" ]
    44      hostname: "*"
    45      mappingSelector:
    46        matchLabels:
    47          hostname: {self.path.k8s}
    48      acmeProvider:
    49        authority: none
    50      requestPolicy:
    51        insecure:
    52          action: Route
    53          # additionalPort: 8080
    54  labels:
    55    scope: AmbassadorTest
    56spec:
    57  selector:
    58    backend: plain-simplemapping-http-all-http
    59  ports:
    60  - name: http
    61    protocol: TCP
    62    port: 80
    63    targetPort: 8080
    64  - name: https
    65    protocol: TCP
    66    port: 443
    67    targetPort: 8443
    68"""
    69        )
    70
    71        if EDGE_STACK:
    72            m += """
    73---
    74kind: Service
    75apiVersion: v1
    76metadata:
    77  name: cleartext-host-{self.path.k8s}
    78  namespace: plain-namespace
    79  annotations:
    80    getambassador.io/config: |
    81      ---
    82      apiVersion: getambassador.io/v3alpha1
    83      kind: Host
    84      name: cleartext-host-{self.path.k8s}
    85      ambassador_id: [ "plain" ]
    86      hostname: "*"
    87      mappingSelector:
    88        matchLabels:
    89          hostname: {self.path.k8s}
    90      acmeProvider:
    91        authority: none
    92      requestPolicy:
    93        insecure:
    94          action: Route
    95          # Since this is cleartext already, additionalPort: 8080 is technically
    96          # an error. Leave it in to make sure it's a harmless no-op error.
    97          additionalPort: 8080
    98  labels:
    99    scope: AmbassadorTest
   100spec:
   101  selector:
   102    backend: plain-simplemapping-http-all-http
   103  ports:
   104  - name: http
   105    protocol: TCP
   106    port: 80
   107    targetPort: 8080
   108  - name: https
   109    protocol: TCP
   110    port: 443
   111    targetPort: 8443
   112"""
   113
   114        return m + super().manifests()
   115
   116    def config(self) -> Generator[Union[str, Tuple[Node, str]], None, None]:
   117        yield self, """
   118---
   119apiVersion: getambassador.io/v3alpha1
   120kind:  Module
   121name:  ambassador
   122config: {}
   123"""
   124
   125    def queries(self):
   126        yield Query(self.url("ambassador/v0/diag/?json=true&filter=errors"), phase=2)
   127
   128    def check(self):
   129        # XXX Ew. If self.results[0].json is empty, the harness won't convert it to a response.
   130        errors = self.results[0].json
   131
   132        # We shouldn't have any missing-CRD-types errors any more.
   133        for source, error in errors:
   134            if ("could not find" in error) and ("CRD definitions" in error):
   135                assert False, f"Missing CRDs: {error}"
   136
   137            if "Ingress resources" in error:
   138                assert False, f"Ingress resource error: {error}"
   139
   140        # The default errors assume that we have missing CRDs, and that's not correct any more,
   141        # so don't try to use assert_default_errors here.

View as plain text