Skip to content

Commit c7472dc

Browse files
committed
In cluster_shutdown module fix exception handling
1 parent 410e846 commit c7472dc

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

plugins/module_utils/cluster.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from time import sleep
1212
from ..module_utils.utils import PayloadMapper
1313
from ..module_utils.rest_client import RestClient
14-
from ..module_utils.errors import ScaleComputingError
14+
from ..module_utils.errors import ScaleComputingError, ScaleTimeoutError
1515
from ..module_utils.typed_classes import TypedClusterToAnsible, TypedTaskTag
1616
from typing import Any
1717

@@ -84,18 +84,14 @@ def shutdown(
8484
dict(forceShutdown=force_shutdown),
8585
check_mode,
8686
)
87-
except ScaleComputingError as e:
88-
# To avoid timeout when there are a lot of VMs to shutdown
89-
if "Request timed out" in str(e):
90-
try:
91-
while True:
92-
# get cluster until "[Errno 111] Connection refused"
93-
Cluster.get(rest_client)
94-
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
87+
# To avoid timeout when there are a lot of VMs to shutdown
88+
except ScaleTimeoutError:
89+
pass
90+
91+
try:
92+
while True:
93+
# get cluster until "[Errno 111] Connection refused"
94+
Cluster.get(rest_client)
95+
sleep(5)
96+
except ConnectionRefusedError:
97+
pass

0 commit comments

Comments
 (0)