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
cc5a5598
Commit
cc5a5598
authored
5 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
fixed unit test to support new snmp cache info
parent
3aa6d81a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/snmp.py
+3
-13
3 additions, 13 deletions
inventory_provider/snmp.py
test/test_snmp_handling.py
+6
-55
6 additions, 55 deletions
test/test_snmp_handling.py
with
9 additions
and
68 deletions
inventory_provider/snmp.py
+
3
−
13
View file @
cc5a5598
...
...
@@ -7,17 +7,8 @@ from pysnmp.smi import builder, compiler
# from pysnmp.smi import view, rfc1902
OID_LIST
=
{
## IPv4
'
v4Address
'
:
'
.1.3.6.1.2.1.4.20.1.1
'
,
'
v4InterfaceOID
'
:
'
.1.3.6.1.2.1.4.20.1.2
'
,
'
v4InterfaceName
'
:
'
.1.3.6.1.2.1.31.1.1.1.1
'
,
'
v4Mask
'
:
'
.1.3.6.1.2.1.4.20.1.3
'
,
## IPv6
'
v6AddressAndMask
'
'
.1.3.6.1.2.1.55.1.8.1.2
'
'
v6InterfaceName
'
:
'
.1.3.6.1.2.1.55.1.5.1.2
'
}
RFC1213_MIB_IFDESC
=
'
1.3.6.1.2.1.2.2.1.2
'
def
_v6address_oid2str
(
dotted_decimal
):
hex_params
=
[]
...
...
@@ -92,8 +83,7 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover
def
get_router_snmp_indexes
(
hostname
,
community
):
indexes
=
{}
RFC1213_MIB_ifDesc
=
'
1.3.6.1.2.1.2.2.1.2
'
for
ifc
in
walk
(
hostname
,
community
,
RFC1213_MIB_ifDesc
):
for
ifc
in
walk
(
hostname
,
community
,
RFC1213_MIB_IFDESC
):
m
=
re
.
match
(
r
'
.*\.(\d+)$
'
,
ifc
[
'
oid
'
])
assert
m
,
'
sanity failure parsing oid: %r
'
%
ifc
[
'
oid
'
]
indexes
[
ifc
[
'
value
'
]]
=
int
(
m
.
group
(
1
))
...
...
This diff is collapsed.
Click to expand it.
test/test_snmp_handling.py
+
6
−
55
View file @
cc5a5598
...
...
@@ -26,71 +26,22 @@ def test_snmp_interfaces(mocker, data_config, snmp_walk_responses):
expected_result_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
definitions
"
:
{
"
v4ifc
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
v4Address
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
r
'
^(\d+\.){3}\d+$
'
},
"
v4Mask
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
r
'
^(\d+\.){3}\d+$
'
},
"
v4InterfaceName
"
:
{
"
type
"
:
"
string
"
},
"
index
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
r
'
^\d+$
'
}
},
"
required
"
:
[
"
v4Address
"
,
"
v4Mask
"
,
"
v4InterfaceName
"
,
"
index
"
],
"
additionalProperties
"
:
False
},
"
v6ifc
"
:
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
v6Address
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
r
'
^[a-f\d:]+$
'
},
"
v6Mask
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
r
'
^\d+$
'
},
"
v6InterfaceName
"
:
{
"
type
"
:
"
string
"
},
"
index
"
:
{
"
type
"
:
"
string
"
,
"
pattern
"
:
r
'
^\d+$
'
}
},
"
required
"
:
[
"
v6Address
"
,
"
v6Mask
"
,
"
v6InterfaceName
"
,
"
index
"
],
"
additionalProperties
"
:
False
}
},
"
type
"
:
"
array
"
,
"
items
"
:
{
"
anyOf
"
:
[
{
"
$ref
"
:
"
#/definitions/v4ifc
"
},
{
"
$ref
"
:
"
#/definitions/v6ifc
"
}
]
"
name
"
:
{
"
type
"
:
"
string
"
},
"
index
"
:
{
"
type
"
:
"
integer
"
}
}
}
def
_mocked_walk
(
agent_hostname
,
community
,
base_oid
):
return
[
e
for
e
in
snmp_walk_responses
if
e
[
'
oid
'
].
startswith
(
base_oid
)]
def
_mocked_walk
(
agent_hostname
,
community
,
ignored_oid
):
return
snmp_walk_responses
mocker
.
patch
(
'
inventory_provider.snmp.walk
'
,
_mocked_walk
)
interfaces
=
snmp
.
get_router_
interfac
es
(
'
ignored
'
,
'
ignored
'
,
{
'
oids
'
:
data_config
[
'
oids
'
]}
)
interfaces
=
snmp
.
get_router_
snmp_index
es
(
'
ignored
'
,
'
ignored
'
)
interfaces
=
list
(
interfaces
)
jsonschema
.
validate
(
interfaces
,
expected_result_schema
)
...
...
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