From 028af0271418b0e00cad7148afd42293c1cdb5ee Mon Sep 17 00:00:00 2001 From: Venktesh Date: Tue, 18 Jun 2024 13:17:06 +0100 Subject: [PATCH 1/2] check pod readiness --- tests/conftest.py | 3 ++- tests/suite/test_rl_ingress.py | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d8edec86da..0885f93611 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,7 +16,7 @@ NS_COUNT, NUM_REPLICAS, ) -from suite.utils.resources_utils import get_first_pod_name +from suite.utils.resources_utils import get_first_pod_name, wait_until_all_pods_are_ready def pytest_addoption(parser) -> None: @@ -200,6 +200,7 @@ def pytest_runtest_makereport(item) -> None: pod_namespace = item.funcargs["ingress_controller_prerequisites"].namespace pod_name = get_first_pod_name(item.funcargs["kube_apis"].v1, pod_namespace) print("\n===================== IC Logs Start =====================") + wait_until_all_pods_are_ready(item.funcargs["kube_apis"].v1, pod_namespace) print(item.funcargs["kube_apis"].v1.read_namespaced_pod_log(pod_name, pod_namespace)) print("\n===================== IC Logs End =====================") diff --git a/tests/suite/test_rl_ingress.py b/tests/suite/test_rl_ingress.py index ae94858fbd..861518519f 100644 --- a/tests/suite/test_rl_ingress.py +++ b/tests/suite/test_rl_ingress.py @@ -8,6 +8,7 @@ from suite.fixtures.fixtures import PublicEndpoint from suite.utils.custom_assertions import assert_event_count_increased from suite.utils.resources_utils import ( + are_all_pods_in_ready_state, create_example_app, create_items_from_yaml, delete_common_app, @@ -129,14 +130,18 @@ def test_ingress_rate_limit_sscaled( """ ns = ingress_controller_prerequisites.namespace scale_deployment(kube_apis.v1, kube_apis.apps_v1_api, "nginx-ingress", ns, 4) - ic_pods = get_pod_list(kube_apis.v1, ns) - for i in range(len(ic_pods)): - conf = get_ingress_nginx_template_conf( - kube_apis.v1, - annotations_setup.namespace, - annotations_setup.ingress_name, - ic_pods[i].metadata.name, - ingress_controller_prerequisites.namespace, - ) - flag = ("rate=10r/s" in conf) or ("rate=13r/s" in conf) - assert flag + wait_before_test() + if are_all_pods_in_ready_state(kube_apis.v1, ns): + ic_pods = get_pod_list(kube_apis.v1, ns) + for i in range(len(ic_pods)): + conf = get_ingress_nginx_template_conf( + kube_apis.v1, + annotations_setup.namespace, + annotations_setup.ingress_name, + ic_pods[i].metadata.name, + ingress_controller_prerequisites.namespace, + ) + flag = ("rate=10r/s" in conf) or ("rate=13r/s" in conf) + assert flag + else: + assert False, "Pods are not in ready state" From 1cf3622a1ae0e826197ffcdefad6dc4f357af9ef Mon Sep 17 00:00:00 2001 From: Venktesh Date: Tue, 18 Jun 2024 13:42:25 +0100 Subject: [PATCH 2/2] add condition --- tests/conftest.py | 7 +++++-- tests/suite/test_rl_ingress.py | 32 +++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0885f93611..555bdc9efc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,7 +16,7 @@ NS_COUNT, NUM_REPLICAS, ) -from suite.utils.resources_utils import get_first_pod_name, wait_until_all_pods_are_ready +from suite.utils.resources_utils import are_all_pods_in_ready_state, get_first_pod_name, wait_before_test def pytest_addoption(parser) -> None: @@ -200,7 +200,10 @@ def pytest_runtest_makereport(item) -> None: pod_namespace = item.funcargs["ingress_controller_prerequisites"].namespace pod_name = get_first_pod_name(item.funcargs["kube_apis"].v1, pod_namespace) print("\n===================== IC Logs Start =====================") - wait_until_all_pods_are_ready(item.funcargs["kube_apis"].v1, pod_namespace) + count = 0 + while (not are_all_pods_in_ready_state(item.funcargs["kube_apis"].v1, pod_namespace)) and count < 10: + count += 1 + wait_before_test() print(item.funcargs["kube_apis"].v1.read_namespaced_pod_log(pod_name, pod_namespace)) print("\n===================== IC Logs End =====================") diff --git a/tests/suite/test_rl_ingress.py b/tests/suite/test_rl_ingress.py index 861518519f..4ca5142991 100644 --- a/tests/suite/test_rl_ingress.py +++ b/tests/suite/test_rl_ingress.py @@ -130,18 +130,20 @@ def test_ingress_rate_limit_sscaled( """ ns = ingress_controller_prerequisites.namespace scale_deployment(kube_apis.v1, kube_apis.apps_v1_api, "nginx-ingress", ns, 4) - wait_before_test() - if are_all_pods_in_ready_state(kube_apis.v1, ns): - ic_pods = get_pod_list(kube_apis.v1, ns) - for i in range(len(ic_pods)): - conf = get_ingress_nginx_template_conf( - kube_apis.v1, - annotations_setup.namespace, - annotations_setup.ingress_name, - ic_pods[i].metadata.name, - ingress_controller_prerequisites.namespace, - ) - flag = ("rate=10r/s" in conf) or ("rate=13r/s" in conf) - assert flag - else: - assert False, "Pods are not in ready state" + count = 0 + while (not are_all_pods_in_ready_state(kube_apis.v1, ns)) and count < 10: + count += 1 + wait_before_test() + + ic_pods = get_pod_list(kube_apis.v1, ns) + for i in range(len(ic_pods)): + conf = get_ingress_nginx_template_conf( + kube_apis.v1, + annotations_setup.namespace, + annotations_setup.ingress_name, + ic_pods[i].metadata.name, + ingress_controller_prerequisites.namespace, + ) + flag = ("rate=10r/s" in conf) or ("rate=13r/s" in conf) + assert flag + scale_deployment(kube_apis.v1, kube_apis.apps_v1_api, "nginx-ingress", ns, 1)