예제 #1
0
    def test_total_metrics(self, crd_ingress_controller, ts_setup,
                           ingress_controller_endpoint, kube_apis,
                           test_namespace, ts):
        """
        Tests nginx_ingress_controller_transportserver_resources_total metric for a given TransportServer type.
        """
        ts_file = ts[0]
        ts_type = ts[1]

        # initially, the number of TransportServers is 0

        assert_ts_total_metric(ingress_controller_endpoint, ts_type, 0)

        # create a TS and check the metric is 1

        ts_resource = create_ts_from_yaml(kube_apis.custom_objects, ts_file,
                                          test_namespace)
        wait_before_test()

        assert_ts_total_metric(ingress_controller_endpoint, ts_type, 1)

        # make the TS invalid and check the metric is 0

        ts_resource["spec"]["listener"]["protocol"] = "invalid"

        patch_ts(kube_apis.custom_objects, test_namespace, ts_resource)
        wait_before_test()

        assert_ts_total_metric(ingress_controller_endpoint, ts_type, 0)

        # restore the TS and check the metric is 1

        patch_ts_from_yaml(kube_apis.custom_objects,
                           ts_resource["metadata"]["name"], ts_file,
                           test_namespace)
        wait_before_test()

        assert_ts_total_metric(ingress_controller_endpoint, ts_type, 1)

        # delete the TS and check the metric is 0

        delete_ts(kube_apis.custom_objects, ts_resource, test_namespace)
        wait_before_test()

        assert_ts_total_metric(ingress_controller_endpoint, ts_type, 0)
예제 #2
0
    def test_tls_passthrough_host_collision_ts(
        self,
        kube_apis,
        crd_ingress_controller,
        transport_server_tls_passthrough_setup,
        test_namespace,
    ):
        """
            Test host collision handling in TransportServer with another TransportServer.
        """
        print("Step 1: Create second TS with same host")
        ts_src_same_host = (
            f"{TEST_DATA}/transport-server-tls-passthrough/transport-server-same-host.yaml"
        )
        ts_same_host = create_ts_from_yaml(kube_apis.custom_objects,
                                           ts_src_same_host, test_namespace)
        wait_before_test()
        response = read_ts(kube_apis.custom_objects, test_namespace,
                           ts_same_host["metadata"]["name"])
        assert (response["status"]["reason"] == "Rejected"
                and response["status"]["message"]
                == "Host is taken by another resource")

        print("Step 2: Delete TS taking up the host")
        delete_ts(
            kube_apis.custom_objects,
            transport_server_tls_passthrough_setup.ts_resource,
            test_namespace,
        )
        wait_before_test(1)
        response = read_ts(kube_apis.custom_objects, test_namespace,
                           ts_same_host["metadata"]["name"])
        assert (response["status"]["reason"] == "AddedOrUpdated"
                and response["status"]["state"] == "Valid")
        print("Step 3: Delete second TS and re-create standard one")
        delete_ts(kube_apis.custom_objects, ts_same_host, test_namespace)
        self.restore_ts(kube_apis, transport_server_tls_passthrough_setup)
        response = read_ts(kube_apis.custom_objects, test_namespace,
                           transport_server_tls_passthrough_setup.name)
        assert (response["status"]["reason"] == "AddedOrUpdated"
                and response["status"]["state"] == "Valid")
예제 #3
0
 def fin():
     print("Clean up TransportServer and app:")
     delete_ts(kube_apis.custom_objects, ts_resource, test_namespace)
     delete_items_from_yaml(kube_apis, secure_app_file, test_namespace)
    def test_tcp_request_load_balanced_multiple(self, kube_apis,
                                                crd_ingress_controller,
                                                transport_server_setup):
        """
        Requests to the load balanced TCP service should result in responses from 3 different endpoints.
        """
        port = transport_server_setup.public_endpoint.tcp_server_port
        host = transport_server_setup.public_endpoint.public_ip

        # Step 1, confirm load balancing is working.
        print(f"sending tcp requests to: {host}:{port}")
        host = host.strip("[]")
        client = socket.create_connection((host, port))
        client.sendall(b'connect')
        response = client.recv(4096)
        endpoint = response.decode()
        print(f'response: {endpoint}')
        client.close()
        assert endpoint is not ""

        # Step 2, add a second TransportServer with the same port and confirm the collision
        transport_server_file = f"{TEST_DATA}/transport-server-tcp-load-balance/second-transport-server.yaml"
        ts_resource = create_ts_from_yaml(kube_apis.custom_objects,
                                          transport_server_file,
                                          transport_server_setup.namespace)
        wait_before_test()

        second_ts_name = ts_resource['metadata']['name']
        response = read_ts(
            kube_apis.custom_objects,
            transport_server_setup.namespace,
            second_ts_name,
        )
        assert (response["status"]
                and response["status"]["reason"] == "Rejected"
                and response["status"]["state"] == "Warning"
                and response["status"]["message"]
                == "Listener tcp-server is taken by another resource")

        # Step 3, remove the default TransportServer with the same port
        delete_ts(kube_apis.custom_objects, transport_server_setup.resource,
                  transport_server_setup.namespace)

        wait_before_test()
        response = read_ts(
            kube_apis.custom_objects,
            transport_server_setup.namespace,
            second_ts_name,
        )
        assert (response["status"]
                and response["status"]["reason"] == "AddedOrUpdated"
                and response["status"]["state"] == "Valid")

        # Step 4, confirm load balancing is still working.
        print(f"sending tcp requests to: {host}:{port}")
        host = host.strip("[]")
        client = socket.create_connection((host, port))
        client.sendall(b'connect')
        response = client.recv(4096)
        endpoint = response.decode()
        print(f'response: {endpoint}')
        client.close()
        assert endpoint is not ""

        # cleanup
        delete_ts(kube_apis.custom_objects, ts_resource,
                  transport_server_setup.namespace)
        transport_server_file = f"{TEST_DATA}/transport-server-tcp-load-balance/standard/transport-server.yaml"
        create_ts_from_yaml(kube_apis.custom_objects, transport_server_file,
                            transport_server_setup.namespace)
        wait_before_test()
예제 #5
0
 def fin():
     print("Clean up TransportServer Example:")
     delete_ts(kube_apis.custom_objects, ts_resource, test_namespace)
     delete_items_from_yaml(kube_apis, service_file, test_namespace)
     delete_gc(kube_apis.custom_objects, gc_resource, "nginx-ingress")