From: Anil Belur Date: Mon, 12 Jan 2026 14:28:24 +0000 (+1000) Subject: fix: Handle duplicate resource exception and update urllib3 X-Git-Tag: v0.37.19^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=6c73e06bd42eda127588d0040e778c60b05fec2b;p=releng%2Flftools.git fix: Handle duplicate resource exception and update urllib3 1. Fix duplicate resource exception handling across OpenStack modules: - OpenStack SDK changed exception message format - Old: 'Multiple matches found for...' - New: 'More than one {Resource} exists with the name...' - Update exception check to handle both message formats - Applied to: image.py, server.py, volume.py 2. Fix server.created_at attribute: - Use 'created_at' instead of 'created' for Server objects - Bug introduced during shade to openstacksdk migration (2023) - Applied to: server.py lines 27, 92 3. Update urllib3 requirement: - Change from 'urllib3<2.1.0' to 'urllib3>=1.26.15,<3.0.0' - Resolves dependency conflict warnings - Supports newer urllib3 2.x while maintaining compatibility Fixes builder-openstack-cron job failures. Issue: AttributeError: 'Server' object has no attribute 'created' Issue: More than one Image/Server/Volume exists with the name Issue: urllib3 version conflict Change-Id: I4561bd1092c81c31e730fb21a2788966128049c1 Signed-off-by: Anil Belur --- diff --git a/lftools/openstack/image.py b/lftools/openstack/image.py index 3bcb0f81..038309c0 100644 --- a/lftools/openstack/image.py +++ b/lftools/openstack/image.py @@ -118,11 +118,14 @@ def cleanup(os_cloud, days=0, hide_public=False, ci_managed=True, clouds=None): try: result = cloud.delete_image(image.name) except OpenStackCloudException as e: - if str(e).startswith("Multiple matches found for"): - log.warning("{}. Skipping image...".format(str(e))) + error_msg = str(e) + if error_msg.startswith("Multiple matches found for") or error_msg.startswith( + "More than one Image exists with the name" + ): + log.warning("{}. Skipping image...".format(error_msg)) continue else: - log.error("Unexpected exception: {}".format(str(e))) + log.error("Unexpected exception: {}".format(error_msg)) raise if not result: diff --git a/lftools/openstack/server.py b/lftools/openstack/server.py index 4f6922fb..5f1608c3 100644 --- a/lftools/openstack/server.py +++ b/lftools/openstack/server.py @@ -24,7 +24,9 @@ def _filter_servers(servers, days=0): """Filter server data and return list.""" filtered = [] for server in servers: - if days and (datetime.strptime(server.created, "%Y-%m-%dT%H:%M:%SZ") >= datetime.now() - timedelta(days=days)): + if days and ( + datetime.strptime(server.created_at, "%Y-%m-%dT%H:%M:%SZ") >= datetime.now() - timedelta(days=days) + ): continue filtered.append(server) @@ -89,7 +91,7 @@ def remove(os_cloud, server_name, minutes=0): print("ERROR: Server not found.") sys.exit(1) - if datetime.strptime(server.created, "%Y-%m-%dT%H:%M:%SZ") >= datetime.utcnow() - timedelta(minutes=minutes): + if datetime.strptime(server.created_at, "%Y-%m-%dT%H:%M:%SZ") >= datetime.utcnow() - timedelta(minutes=minutes): print('WARN: Server "{}" is not older than {} minutes.'.format(server.name, minutes)) else: cloud.delete_server(server.name) diff --git a/lftools/openstack/volume.py b/lftools/openstack/volume.py index 7faa7700..88e2eab9 100644 --- a/lftools/openstack/volume.py +++ b/lftools/openstack/volume.py @@ -56,11 +56,14 @@ def cleanup(os_cloud, days=0): try: result = cloud.delete_volume(volume.name) except OpenStackCloudException as e: - if str(e).startswith("Multiple matches found for"): - print("WARNING: {}. Skipping volume...".format(str(e))) + error_msg = str(e) + if error_msg.startswith("Multiple matches found for") or error_msg.startswith( + "More than one Volume exists with the name" + ): + print("WARNING: {}. Skipping volume...".format(error_msg)) continue else: - print("ERROR: Unexpected exception: {}".format(str(e))) + print("ERROR: Unexpected exception: {}".format(error_msg)) raise if not result: diff --git a/pyproject.toml b/pyproject.toml index 7afaf4bc..490f5c94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,7 @@ dependencies = [ "tabulate", "toml", "tqdm", - "urllib3<2.1.0", + "urllib3>=1.26.15,<3.0.0", "websocket-client", "wrapt", "xdg"