From 495a7257a4ce10c5260b468328a6c7bae7a780de Mon Sep 17 00:00:00 2001 From: Michel Thebeau Date: Fri, 20 Sep 2024 13:42:23 +0000 Subject: [PATCH] Fix Tox test of dex and oidc client The dbapi.address_get_by_name function is returning a list now. Zuul log says "AttributeError: 'list' object has no attribute 'address'" Add some debug and a length assertion, but use the first address in the list. Test Plan: PASS Zuul's tox execution passes with new logs Closes-Bug: 2083724 Change-Id: I9cc6ffdd63de05465c54fcb5798bcad047ae5ac6 Signed-off-by: Michel Thebeau --- .../k8sapp_oidc/k8sapp_oidc/tests/test_dex.py | 19 ++++++++++++++++++- .../k8sapp_oidc/tests/test_oidc_client.py | 17 ++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/python3-k8sapp-oidc/k8sapp_oidc/k8sapp_oidc/tests/test_dex.py b/python3-k8sapp-oidc/k8sapp_oidc/k8sapp_oidc/tests/test_dex.py index 08435f4..008e888 100644 --- a/python3-k8sapp-oidc/k8sapp_oidc/k8sapp_oidc/tests/test_dex.py +++ b/python3-k8sapp-oidc/k8sapp_oidc/k8sapp_oidc/tests/test_dex.py @@ -33,12 +33,29 @@ class DexTestCase(test_plugins.K8SAppOidcAppMixin, oam_addr_name = utils.format_address_name(constants.CONTROLLER_HOSTNAME, constants.NETWORK_TYPE_OAM) oam_address = self.dbapi.address_get_by_name(oam_addr_name) - config_issuer = "https://%s:30556/dex" % (utils.format_url_address(oam_address.address)) + + # add some debug printing + print("Number of addresses (%s): %s" % + (type(oam_address), len(oam_address))) + i = 0 + while i < len(oam_address): + print("Address[%s]: %s" % (i, str(oam_address[i].address))) + i += 1 + + # There should be one address + oam_url = utils.format_url_address(oam_address[0].address) + print("Url Address: %s" % oam_url) + config_issuer = "https://%s:30556/dex" % oam_url self.assertOverridesParameters(overrides, { # issuer is set properly 'config': {'issuer': config_issuer} }) + # Complain if there is more than one address. + # It already failed if the list was empty + if len(oam_address) > 1: + raise ValueError("Too many addresses in returned list") + class DexIPv4ControllerHostTestCase(DexTestCase, dbbase.ProvisionedControllerHostTestCase): diff --git a/python3-k8sapp-oidc/k8sapp_oidc/k8sapp_oidc/tests/test_oidc_client.py b/python3-k8sapp-oidc/k8sapp_oidc/k8sapp_oidc/tests/test_oidc_client.py index aaaf5cd..4aeb84d 100644 --- a/python3-k8sapp-oidc/k8sapp_oidc/k8sapp_oidc/tests/test_oidc_client.py +++ b/python3-k8sapp-oidc/k8sapp_oidc/k8sapp_oidc/tests/test_oidc_client.py @@ -31,7 +31,17 @@ class OidcClientTestCase(test_plugins.K8SAppOidcAppMixin, oam_addr_name = utils.format_address_name(constants.CONTROLLER_HOSTNAME, constants.NETWORK_TYPE_OAM) address = self.dbapi.address_get_by_name(oam_addr_name) - oam_url = utils.format_url_address(address.address) + + # add some debug printing + print("Number of addresses (%s): %s" % (type(address), len(address))) + i = 0 + while i < len(address): + print("Address[%s]: %s" % (i, str(address[i].address))) + i += 1 + + # There should be one address + oam_url = utils.format_url_address(address[0].address) + print("Url Address: %s" % oam_url) parameters = { 'config': { 'issuer': 'https://%s:30556/dex' % oam_url, @@ -40,6 +50,11 @@ class OidcClientTestCase(test_plugins.K8SAppOidcAppMixin, } self.assertOverridesParameters(overrides, parameters) + # Complain if there is more than one address. + # It already failed if the list was empty + if len(address) > 1: + raise ValueError("Too many addresses in returned list") + class OidcClientIPv4ControllerHostTestCase(OidcClientTestCase, dbbase.ProvisionedControllerHostTestCase):