Skip to content
Snippets Groups Projects
Commit 30822e21 authored by Robert Latta's avatar Robert Latta
Browse files

added clearing of Dynamic Context Cache

parent a8bf72f1
No related branches found
No related tags found
No related merge requests found
......@@ -221,6 +221,20 @@ class IMS(object):
cls.bearer_token_init_time = re_init_time
cls.bearer_token = response.text
def clear_dynamic_context_cache(self):
if not IMS.bearer_token:
IMS._init_bearer_token(self.username, self.password)
while True:
logger.info('Clearing Dynamic Context Cache')
response = requests.put(
f'{self.base_url + IMS.IMS_PATH}/ClearDynamicContextCache',
headers={'Authorization': f'Bearer {self.bearer_token}'})
if response.status_code == 401:
IMS._init_bearer_token(self.username, self.password)
continue
response.raise_for_status()
break
def _get_entity(
self,
url,
......
......@@ -741,6 +741,8 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password):
def _ds() -> IMS:
return IMS(ims_api_url, ims_username, ims_password)
_ds().clear_dynamic_context_cache()
locations = {}
lg_routers = []
geant_nodes = []
......@@ -829,7 +831,6 @@ def _extract_ims_data(ims_api_url, ims_username, ims_password):
nonlocal flexils_data
flexils_data = ims_data.get_flexils_by_circuitid(ds=_ds())
@log_task_entry_and_exit
def _populate_hierarchy():
nonlocal hierarchy
......
......@@ -16,6 +16,9 @@ def test_extract_ims_data(mocker):
'inventory_provider.tasks.worker.ims_data.get_node_locations',
return_value=[('loc_a', 'LOC A'), ('loc_b', 'LOC B')]
)
mocker.patch(
'inventory_provider.tasks.worker.IMS.clear_dynamic_context_cache'
)
mocker.patch(
'inventory_provider.tasks.worker.ims_data.lookup_lg_routers',
return_value=['lg router 1', 'lg router 2']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment