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

removed caching functionality from IMS class. RE DBOARD3-1053

parent 98374f10
No related branches found
No related tags found
No related merge requests found
...@@ -250,25 +250,13 @@ class IMS(object): ...@@ -250,25 +250,13 @@ class IMS(object):
self, self,
url, url,
params=None, params=None,
navigation_properties=None, navigation_properties=None):
use_cache=False):
url = f'{self.base_url + IMS.IMS_PATH}/{url}' url = f'{self.base_url + IMS.IMS_PATH}/{url}'
cache_key = url
if navigation_properties: if navigation_properties:
params = params if params else {} params = params if params else {}
params['navigationproperty'] = navigation_properties if isinstance( params['navigationproperty'] = navigation_properties if isinstance(
navigation_properties, int) else sum(navigation_properties) navigation_properties, int) else sum(navigation_properties)
if use_cache:
if params:
s = '-'.join(
[f'{t}::{params[t]}'
for t in sorted(params)])
cache_key = f'{cache_key}::{s}'
entity = IMS.cache.get(cache_key, None)
if entity:
return entity
if not IMS.bearer_token: if not IMS.bearer_token:
IMS._init_bearer_token( IMS._init_bearer_token(
self.username, self.password, self.verify_ssl) self.username, self.password, self.verify_ssl)
...@@ -325,9 +313,6 @@ class IMS(object): ...@@ -325,9 +313,6 @@ class IMS(object):
response.raise_for_status() response.raise_for_status()
orig = response.json() orig = response.json()
return_value = _convert_keys(orig) return_value = _convert_keys(orig)
if use_cache:
IMS.cache[cache_key] = return_value
return return_value return return_value
@log_entry_and_exit @log_entry_and_exit
...@@ -335,22 +320,20 @@ class IMS(object): ...@@ -335,22 +320,20 @@ class IMS(object):
self, self,
entity_type, entity_type,
entity_id, entity_id,
navigation_properties=None, navigation_properties=None):
use_cache=False):
url = f'{entity_type}/{entity_id}' url = f'{entity_type}/{entity_id}'
return \ return \
self._get_ims_data(url, None, navigation_properties, use_cache) self._get_ims_data(url, None, navigation_properties)
@log_entry_and_exit @log_entry_and_exit
def get_entity_by_name( def get_entity_by_name(
self, self,
entity, entity,
name, name,
navigation_properties=None, navigation_properties=None):
use_cache=False):
url = f'{entity}/byname/"{name}"' url = f'{entity}/byname/"{name}"'
return self._get_ims_data(url, None, navigation_properties, use_cache) return self._get_ims_data(url, None, navigation_properties)
@log_entry_and_exit @log_entry_and_exit
def get_filtered_entities( def get_filtered_entities(
...@@ -358,13 +341,11 @@ class IMS(object): ...@@ -358,13 +341,11 @@ class IMS(object):
entity, entity,
filter_string, filter_string,
navigation_properties=None, navigation_properties=None,
use_cache=False,
step_count=50): step_count=50):
url = f'{entity}/filtered/{filter_string}' url = f'{entity}/filtered/{filter_string}'
yield from self.get_entities( yield from self.get_entities(
url, url,
navigation_properties, navigation_properties,
use_cache,
step_count step_count
) )
...@@ -372,7 +353,6 @@ class IMS(object): ...@@ -372,7 +353,6 @@ class IMS(object):
self, self,
url, url,
navigation_properties=None, navigation_properties=None,
use_cache=False,
step_count=50): step_count=50):
more_to_come = True more_to_come = True
start_entity = 0 start_entity = 0
...@@ -387,8 +367,7 @@ class IMS(object): ...@@ -387,8 +367,7 @@ class IMS(object):
entities = self._get_ims_data( entities = self._get_ims_data(
url, url,
params, params,
navigation_properties, navigation_properties)
use_cache)
except HTTPError as e: except HTTPError as e:
r = e.response r = e.response
if r.status_code == requests.codes.not_found \ if r.status_code == requests.codes.not_found \
...@@ -418,13 +397,11 @@ class IMS(object): ...@@ -418,13 +397,11 @@ class IMS(object):
self, self,
entity, entity,
navigation_properties=None, navigation_properties=None,
use_cache=False,
step_count=50 step_count=50
): ):
url = f'{entity}/all' url = f'{entity}/all'
yield from self.get_entities( yield from self.get_entities(
url, url,
navigation_properties, navigation_properties,
use_cache,
step_count step_count
) )
...@@ -598,8 +598,7 @@ def lookup_lg_routers(ds: IMS): ...@@ -598,8 +598,7 @@ def lookup_lg_routers(ds: IMS):
if node['inventorystatusid'] != InventoryStatus.IN_SERVICE.value: if node['inventorystatusid'] != InventoryStatus.IN_SERVICE.value:
continue continue
site = ds.get_entity_by_id('Site', node['siteid'], site_nav_props, site = ds.get_entity_by_id('Site', node['siteid'], site_nav_props)
True)
city = site['city'] city = site['city']
abbreviation = '' abbreviation = ''
......
...@@ -158,25 +158,3 @@ def test_ims_class_navigation_properties(mocker): ...@@ -158,25 +158,3 @@ def test_ims_class_navigation_properties(mocker):
'dummy_base/ims/Node/1234', 'dummy_base/ims/Node/1234',
headers={'Authorization': 'Bearer dummy_bt'}, headers={'Authorization': 'Bearer dummy_bt'},
params={'navigationproperty': 6}, verify=False) params={'navigationproperty': 6}, verify=False)
def test_ims_class_cache(mocker):
mock_get = mocker.patch('inventory_provider.db.ims.requests.get')
ds = inventory_provider.db.ims.IMS(
'dummy_base', 'dummy_username', 'dummy_password', 'dummy_bt')
ds.get_entity_by_id(
'Node', 4567, navigation_properties=[1, 2, 3, 4], use_cache=True)
assert mock_get.call_count == 1
ds.get_entity_by_id(
'Node', 4567, navigation_properties=[1, 2, 3, 4], use_cache=True)
assert mock_get.call_count == 1
ds.get_entity_by_id(
'Node', 4567, navigation_properties=[1, 2, 3, 4], use_cache=False)
assert mock_get.call_count == 2
ds.get_entity_by_id(
'Node', 4567, navigation_properties=[1, 2, 3, 4])
assert mock_get.call_count == 3
ds.get_entity_by_id(
'Node', 4567, navigation_properties=[1, 2, 3, 4, 5], use_cache=True)
assert mock_get.call_count == 4
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment