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
9faf8327
Commit
9faf8327
authored
4 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
added handling for changed IMS response and updated test to cover it
parent
4c29640f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/db/ims.py
+24
-7
24 additions, 7 deletions
inventory_provider/db/ims.py
test/test_ims.py
+17
-0
17 additions, 0 deletions
test/test_ims.py
with
41 additions
and
7 deletions
inventory_provider/db/ims.py
+
24
−
7
View file @
9faf8327
...
...
@@ -6,6 +6,8 @@ from enum import Enum
# Navigation Properties
# http://149.210.162.190:81/ImsVersions/4.19.9/html/86d07a57-fa45-835e-d4a2-a789c4acbc96.htm # noqa
from
requests
import
HTTPError
CIRCUIT_PROPERTIES
=
{
'
Ports
'
:
512
,
'
InternalPorts
'
:
1024
,
...
...
@@ -75,6 +77,8 @@ VENDOR_RELATED_CONTACT_PROPERTIES = {
'
Contact
'
:
16
}
NO_FILTERED_RESULTS_MESSAGE
=
'
no records found for entity:
'
class
InventoryStatus
(
Enum
):
PLANNED
=
1
...
...
@@ -166,7 +170,12 @@ class IMS(object):
if
response_
.
status_code
==
requests
.
codes
.
unauthorized
:
return
True
if
response_
.
status_code
==
requests
.
codes
.
ok
:
if
response_
.
status_code
in
(
requests
.
codes
.
ok
,
requests
.
codes
.
not_found
):
if
NO_FILTERED_RESULTS_MESSAGE
in
response_
.
text
.
lower
():
return
False
r
=
response_
.
json
()
if
r
and
'
HasErrors
'
in
r
and
r
[
'
HasErrors
'
]:
for
e
in
r
[
'
Errors
'
]:
...
...
@@ -238,12 +247,20 @@ class IMS(object):
'
paginatorNumberOfElements
'
:
step_count
}
url
=
f
'
{
entity
}
/filtered/
{
filter_string
}
'
entities
=
self
.
_get_entity
(
url
,
params
,
navigation_properties
,
use_cache
)
more_to_come
=
False
try
:
more_to_come
=
False
entities
=
self
.
_get_entity
(
url
,
params
,
navigation_properties
,
use_cache
)
except
HTTPError
as
e
:
r
=
e
.
response
if
r
.
status_code
==
requests
.
codes
.
not_found
\
and
NO_FILTERED_RESULTS_MESSAGE
in
r
.
text
.
lower
():
entities
=
None
else
:
raise
e
if
entities
:
more_to_come
=
\
len
(
entities
)
>=
step_count
...
...
This diff is collapsed.
Click to expand it.
test/test_ims.py
+
17
−
0
View file @
9faf8327
from
requests
import
HTTPError
import
inventory_provider
...
...
@@ -5,6 +7,7 @@ class MockResponse:
def
__init__
(
self
,
json_data
,
status_code
):
self
.
json_data
=
json_data
self
.
status_code
=
status_code
self
.
text
=
''
if
json_data
else
'
No records found for Entity:XXXXX
'
def
json
(
self
):
return
self
.
json_data
...
...
@@ -96,6 +99,20 @@ def test_ims_class_filtered_entities(mocker):
assert
mock_multi_get
.
call_count
==
2
assert
res
==
[
1
,
2
,
3
]
def
side_effect_no_recs
(
*
args
,
**
kargs
):
if
kargs
[
'
params
'
][
'
paginatorStartElement
'
]
==
0
:
return
MockResponse
([
1
,
2
],
200
)
e
=
HTTPError
()
e
.
response
=
MockResponse
(
''
,
404
)
raise
e
mocker
.
patch
(
'
inventory_provider.db.ims.requests.get
'
,
side_effect
=
side_effect_no_recs
)
res
=
list
(
ds
.
get_filtered_entities
(
'
Node
'
,
'
dummy_param=dummy value
'
,
step_count
=
2
))
assert
res
==
[
1
,
2
]
def
test_ims_class_get_all_entities
(
mocker
):
mock_get
=
mocker
.
patch
(
'
inventory_provider.db.ims.requests.get
'
)
...
...
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