Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
480b88f1
Commit
480b88f1
authored
7 months ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
removed caching functionality from IMS class. RE DBOARD3-1053
parent
98374f10
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inventory_provider/db/ims.py
+6
-29
6 additions, 29 deletions
inventory_provider/db/ims.py
inventory_provider/db/ims_data.py
+1
-2
1 addition, 2 deletions
inventory_provider/db/ims_data.py
test/test_ims.py
+0
-22
0 additions, 22 deletions
test/test_ims.py
with
7 additions
and
53 deletions
inventory_provider/db/ims.py
+
6
−
29
View file @
480b88f1
...
@@ -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
)
)
This diff is collapsed.
Click to expand it.
inventory_provider/db/ims_data.py
+
1
−
2
View file @
480b88f1
...
@@ -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
=
''
...
...
This diff is collapsed.
Click to expand it.
test/test_ims.py
+
0
−
22
View file @
480b88f1
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment