Skip to content

Commit 6c73e06

Browse files
committed
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 <abelur@linuxfoundation.org>
1 parent 1879e8c commit 6c73e06

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

lftools/openstack/image.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ def _remove_images_from_cloud(images, cloud):
118118
try:
119119
result = cloud.delete_image(image.name)
120120
except OpenStackCloudException as e:
121-
if str(e).startswith("Multiple matches found for"):
122-
log.warning("{}. Skipping image...".format(str(e)))
121+
error_msg = str(e)
122+
if error_msg.startswith("Multiple matches found for") or error_msg.startswith(
123+
"More than one Image exists with the name"
124+
):
125+
log.warning("{}. Skipping image...".format(error_msg))
123126
continue
124127
else:
125-
log.error("Unexpected exception: {}".format(str(e)))
128+
log.error("Unexpected exception: {}".format(error_msg))
126129
raise
127130

128131
if not result:

lftools/openstack/server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def _filter_servers(servers, days=0):
2424
"""Filter server data and return list."""
2525
filtered = []
2626
for server in servers:
27-
if days and (datetime.strptime(server.created, "%Y-%m-%dT%H:%M:%SZ") >= datetime.now() - timedelta(days=days)):
27+
if days and (
28+
datetime.strptime(server.created_at, "%Y-%m-%dT%H:%M:%SZ") >= datetime.now() - timedelta(days=days)
29+
):
2830
continue
2931

3032
filtered.append(server)
@@ -89,7 +91,7 @@ def remove(os_cloud, server_name, minutes=0):
8991
print("ERROR: Server not found.")
9092
sys.exit(1)
9193

92-
if datetime.strptime(server.created, "%Y-%m-%dT%H:%M:%SZ") >= datetime.utcnow() - timedelta(minutes=minutes):
94+
if datetime.strptime(server.created_at, "%Y-%m-%dT%H:%M:%SZ") >= datetime.utcnow() - timedelta(minutes=minutes):
9395
print('WARN: Server "{}" is not older than {} minutes.'.format(server.name, minutes))
9496
else:
9597
cloud.delete_server(server.name)

lftools/openstack/volume.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ def _remove_volumes_from_cloud(volumes, cloud):
5656
try:
5757
result = cloud.delete_volume(volume.name)
5858
except OpenStackCloudException as e:
59-
if str(e).startswith("Multiple matches found for"):
60-
print("WARNING: {}. Skipping volume...".format(str(e)))
59+
error_msg = str(e)
60+
if error_msg.startswith("Multiple matches found for") or error_msg.startswith(
61+
"More than one Volume exists with the name"
62+
):
63+
print("WARNING: {}. Skipping volume...".format(error_msg))
6164
continue
6265
else:
63-
print("ERROR: Unexpected exception: {}".format(str(e)))
66+
print("ERROR: Unexpected exception: {}".format(error_msg))
6467
raise
6568

6669
if not result:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ dependencies = [
8080
"tabulate",
8181
"toml",
8282
"tqdm",
83-
"urllib3<2.1.0",
83+
"urllib3>=1.26.15,<3.0.0",
8484
"websocket-client",
8585
"wrapt",
8686
"xdg"

0 commit comments

Comments
 (0)