Skip to content

Commit

Permalink
Update vs backup service tests with retries (#4797)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaun-nx authored Dec 14, 2023
1 parent 4a9832a commit 4670aca
Showing 1 changed file with 55 additions and 22 deletions.
77 changes: 55 additions & 22 deletions tests/suite/test_virtual_server_backup_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
scale_deployment,
wait_before_test,
)
from suite.utils.vs_vsr_resources_utils import patch_virtual_server_from_yaml
from suite.utils.vs_vsr_resources_utils import delete_and_create_vs_from_yaml


def make_request(url, host):
Expand All @@ -28,6 +28,24 @@ def make_request(url, host):
)


def get_result_in_conf_with_retry(
kube_apis_v1, expected_conf_line, external_host, vs_name, vs_namespace, ic_pod_name, ic_pod_namespace
):
retry = 0
result_conf = ""
while (expected_conf_line not in result_conf) and retry < 5:
wait_before_test()
result_conf = get_vs_nginx_template_conf(
kube_apis_v1,
vs_namespace,
vs_name,
ic_pod_name,
ic_pod_namespace,
)
retry = +1
return result_conf


class ExternalNameSetup:
"""Encapsulate ExternalName example details.
Expand Down Expand Up @@ -124,7 +142,7 @@ def test_get_response_from_application(
vs_externalname_setup,
) -> None:
vs_backup_service = f"{TEST_DATA}/virtual-server-backup-service/virtual-server-backup.yaml"
patch_virtual_server_from_yaml(
delete_and_create_vs_from_yaml(
kube_apis.custom_objects,
virtual_server_setup.vs_name,
vs_backup_service,
Expand All @@ -143,16 +161,19 @@ def test_get_response_from_application(
assert "backend1-" in res.text
assert "external-backend" not in res.text

result_conf = get_vs_nginx_template_conf(
expected_conf_line = f"server {vs_externalname_setup.external_host}:80 backup resolve;"
result_conf = get_result_in_conf_with_retry(
kube_apis.v1,
virtual_server_setup.namespace,
expected_conf_line,
vs_externalname_setup.external_host,
virtual_server_setup.vs_name,
virtual_server_setup.namespace,
vs_externalname_setup.ic_pod_name,
ingress_controller_prerequisites.namespace,
)

assert "least_conn;" in result_conf
assert f"server {vs_externalname_setup.external_host}:80 backup resolve;" in result_conf
assert expected_conf_line in result_conf

"""
This test validates that we get a response back from the backup service.
Expand All @@ -168,7 +189,7 @@ def test_get_response_from_backup(
vs_externalname_setup,
) -> None:
vs_backup_service = f"{TEST_DATA}/virtual-server-backup-service/virtual-server-backup.yaml"
patch_virtual_server_from_yaml(
delete_and_create_vs_from_yaml(
kube_apis.custom_objects,
virtual_server_setup.vs_name,
vs_backup_service,
Expand All @@ -187,16 +208,19 @@ def test_get_response_from_backup(
assert "backend1-" in res.text
assert "external-backend" not in res.text

result_conf = get_vs_nginx_template_conf(
expected_conf_line = f"server {vs_externalname_setup.external_host}:80 backup resolve;"
result_conf = get_result_in_conf_with_retry(
kube_apis.v1,
virtual_server_setup.namespace,
expected_conf_line,
vs_externalname_setup.external_host,
virtual_server_setup.vs_name,
virtual_server_setup.namespace,
vs_externalname_setup.ic_pod_name,
ingress_controller_prerequisites.namespace,
)

assert "least_conn;" in result_conf
assert f"server {vs_externalname_setup.external_host}:80 backup resolve;" in result_conf
assert expected_conf_line in result_conf

print("\nStep 3: Scale deployment to zero replicas")
scale_deployment(kube_apis.v1, kube_apis.apps_v1_api, "backend1", virtual_server_setup.namespace, 0)
Expand All @@ -212,16 +236,18 @@ def test_get_response_from_backup(
assert "external-backend" in res_from_backup.text
assert "backend1-" not in res_from_backup.text

result_conf = get_vs_nginx_template_conf(
result_conf = get_result_in_conf_with_retry(
kube_apis.v1,
virtual_server_setup.namespace,
expected_conf_line,
vs_externalname_setup.external_host,
virtual_server_setup.vs_name,
virtual_server_setup.namespace,
vs_externalname_setup.ic_pod_name,
ingress_controller_prerequisites.namespace,
)

assert "least_conn;" in result_conf
assert f"server {vs_externalname_setup.external_host}:80 backup resolve;" in result_conf
assert expected_conf_line in result_conf

print("\nStep 5: Scale deployment back to 2 replicas")
scale_deployment(kube_apis.v1, kube_apis.apps_v1_api, "backend1", virtual_server_setup.namespace, 2)
Expand All @@ -237,16 +263,18 @@ def test_get_response_from_backup(
assert "external-backend" not in res_after_scaleup.text
assert "backend1-" in res_after_scaleup.text

result_conf = get_vs_nginx_template_conf(
result_conf = get_result_in_conf_with_retry(
kube_apis.v1,
virtual_server_setup.namespace,
expected_conf_line,
vs_externalname_setup.external_host,
virtual_server_setup.vs_name,
virtual_server_setup.namespace,
vs_externalname_setup.ic_pod_name,
ingress_controller_prerequisites.namespace,
)

assert "least_conn;" in result_conf
assert f"server {vs_externalname_setup.external_host}:80 backup resolve;" in result_conf
assert expected_conf_line in result_conf

"""
This test validates that getting an error response after deleting the backup service.
Expand All @@ -261,7 +289,7 @@ def test_delete_backup_service(
vs_externalname_setup,
) -> None:
vs_backup_service = f"{TEST_DATA}/virtual-server-backup-service/virtual-server-backup.yaml"
patch_virtual_server_from_yaml(
delete_and_create_vs_from_yaml(
kube_apis.custom_objects,
virtual_server_setup.vs_name,
vs_backup_service,
Expand All @@ -280,16 +308,19 @@ def test_delete_backup_service(
assert "backend1-" in res.text
assert "external-backend" not in res.text

result_conf = get_vs_nginx_template_conf(
expected_conf_line = f"server {vs_externalname_setup.external_host}:80 backup resolve;"
result_conf = get_result_in_conf_with_retry(
kube_apis.v1,
virtual_server_setup.namespace,
expected_conf_line,
vs_externalname_setup.external_host,
virtual_server_setup.vs_name,
virtual_server_setup.namespace,
vs_externalname_setup.ic_pod_name,
ingress_controller_prerequisites.namespace,
)

assert "least_conn;" in result_conf
assert f"server {vs_externalname_setup.external_host}:80 backup resolve;" in result_conf
assert expected_conf_line in result_conf

print("\nStep 3: Scale deployment to zero replicas")
scale_deployment(kube_apis.v1, kube_apis.apps_v1_api, "backend1", virtual_server_setup.namespace, 0)
Expand All @@ -305,16 +336,18 @@ def test_delete_backup_service(
assert "external-backend" in res_from_backup.text
assert "backend1-" not in res_from_backup.text

result_conf = get_vs_nginx_template_conf(
result_conf = get_result_in_conf_with_retry(
kube_apis.v1,
virtual_server_setup.namespace,
expected_conf_line,
vs_externalname_setup.external_host,
virtual_server_setup.vs_name,
virtual_server_setup.namespace,
vs_externalname_setup.ic_pod_name,
ingress_controller_prerequisites.namespace,
)

assert "least_conn;" in result_conf
assert f"server {vs_externalname_setup.external_host}:80 backup resolve;" in result_conf
assert expected_conf_line in result_conf

print("\nStep 5: Delete backup service by deleting the namespace")
delete_namespace(kube_apis.v1, "external-ns")
Expand Down

0 comments on commit 4670aca

Please sign in to comment.