From 7a63c928e72dfe2afdd6ef10643fc56df8b9e40f Mon Sep 17 00:00:00 2001 From: Jon Uriarte Date: Tue, 11 Jan 2022 12:29:07 +0000 Subject: [PATCH] Add wait until active LB in NP test The test test_egress_np_to_service_wo_selector is failing in some environments when checking the connectivity to services (before the NP is applied). The endpoints are defined in kuryrloadbalancers objects but the connectivity is not working. This change adds the method wait_until_service_LB_is_active() and calls it in that test before checking the connectivity to the services. Change-Id: I41cec1ea1db43e2fbeb0bf6d5fafb84c87e77d1c --- kuryr_tempest_plugin/tests/scenario/base.py | 23 +++++++++++-------- .../tests/scenario/test_network_policy.py | 10 ++++++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/kuryr_tempest_plugin/tests/scenario/base.py b/kuryr_tempest_plugin/tests/scenario/base.py index d4aa31c3..de82bcc5 100644 --- a/kuryr_tempest_plugin/tests/scenario/base.py +++ b/kuryr_tempest_plugin/tests/scenario/base.py @@ -1505,6 +1505,18 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest): self.addClassResourceCleanup(self.delete_pod, pod_name, namespace=namespace) + self.wait_until_service_LB_is_active(service_name, namespace) + self.assert_backend_amount_from_pod( + clusterip_svc_ip, + pod_num, + pod_name, + service_port, + protocol, + namespace_name=namespace) + return pod_name + + def wait_until_service_LB_is_active(self, service_name, + namespace='default', poll_interval=5): if CONF.kuryr_kubernetes.kuryrloadbalancers: klb_crd_id = self.get_klb_crd_id(service_name, namespace) start = time.time() @@ -1519,21 +1531,12 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest): if loadbalancer.get("provisioning_status") == "ACTIVE": LOG.info("LB is ACTIVE: %s", klb_crd_id) break - time.sleep(10) + time.sleep(poll_interval) else: msg = ("Timed out waiting for loadbalancer %s to become" " ACTIVE", klb_crd_id) raise lib_exc.TimeoutException(msg) - self.assert_backend_amount_from_pod( - clusterip_svc_ip, - pod_num, - pod_name, - service_port, - protocol, - namespace_name=namespace) - return pod_name - def get_curl_template(self, ip_or_cidr, extra_args='', port=False): ipn = netaddr.IPNetwork(ip_or_cidr) diff --git a/kuryr_tempest_plugin/tests/scenario/test_network_policy.py b/kuryr_tempest_plugin/tests/scenario/test_network_policy.py index c1b35d67..0172101f 100644 --- a/kuryr_tempest_plugin/tests/scenario/test_network_policy.py +++ b/kuryr_tempest_plugin/tests/scenario/test_network_policy.py @@ -296,6 +296,8 @@ class ServiceWOSelectorsNPScenario(base.BaseKuryrScenarioTest): self.verify_lbaas_endpoints_configured(service_name, 1, server_ns_name) self.verify_lbaas_endpoints_configured(service2_name, 1, server_ns_name) + self.wait_until_service_LB_is_active(service_name, server_ns_name) + self.wait_until_service_LB_is_active(service2_name, server_ns_name) # check connectivity curl_tmpl = self.get_curl_template(service_ip, extra_args='-m 10') @@ -303,10 +305,14 @@ class ServiceWOSelectorsNPScenario(base.BaseKuryrScenarioTest): cmd2 = ["/bin/sh", "-c", curl_tmpl.format(service2_ip)] self.assertIn(consts.POD_OUTPUT, self.exec_command_in_pod(client_pod_name, cmd, - namespace=client_ns_name)) + namespace=client_ns_name), + "Connectivity from %s to service %s (%s) failed." % + (client_pod_name, service_ip, service_name)) self.assertIn(consts.POD_OUTPUT, self.exec_command_in_pod(client_pod_name, cmd2, - namespace=client_ns_name)) + namespace=client_ns_name), + "Connectivity from %s to service2 %s (%s) failed." % + (client_pod_name, service2_ip, service2_name)) # create NP for client to be able to reach server np_name = data_utils.rand_name(prefix='kuryr-np')