Skip to content

Commit e988bae

Browse files
committed
Use ConnectionRefusedError in cluster shutdown instead of error description comparison
1 parent 94c3b47 commit e988bae

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

plugins/module_utils/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def _request(
134134
return Response(e.code, e.read(), e.headers)
135135
except URLError as e:
136136
# TODO: Add other errors here; we need to handle them in modules.
137+
# TimeoutError is handled in the rest_client
137138
if (
138139
e.args
139140
and isinstance(e.args, tuple)

plugins/module_utils/cluster.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ def shutdown(
8484
dict(forceShutdown=force_shutdown),
8585
check_mode,
8686
)
87+
# TimeoutError is handled in rest_client.create_record:
88+
# except TimeoutError as e:
89+
# raise errors.ScaleComputingError(f"Request timed out: {e}")
8790
except ScaleComputingError as e:
8891
# To avoid timeout when there are a lot of VMs to shutdown
8992
if "Request timed out" in str(e):
@@ -92,10 +95,9 @@ def shutdown(
9295
# get cluster until "[Errno 111] Connection refused"
9396
Cluster.get(rest_client)
9497
sleep(5)
95-
except ScaleComputingError as e2:
96-
if "Connection refused" in str(e2): # cluster is shutdown
97-
pass
98-
else:
99-
raise e2 # Some other unexpected error
100-
else:
101-
raise e # UnexpectedAPIResponse error
98+
except ConnectionRefusedError:
99+
pass # cluster is shutdown
100+
except ScaleComputingError as e2: # Some other unexpected error
101+
raise e2
102+
else: # UnexpectedAPIResponse error
103+
raise e

0 commit comments

Comments
 (0)