Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion aci-preupgrade-validation-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ def _icurl(apitype, query, page=0, page_size=100000):
return data


def icurl(apitype, query, page_size=100000):
def _icurl_all_pages(apitype, query, page_size=100000):
total_imdata = []
total_cnt = 999999
page = 0
Expand All @@ -1762,6 +1762,24 @@ def icurl(apitype, query, page_size=100000):
return total_imdata


_icurl_cache = {}
_icurl_locks = {}
_icurl_locks_lock = threading.Lock()


def icurl(apitype, query, page_size=100000):
# Checks run in parallel threads and several issue identical queries. Successful
# results are cached for the run; a per-query lock makes concurrent callers of the
# same query wait for the first one instead of all hitting the APIC at once.
cache_key = (apitype, query, page_size)
with _icurl_locks_lock:
key_lock = _icurl_locks.setdefault(cache_key, threading.Lock())
with key_lock:
if cache_key not in _icurl_cache:
_icurl_cache[cache_key] = _icurl_all_pages(apitype, query, page_size)
return _icurl_cache[cache_key]


def run_cmd(cmd, splitlines=True):
"""
Run a shell command.
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _mock_icurl(apitype, query, page=0, page_size=100000):
return data

monkeypatch.setattr(script, "_icurl", _mock_icurl)
monkeypatch.setattr(script, "_icurl_cache", {})


@pytest.fixture
Expand Down