Adds tests for making listener timeouts configurable

Change-Id: Ida82b70aedd3979697ef7e5760ea389ab99c4a5b
This commit is contained in:
Tabitha Fasoyin 2021-03-30 19:53:48 +00:00
parent 36fd12e958
commit bb32e50644
3 changed files with 81 additions and 0 deletions

View File

@ -96,4 +96,7 @@ kuryr_k8s_opts = [
cfg.BoolOpt("test_services_without_selector", default=False,
help="Whether or not service without selector tests will be "
"running"),
cfg.BoolOpt("test_configurable_listener_timeouts", default=False,
help="Whether or not listener timeout values are "
"configurable"),
]

View File

@ -426,6 +426,18 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
namespace=namespace,
body=delete_options)
@classmethod
def update_service(cls, service_name, annotation, namespace="default"):
api = cls.k8s_client.CoreV1Api()
service = api.read_namespaced_service(service_name, namespace)
service.metadata = cls.k8s_client.V1ObjectMeta(
name=service_name, annotations=annotation)
service_obj = api.patch_namespaced_service(body=service,
name=service_name,
namespace=namespace)
return service_obj
@classmethod
def get_service_ip(
cls, service_name, spec_type="ClusterIP", namespace="default"):
@ -514,6 +526,30 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
msg = "Timed out waiting for lb crd status %s" % service_name
raise lib_exc.TimeoutException(msg)
@classmethod
def get_listener_timeout_on_crd(cls, service_name, namespace):
api = cls.k8s_client.CoreV1Api()
service = api.read_namespaced_service(service_name, namespace)
if service.metadata.annotations:
try:
klb_crd = cls.get_kuryr_loadbalancer_crds(
service_name, namespace)
except kubernetes.client.rest.ApiException:
return None, None
klb_status = klb_crd.get('status')
if klb_status and klb_status.get('listeners'):
try:
for l in klb_status.get('listeners', []):
timeout_cli = l.get('timeout_client_data')
timeout_mb = l.get('timeout_member_data')
return timeout_cli, timeout_mb
except KeyError:
LOG.info("Waiting till LB's timeout appears in CRD")
return None, None
return None, None
@classmethod
def wait_kuryr_annotation(cls, group, version, plural, annotation,
timeout_period, name, namespace='default'):
@ -1378,3 +1414,26 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
if ipn.version == 6 else curl_tmpl + " {}")
return curl_tmpl + "{}" if port else curl_tmpl
def check_updated_listener_timeout(self, service_name,
namespace='default'):
annotation = {
'openstack.org/kuryr-timeout-client-data': '70000',
'openstack.org/kuryr-timeout-member-data': '75000'
}
updated_service = self.update_service(service_name=service_name,
annotation=annotation,
namespace=namespace)
annotated_values = [value for i, value in annotation.items()]
start = time.time()
while time.time() - start < consts.LB_TIMEOUT:
time.sleep(5)
timeout_cli, timeout_mem = self.get_listener_timeout_on_crd(
service_name=updated_service.metadata.name,
namespace=namespace)
lb_status_values = [str(timeout_cli), str(timeout_mem)]
if annotated_values == lb_status_values:
break
self.assertEqual(annotated_values, lb_status_values)

View File

@ -155,3 +155,22 @@ class TestSCTPServiceScenario(base.BaseKuryrScenarioTest):
self.check_service_internal_connectivity(
service_port='90', protocol='SCTP')
class TestListenerTimeoutScenario(base.BaseKuryrScenarioTest):
@classmethod
def skip_checks(cls):
super(TestListenerTimeoutScenario, cls).skip_checks()
if not CONF.kuryr_kubernetes.service_tests_enabled:
raise cls.skipException("Service tests are not enabled")
if not CONF.kuryr_kubernetes.test_configurable_listener_timeouts:
raise cls.skipException("Listener timeout tests are not enabled")
@decorators.idempotent_id('ca9bd886-d776-5675-b532-228c92a4da7f')
def test_updated_listener_timeouts(self):
self.create_setup_for_service_test(
service_name="kuryr-listener-demo")
self.check_updated_listener_timeout(
service_name="kuryr-listener-demo")