Skip to content

Commit 9fd217a

Browse files
Make concurrency detection more deterministic
1 parent ed8eb8e commit 9fd217a

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

meraki/rest_session.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,23 +246,21 @@ def handle_4xx_errors(self, metadata, operation, reason, response, retries, stat
246246
network_delete_concurrency_error_text = 'concurrent'
247247
action_batch_concurrency_error_text = 'executing batches'
248248

249-
if message_is_dict and 'errors' in message.keys():
250-
errors = message['errors']
251-
if self._logger:
252-
self._logger.warning(f'{tag}, {operation} - {status} {reason} {errors}')
253-
network_deletion_errors = [error for error in message['errors'] if network_delete_concurrency_error_text in
254-
error]
255-
action_batch_errors = [error for error in message['errors'] if action_batch_concurrency_error_text in error]
256-
257-
if network_deletion_errors:
249+
if operation == 'deleteNetwork' and response.status_code == 400:
250+
if network_delete_concurrency_error_text in message['errors'][0]:
258251
wait = random.randint(30, self._network_delete_retry_wait_time)
259252
if self._logger:
260253
self._logger.warning(f'{tag}, {operation} - {status} {reason}, retrying in {wait} seconds')
261254
time.sleep(wait)
262255
retries -= 1
263256
if retries == 0:
264257
raise APIError(metadata, response)
265-
elif action_batch_errors:
258+
259+
elif message_is_dict and 'errors' in message.keys():
260+
261+
action_batch_errors = [error for error in message['errors'] if action_batch_concurrency_error_text in error]
262+
263+
if action_batch_errors:
266264
wait = self._action_batch_retry_wait_time
267265
if self._logger:
268266
self._logger.warning(f'{tag}, {operation} - {status} {reason}, retrying in {wait} seconds')
@@ -271,7 +269,7 @@ def handle_4xx_errors(self, metadata, operation, reason, response, retries, stat
271269
if retries == 0:
272270
raise APIError(metadata, response)
273271

274-
if self._retry_4xx_error:
272+
elif self._retry_4xx_error:
275273
wait = random.randint(1, self._retry_4xx_error_wait_time)
276274
if self._logger:
277275
self._logger.warning(f'{tag}, {operation} - {status} {reason}, retrying in {wait} seconds')

tests/test_dashboard_api_python_library.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def api_key(pytestconfig):
1414

1515
@pytest.fixture(scope='session')
1616
def dashboard(api_key):
17-
return meraki.DashboardAPI(api_key, suppress_logging=True, network_delete_retry_wait_time=600, maximum_retries=100)
17+
return meraki.DashboardAPI(api_key, suppress_logging=True, network_delete_retry_wait_time=1000,
18+
maximum_retries=1000)
1819

1920

2021
@pytest.fixture(scope='session')

0 commit comments

Comments
 (0)