Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve host collisions in VirtualServer and Ingresses #1178

Merged
merged 3 commits into from
Oct 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update python tests
pleshakov committed Oct 6, 2020
commit dd7abbbe60d9ff861b757b00e26b15df507bbeed
20 changes: 20 additions & 0 deletions tests/suite/custom_assertions.py
Original file line number Diff line number Diff line change
@@ -47,6 +47,26 @@ def assert_event_and_count(event_text, count, events_list) -> None:
pytest.fail(f"Failed to find the event \"{event_text}\" in the list. Exiting...")


def assert_event_with_full_equality_and_count(event_text, count, events_list) -> None:
"""
Search for the event in the list and compare its counter with an expected value.

:param event_text: event text
:param count: expected value
:param events_list: list of events
:return:
"""

for i in range(len(events_list) - 1, -1, -1):
# some events have trailing whitespace
message_stripped = events_list[i].message.rstrip()

if event_text == message_stripped:
assert events_list[i].count == count
return
pytest.fail(f"Failed to find the event \"{event_text}\" in the list. Exiting...")


def assert_event_and_get_count(event_text, events_list) -> int:
"""
Search for the event in the list and return its counter.
2 changes: 1 addition & 1 deletion tests/suite/test_ac_policies.py
Original file line number Diff line number Diff line change
@@ -354,7 +354,7 @@ def test_deleted_policy(
assert resp.status_code == 500 and "500 Internal Server Error" in resp.text
assert (
vs_info["status"]["state"] == "Warning"
and vs_info["status"]["reason"] == "UpdatedWithWarning"
and vs_info["status"]["reason"] == "AddedOrUpdatedWithWarning"
)

def test_route_override_spec(
8 changes: 4 additions & 4 deletions tests/suite/test_annotations.py
Original file line number Diff line number Diff line change
@@ -101,13 +101,13 @@ def annotations_setup(request,
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
upstream_names = []
if request.param == 'mergeable':
event_text = f"Configuration for {test_namespace}/{ingress_name}(Master) was added or updated"
error_text = f"{event_text} but was not applied: Error reloading NGINX"
event_text = f"Configuration for {test_namespace}/{ingress_name} was added or updated"
error_text = f"{event_text} ; but was not applied: Error reloading NGINX"
for minion in minions_info:
upstream_names.append(f"{test_namespace}-{minion['name']}-{ingress_host}-{minion['svc_name']}-80")
else:
event_text = f"Configuration for {test_namespace}/{ingress_name} was added or updated"
error_text = f"{event_text}, but not applied: Error reloading NGINX"
error_text = f"{event_text} ; but was not applied: Error reloading NGINX"
upstream_names.append(f"{test_namespace}-{ingress_name}-{ingress_host}-backend1-svc-80")
upstream_names.append(f"{test_namespace}-{ingress_name}-{ingress_host}-backend2-svc-80")

@@ -147,7 +147,7 @@ def annotations_grpc_setup(request,
f"{TEST_DATA}/common/configmap-with-grpc.yaml")
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
event_text = f"Configuration for {test_namespace}/{ingress_name} was added or updated"
error_text = f"{event_text}, but not applied: Error reloading NGINX"
error_text = f"{event_text} ; but was not applied: Error reloading NGINX"

def fin():
print("Clean up gRPC Annotations Example:")
4 changes: 2 additions & 2 deletions tests/suite/test_app_protect.py
Original file line number Diff line number Diff line change
@@ -88,13 +88,13 @@ def backend_setup(request, kube_apis, ingress_controller_endpoint, test_namespac

def fin():
print("Clean up:")
src_ing_yaml = f"{TEST_DATA}/appprotect/appprotect-ingress.yaml"
delete_items_from_yaml(kube_apis, src_ing_yaml, test_namespace)
delete_ap_policy(kube_apis.custom_objects, pol_name, test_namespace)
delete_ap_logconf(kube_apis.custom_objects, log_name, test_namespace)
delete_common_app(kube_apis, "simple", test_namespace)
src_sec_yaml = f"{TEST_DATA}/appprotect/appprotect-secret.yaml"
delete_items_from_yaml(kube_apis, src_sec_yaml, test_namespace)
src_ing_yaml = f"{TEST_DATA}/appprotect/appprotect-ingress.yaml"
delete_items_from_yaml(kube_apis, src_ing_yaml, test_namespace)

request.addfinalizer(fin)

49 changes: 29 additions & 20 deletions tests/suite/test_v_s_route.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@
from kubernetes.client.rest import ApiException

from settings import TEST_DATA
from suite.custom_assertions import assert_event_and_count, assert_event_and_get_count
from suite.custom_assertions import assert_event_and_count, assert_event_and_get_count, \
assert_event_with_full_equality_and_count
from suite.custom_resources_utils import create_virtual_server_from_yaml, \
delete_virtual_server, create_v_s_route_from_yaml, delete_v_s_route, get_vs_nginx_template_conf, \
patch_v_s_route_from_yaml
@@ -51,6 +52,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
vsr_2_name = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
vsr_1_event_text = f"Configuration for {vsr_1_name} was added or updated"
vs_event_text = f"Configuration for {vs_name} was added or updated"
vs_warning_event_text = f"Configuration for {vs_name} was added or updated with warning(s): VirtualServerRoute {vsr_1_name} doesn't exist or invalid"
vsr_2_event_text = f"Configuration for {vsr_2_name} was added or updated"
initial_config = get_vs_nginx_template_conf(kube_apis.v1,
v_s_route_setup.namespace,
@@ -91,7 +93,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 1, events_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 1, events_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 1, events_ns_1)
# 2nd VSRoute gets an event about update too
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 1, events_ns_2)

@@ -111,7 +113,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 2, events_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 2, events_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 2, events_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 2, events_ns_2)

print("\nStep 4: update one backend service port and check")
@@ -128,7 +130,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 3, events_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 3, events_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 3, events_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 3, events_ns_2)

print("\nStep 5: restore backend service and check")
@@ -145,7 +147,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 4, events_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 4, events_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 4, events_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 4, events_ns_2)

print("\nStep 6: remove VSRoute and check")
@@ -169,7 +171,9 @@ def test_responses_and_events_in_flow(self, kube_apis,
events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_locations_not_in_config(new_config, v_s_route_setup.route_m.paths)
assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 4, events_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 5, events_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 4, events_ns_1)
# a warning event because the VS references a non-existing VSR
assert_event_with_full_equality_and_count(vs_warning_event_text, 1, events_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 5, events_ns_2)

print("\nStep 7: restore VSRoute and check")
@@ -193,7 +197,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_locations_in_config(new_config, v_s_route_setup.route_m.paths)
assert_event_and_count(vsr_1_event_text, 1, events_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 6, events_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 5, events_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 6, events_ns_2)

print("\nStep 8: remove one backend service and check")
@@ -211,7 +215,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_event_and_count(vsr_1_event_text, 2, events_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 7, events_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 6, events_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 7, events_ns_2)

print("\nStep 9: restore backend service and check")
@@ -227,7 +231,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_event_and_count(vsr_1_event_text, 3, events_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 8, events_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 7, events_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 8, events_ns_2)

print("\nStep 10: remove VS and check")
@@ -245,7 +249,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
list0_list_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
list0_list_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_event_and_count(vsr_1_event_text, 3, list0_list_ns_1)
assert_event_and_count(vs_event_text, initial_count_vs + 8, list0_list_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 7, list0_list_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 8, list0_list_ns_2)

print("\nStep 11: restore VS and check")
@@ -263,7 +267,7 @@ def test_responses_and_events_in_flow(self, kube_apis,
list1_list_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
list1_list_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_event_and_count(vsr_1_event_text, 4, list1_list_ns_1)
assert_event_and_count(vs_event_text, 1, list1_list_ns_1)
assert_event_with_full_equality_and_count(vs_event_text, 1, list1_list_ns_1)
assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 9, list1_list_ns_2)


@@ -291,9 +295,7 @@ def test_vsr_without_vs(self, kube_apis,
ingress_controller_prerequisites.namespace)
new_list_ns_3 = get_events(kube_apis.v1, test_namespace)
assert_locations_not_in_config(new_config, vsr_paths)
assert_event_and_count(f"No VirtualServer references VirtualServerRoute {test_namespace}/{vsr_name}",
1,
new_list_ns_3)
assert_event_and_count(f"VirtualServer {v_s_route_setup.namespace}/{v_s_route_setup.vs_name} ignores VirtualServerRoute", 1, new_list_ns_3)

@pytest.mark.parametrize("route_yaml", [f"{TEST_DATA}/virtual-server-route/route-single-invalid-host.yaml",
f"{TEST_DATA}/virtual-server-route/route-single-duplicate-path.yaml"])
@@ -317,12 +319,19 @@ def test_make_existing_vsr_invalid(self, kube_apis,
new_vsr_events = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
assert_locations_not_in_config(new_config, v_s_route_setup.route_s.paths)
text = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
assert_event_and_count(f"Ignored VirtualServerRoute {text}",
assert_event_and_count(f"Configuration for {v_s_route_setup.namespace}/{v_s_route_setup.vs_name} was added or updated with warning(s)",
1,
new_vs_events)
assert_event_and_count(f"Ignored by VirtualServer {v_s_route_setup.namespace}/{v_s_route_setup.vs_name}",
1,
new_vsr_events)

if route_yaml == f"{TEST_DATA}/virtual-server-route/route-single-invalid-host.yaml":
assert_event_and_count(f"VirtualServer is invalid or doesn't exist",
1,
new_vsr_events)
else:
assert_event_and_count(f"VirtualServerRoute {text} was rejected with error",
1,
new_vsr_events)


def test_openapi_validation_flow(self, kube_apis, ingress_controller_prerequisites,
crd_ingress_controller, v_s_route_setup):
@@ -367,8 +376,8 @@ def test_create_invalid_vsr(self, kube_apis,
route_yaml = f"{TEST_DATA}/virtual-server-route/route-single-duplicate-path.yaml"
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
text = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
vs_event_text = f"Ignored VirtualServerRoute {text}: spec.subroutes[1].path: Duplicate value: \"/backend2\""
vsr_event_text = f"Ignored by VirtualServer {v_s_route_setup.namespace}/{v_s_route_setup.vs_name}"
vs_event_text = f"Configuration for {v_s_route_setup.namespace}/{v_s_route_setup.vs_name} was added or updated with warning(s)"
vsr_event_text = f"VirtualServerRoute {text} was rejected with error: spec.subroutes[1].path: Duplicate value: \"/backend2\""
delete_v_s_route(kube_apis.custom_objects,
v_s_route_setup.route_s.name,
v_s_route_setup.route_s.namespace)
2 changes: 1 addition & 1 deletion tests/suite/test_v_s_route_canned_responses.py
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ def test_validation_flow(self, kube_apis, crd_ingress_controller, v_s_route_setu
req_host = f"{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}"
req_url = f"http://{req_host}{v_s_route_setup.route_s.paths[0]}"
text = f"{v_s_route_setup.namespace}/{v_s_route_setup.route_m.name}"
vsr_m_event_text = f"VirtualServerRoute {text} is invalid and was rejected: "
vsr_m_event_text = f"VirtualServerRoute {text} was rejected with error:"
vsr_src = f"{TEST_DATA}/virtual-server-route-canned-responses/route-multiple-invalid.yaml"
patch_v_s_route_from_yaml(kube_apis.custom_objects,
v_s_route_setup.route_m.name, vsr_src, v_s_route_setup.namespace)
4 changes: 2 additions & 2 deletions tests/suite/test_v_s_route_error_pages.py
Original file line number Diff line number Diff line change
@@ -73,8 +73,8 @@ def test_validation_event_flow(self, kube_apis, ingress_controller_prerequisites
]
text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
vsr_s_event_text = f"VirtualServerRoute {text_s} is invalid and was rejected: "
vsr_m_event_text = f"VirtualServerRoute {text_m} is invalid and was rejected: "
vsr_s_event_text = f"VirtualServerRoute {text_s} was rejected with error:"
vsr_m_event_text = f"VirtualServerRoute {text_m} was rejected with error:"
patch_v_s_route_from_yaml(kube_apis.custom_objects,
v_s_route_setup.route_s.name,
f"{TEST_DATA}/virtual-server-route-error-pages/route-single-invalid.yaml",
10 changes: 4 additions & 6 deletions tests/suite/test_v_s_route_externalname.py
Original file line number Diff line number Diff line change
@@ -136,13 +136,13 @@ def test_events_flows(self, kube_apis,
text_vsr = f"{vsr_externalname_setup.route.namespace}/{vsr_externalname_setup.route.name}"
text_vs = f"{vsr_externalname_setup.namespace}/{vsr_externalname_setup.vs_name}"
vsr_event_text = f"Configuration for {text_vsr} was added or updated"
vsr_event_warning_text = f"Configuration for {text_vsr} was added or updated with warning(s):"
vs_event_text = f"Configuration for {text_vs} was added or updated"
vs_event_update_text = f"Configuration for {text_vs} was updated"
wait_before_test(5)
initial_events = get_events(kube_apis.v1, vsr_externalname_setup.route.namespace)
initial_count_vsr = assert_event_and_get_count(vsr_event_text, initial_events)
initial_warning_count_vsr = assert_event_and_get_count(vsr_event_warning_text, initial_events)
initial_count_vs = assert_event_and_get_count(vs_event_text, initial_events)
initial_count_vs_up = assert_event_and_get_count(vs_event_update_text, initial_events)

print("Step 1: Update external host in externalName service")
external_svc = read_service(kube_apis.v1, vsr_externalname_setup.external_svc, vsr_externalname_setup.namespace)
@@ -156,16 +156,14 @@ def test_events_flows(self, kube_apis,
events_step_1 = get_events(kube_apis.v1, vsr_externalname_setup.route.namespace)
assert_event_and_count(vsr_event_text, initial_count_vsr + 1, events_step_1)
assert_event_and_count(vs_event_text, initial_count_vs + 1, events_step_1)
assert_event_and_count(vs_event_update_text, initial_count_vs_up, events_step_1)

print("Step 2: Remove resolver from ConfigMap to trigger an error")
vsr_event_warning_text = f"Configuration for {text_vsr} was updated with warning(s):"
config_map_name = ingress_controller_prerequisites.config_map["metadata"]["name"]
replace_configmap(kube_apis.v1, config_map_name,
ingress_controller_prerequisites.namespace,
ingress_controller_prerequisites.config_map)
wait_before_test(5)

events_step_2 = get_events(kube_apis.v1, vsr_externalname_setup.route.namespace)
assert_event_and_count(vsr_event_warning_text, 1, events_step_2)
assert_event_and_count(vs_event_update_text, initial_count_vs_up + 1, events_step_2)
assert_event_and_count(vsr_event_warning_text, initial_warning_count_vsr + 1, events_step_2)
assert_event_and_count(vs_event_text, initial_count_vs + 2, events_step_2)
2 changes: 1 addition & 1 deletion tests/suite/test_v_s_route_redirects.py
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ def test_validation_flow(self, kube_apis, crd_ingress_controller, v_s_route_setu
req_host = f"{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}"
req_url = f"http://{req_host}{v_s_route_setup.route_s.paths[0]}"
text = f"{v_s_route_setup.namespace}/{v_s_route_setup.route_m.name}"
event_text = f"VirtualServerRoute {text} is invalid and was rejected: "
event_text = f"VirtualServerRoute {text} was rejected with error:"
invalid_fields = [
"spec.subroutes[0].action.redirect.code", "spec.subroutes[1].action.redirect.url"
]
7 changes: 3 additions & 4 deletions tests/suite/test_v_s_route_regexp_location.py
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ def test_flow_for_invalid_vs(self, kube_apis,
v_s_route_setup, v_s_route_app_setup):
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
text_vs = f"{v_s_route_setup.namespace}/{v_s_route_setup.vs_name}"
vs_event_text = f'VirtualServer {text_vs} is invalid and was rejected: ' \
vs_event_text = f'VirtualServer {text_vs} was rejected with error: ' \
f'spec.routes[1].path: Duplicate value: "=/exact-match$request"'
vs_src_yaml = f"{TEST_DATA}" \
f"/virtual-server-route-regexp-location/standard/virtual-server-invalid-duplicate-routes.yaml"
@@ -80,9 +80,8 @@ def test_flow_for_invalid_vsr(self, kube_apis,
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
text_vs = f"{v_s_route_setup.namespace}/{v_s_route_setup.vs_name}"
text_vsr_s = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
vs_event_text = f'Ignored by VirtualServer {text_vs}: spec.subroutes: Invalid value: "subroutes": ' \
f'must have only one subroute if regex match or exact match are being used'
vsr_event_text = f'VirtualServerRoute {text_vsr_s} is invalid and was rejected: ' \
vs_event_text = f'Configuration for {text_vs} was added or updated with warning(s)'
vsr_event_text = f'VirtualServerRoute {text_vsr_s} was rejected with error: ' \
f'spec.subroutes[1].path: Duplicate value: "=/backends/exact-match$request"'
vs_src_yaml = f"{TEST_DATA}" \
f"/virtual-server-route-regexp-location/standard/virtual-server-exact.yaml"
22 changes: 11 additions & 11 deletions tests/suite/test_v_s_route_status.py
Original file line number Diff line number Diff line change
@@ -126,14 +126,14 @@ def test_status_invalid(
assert (
response_m["status"]
and response_m["status"]["reason"] == "Rejected"
and response_m["status"]["referencedBy"]
and not response_m["status"]["referencedBy"]
and response_m["status"]["state"] == "Invalid"
)

assert (
response_s["status"]
and response_s["status"]["reason"] == "Rejected"
and response_s["status"]["referencedBy"]
and not response_s["status"]["referencedBy"]
and response_s["status"]["state"] == "Invalid"
)

@@ -184,9 +184,9 @@ def test_status_invalid_prefix(

assert (
response_s["status"]
and response_s["status"]["reason"] == "AddedOrUpdated"
and response_s["status"]["referencedBy"]
and response_s["status"]["state"] == "Valid"
and response_s["status"]["reason"] == "Ignored"
and not response_s["status"]["referencedBy"]
and response_s["status"]["state"] == "Warning"
)

def test_status_invalid_vsr_in_vs(
@@ -217,16 +217,16 @@ def test_status_invalid_vsr_in_vs(
self.patch_valid_vs(kube_apis, v_s_route_setup)
assert (
response_m["status"]
and response_m["status"]["reason"] == "NoVirtualServerFound"
and response_m["status"]["reason"] == "Ignored"
and not response_m["status"]["referencedBy"]
and response_m["status"]["state"] == "Invalid"
and response_m["status"]["state"] == "Warning"
)

assert (
response_s["status"]
and response_s["status"]["reason"] == "NoVirtualServerFound"
and response_s["status"]["reason"] == "Ignored"
and not response_s["status"]["referencedBy"]
and response_s["status"]["state"] == "Invalid"
and response_s["status"]["state"] == "Warning"
)

def test_status_remove_vs(
@@ -259,12 +259,12 @@ def test_status_remove_vs(
response_m["status"]
and response_m["status"]["reason"] == "NoVirtualServerFound"
and not response_m["status"]["referencedBy"]
and response_m["status"]["state"] == "Invalid"
and response_m["status"]["state"] == "Warning"
)

assert (
response_s["status"]
and response_s["status"]["reason"] == "NoVirtualServerFound"
and not response_s["status"]["referencedBy"]
and response_s["status"]["state"] == "Invalid"
and response_s["status"]["state"] == "Warning"
)
8 changes: 4 additions & 4 deletions tests/suite/test_v_s_route_upstream_options.py
Original file line number Diff line number Diff line change
@@ -283,8 +283,8 @@ def test_event_message_and_config(self, kube_apis, ingress_controller_prerequisi
]
text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
vsr_s_event_text = f"VirtualServerRoute {text_s} is invalid and was rejected: "
vsr_m_event_text = f"VirtualServerRoute {text_m} is invalid and was rejected: "
vsr_s_event_text = f"VirtualServerRoute {text_s} was rejected with error:"
vsr_m_event_text = f"VirtualServerRoute {text_m} was rejected with error:"
patch_v_s_route_from_yaml(kube_apis.custom_objects,
v_s_route_setup.route_s.name,
f"{TEST_DATA}/virtual-server-route-upstream-options/route-single-invalid-keys.yaml",
@@ -508,8 +508,8 @@ def test_validation_flow(self, kube_apis, ingress_controller_prerequisites,
]
text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
vsr_s_event_text = f"VirtualServerRoute {text_s} is invalid and was rejected: "
vsr_m_event_text = f"VirtualServerRoute {text_m} is invalid and was rejected: "
vsr_s_event_text = f"VirtualServerRoute {text_s} was rejected with error:"
vsr_m_event_text = f"VirtualServerRoute {text_m} was rejected with error:"
patch_v_s_route_from_yaml(kube_apis.custom_objects,
v_s_route_setup.route_s.name,
f"{TEST_DATA}/virtual-server-route-upstream-options/plus-route-s-invalid-keys.yaml",
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_canned_responses.py
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ def test_validation_flow(self, kube_apis, crd_ingress_controller, virtual_server
"spec.routes[0].action.return.code", "spec.routes[0].action.return.body"
]
text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
vs_event_text = f"VirtualServer {text} is invalid and was rejected: "
vs_event_text = f"VirtualServer {text} was rejected with error:"
vs_src = f"{TEST_DATA}/virtual-server-canned-responses/virtual-server-invalid.yaml"
patch_virtual_server_from_yaml(kube_apis.custom_objects, virtual_server_setup.vs_name, vs_src,
virtual_server_setup.namespace)
14 changes: 7 additions & 7 deletions tests/suite/test_virtual_server_configmap_keys.py
Original file line number Diff line number Diff line change
@@ -9,25 +9,25 @@

def assert_update_events_emitted(virtual_server_setup, new_list, previous_list, expected_amount):
item_name = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
text_valid = f"Configuration for {item_name} was updated"
text_invalid = "was updated but was not applied"
text_valid = f"Configuration for {item_name} was added or updated"
text_invalid = "but was not applied"
new_event = new_list[len(new_list) - 1]
assert len(new_list) - len(previous_list) == expected_amount
assert text_valid in new_event.message and text_invalid not in new_event.message


def assert_not_applied_events_emitted(virtual_server_setup, new_list, previous_list, expected_amount):
item_name = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
text_invalid = f"Configuration for {item_name} was updated but was not applied"
text_invalid = f"Configuration for {item_name} was added or updated ; but was not applied"
new_event = new_list[len(new_list) - 1]
assert len(new_list) - len(previous_list) == expected_amount
assert text_invalid in new_event.message


def assert_update_event_count_increased(virtual_server_setup, new_list, previous_list):
item_name = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
text_valid = f"Configuration for {item_name} was updated"
text_invalid = "was updated but was not applied"
text_valid = f"Configuration for {item_name} was added or updated"
text_invalid = "but was not applied"
for i in range(len(previous_list)-1, 0, -1):
if text_valid in previous_list[i].message and text_invalid not in previous_list[i].message:
assert new_list[i].count - previous_list[i].count == 1, "We expect the counter to increase"
@@ -158,7 +158,7 @@ def test_keys(self, cli_arguments, kube_apis, ingress_controller_prerequisites,
virtual_server_setup.vs_name,
ic_pod_name,
ingress_controller_prerequisites.namespace)
assert_update_events_emitted(virtual_server_setup, step_1_events, initial_list, ic_pods_amount)
assert_update_event_count_increased(virtual_server_setup, step_1_events, initial_list)
assert_keys_without_validation(step_1_config, expected_values)

print("Step 2: update ConfigMap with invalid keys without validation rules")
@@ -299,7 +299,7 @@ def test_ssl_keys(self, cli_arguments, kube_apis, ingress_controller_prerequisit
virtual_server_setup.vs_name,
ic_pod_name,
ingress_controller_prerequisites.namespace)
assert_update_events_emitted(virtual_server_setup, step_1_events, initial_list, ic_pods_amount)
assert_update_event_count_increased(virtual_server_setup, step_1_events, initial_list)
assert_ssl_keys(step_1_config)

print("Step 2: update ConfigMap with invalid ssl keys")
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_error_pages.py
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ def test_validation_event_flow(self, kube_apis, ingress_controller_prerequisites
"spec.routes[1].errorPages[0].return.headers[0].value: Invalid value: \"schema\""
]
text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
vs_event_text = f"VirtualServer {text} is invalid and was rejected: "
vs_event_text = f"VirtualServer {text} was rejected with error:"
vs_file = f"{TEST_DATA}/virtual-server-error-pages/virtual-server-invalid.yaml"
patch_virtual_server_from_yaml(kube_apis.custom_objects,
virtual_server_setup.vs_name,
9 changes: 3 additions & 6 deletions tests/suite/test_virtual_server_external_name.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

from settings import TEST_DATA
from suite.custom_assertions import assert_event_and_count, assert_event_and_get_count, wait_and_assert_status_code, \
wait_for_event_count_increases
wait_for_event_count_increases, assert_event_with_full_equality_and_count
from suite.custom_resources_utils import get_vs_nginx_template_conf
from suite.resources_utils import replace_configmap_from_yaml, \
ensure_connection_to_public_endpoint, replace_configmap, create_service_from_yaml, get_first_pod_name, get_events, \
@@ -88,11 +88,9 @@ def test_events_flows(self, kube_apis, ingress_controller_prerequisites,
crd_ingress_controller, virtual_server_setup, vs_externalname_setup):
text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
vs_event_text = f"Configuration for {text} was added or updated"
vs_event_update_text = f"Configuration for {text} was updated"
wait_before_test(5)
events_vs = get_events(kube_apis.v1, virtual_server_setup.namespace)
initial_count = assert_event_and_get_count(vs_event_text, events_vs)
initial_count_up = assert_event_and_get_count(vs_event_update_text, events_vs)

print("Step 1: Update external host in externalName service")
external_svc = read_service(kube_apis.v1, vs_externalname_setup.external_svc, virtual_server_setup.namespace)
@@ -103,16 +101,15 @@ def test_events_flows(self, kube_apis, ingress_controller_prerequisites,
wait_for_event_count_increases(kube_apis, vs_event_text, initial_count, virtual_server_setup.namespace)
events_step_1 = get_events(kube_apis.v1, virtual_server_setup.namespace)
assert_event_and_count(vs_event_text, initial_count + 1, events_step_1)
assert_event_and_count(vs_event_update_text, initial_count_up, events_step_1)

print("Step 2: Remove resolver from ConfigMap to trigger an error")
config_map_name = ingress_controller_prerequisites.config_map["metadata"]["name"]
vs_event_warning_text = f"Configuration for {text} was updated with warning(s):"
vs_event_warning_text = f"Configuration for {text} was added or updated ; with warning(s):"
replace_configmap(kube_apis.v1, config_map_name,
ingress_controller_prerequisites.namespace,
ingress_controller_prerequisites.config_map)
wait_before_test(5)

events_step_2 = get_events(kube_apis.v1, virtual_server_setup.namespace)
assert_event_and_count(vs_event_warning_text, 1, events_step_2)
assert_event_and_count(vs_event_update_text, initial_count_up, events_step_2)
assert_event_with_full_equality_and_count(vs_event_text, initial_count + 1, events_step_2)
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_redirects.py
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ def test_update(self, kube_apis, crd_ingress_controller, virtual_server_setup):

def test_validation_flow(self, kube_apis, crd_ingress_controller, virtual_server_setup):
text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
event_text = f"VirtualServer {text} is invalid and was rejected: "
event_text = f"VirtualServer {text} was rejected with error:"
invalid_fields = ["spec.routes[0].action.redirect.code", "spec.routes[1].action.redirect.url"]
vs_src = f"{TEST_DATA}/virtual-server-redirects/virtual-server-invalid.yaml"
patch_virtual_server_from_yaml(kube_apis.custom_objects, virtual_server_setup.vs_name, vs_src,
8 changes: 4 additions & 4 deletions tests/suite/test_virtual_server_upstream_options.py
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ def test_when_option_in_config_map_only(self, kube_apis, ingress_controller_prer
crd_ingress_controller, virtual_server_setup, restore_configmap,
config_map_file, expected_strings, unexpected_strings):
text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
vs_event_text = f"Configuration for {text} was updated"
vs_event_text = f"Configuration for {text} was added or updated"
print(f"Case 3: key specified in ConfigMap, no option in VS")
patch_virtual_server_from_yaml(kube_apis.custom_objects, virtual_server_setup.vs_name,
f"{TEST_DATA}/virtual-server-upstream-options/standard/virtual-server.yaml",
@@ -233,7 +233,7 @@ def test_event_message_and_config(self, kube_apis, ingress_controller_prerequisi
"upstreams[1].buffers.number", "upstreams[1].buffers.size", "upstreams[1].buffer-size"
]
text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
vs_event_text = f"VirtualServer {text} is invalid and was rejected: "
vs_event_text = f"VirtualServer {text} was rejected with error:"
vs_file = f"{TEST_DATA}/virtual-server-upstream-options/virtual-server-with-invalid-keys.yaml"
patch_virtual_server_from_yaml(kube_apis.custom_objects,
virtual_server_setup.vs_name,
@@ -366,7 +366,7 @@ def test_slow_start_warning(self, kube_apis, ingress_controller_prerequisites,
crd_ingress_controller, virtual_server_setup, options):
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
vs_event_text = f"Configuration for {text} was added or updated with warning(s): Slow start will be disabled"
vs_event_text = f"Configuration for {text} was added or updated ; with warning(s): Slow start will be disabled"
print(f"Case 0: verify a warning")
new_body = generate_item_with_upstream_options(
f"{TEST_DATA}/virtual-server-upstream-options/standard/virtual-server.yaml",
@@ -410,7 +410,7 @@ def test_validation_flow(self, kube_apis, ingress_controller_prerequisites,
"upstreams[1].sessionCookie.expires", "upstreams[1].sessionCookie.domain"
]
text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
vs_event_text = f"VirtualServer {text} is invalid and was rejected: "
vs_event_text = f"VirtualServer {text} was rejected with error:"
vs_file = f"{TEST_DATA}/virtual-server-upstream-options/plus-virtual-server-with-invalid-keys.yaml"
patch_virtual_server_from_yaml(kube_apis.custom_objects,
virtual_server_setup.vs_name,
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_validation.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

def assert_reject_events_emitted(virtual_server_setup, new_list, previous_list, expected_amount):
item_name = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
text_invalid = f"VirtualServer {item_name} is invalid and was rejected"
text_invalid = f"VirtualServer {item_name} was rejected with error"
new_event = new_list[len(new_list) - 1]
assert len(new_list) - len(previous_list) == expected_amount
assert text_invalid in new_event.message