def test_status_invalid( self, kube_apis, crd_ingress_controller, transport_server_setup, ): """ Test TransportServer status with an invalid protocol. """ patch_src = f"{TEST_DATA}/transport-server-status/rejected-invalid.yaml" patch_ts( kube_apis.custom_objects, transport_server_setup.name, patch_src, transport_server_setup.namespace, ) wait_before_test() response = read_ts( kube_apis.custom_objects, transport_server_setup.namespace, transport_server_setup.name, ) self.restore_ts(kube_apis, transport_server_setup) assert (response["status"] and response["status"]["reason"] == "Rejected" and response["status"]["state"] == "Invalid")
def test_status_warning( self, kube_apis, crd_ingress_controller, transport_server_setup, ): """ Test TransportServer status with a missing listener. """ patch_src = f"{TEST_DATA}/transport-server-status/rejected-warning.yaml" patch_ts_from_yaml( kube_apis.custom_objects, transport_server_setup.name, patch_src, transport_server_setup.namespace, ) wait_before_test() response = read_ts( kube_apis.custom_objects, transport_server_setup.namespace, transport_server_setup.name, ) self.restore_ts(kube_apis, transport_server_setup) assert (response["status"] and response["status"]["reason"] == "Rejected" and response["status"]["state"] == "Warning")
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")
def test_status_valid( self, kube_apis, crd_ingress_controller, transport_server_setup, ): """ Test TransportServer status with valid fields in yaml. """ response = read_ts( kube_apis.custom_objects, transport_server_setup.namespace, transport_server_setup.name, ) assert (response["status"] and response["status"]["reason"] == "AddedOrUpdated" and response["status"]["state"] == "Valid")
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()