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
cabfc5c7
Commit
cabfc5c7
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
updated unit tests to match new api
parent
5484f87b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_juniper_data.py
+46
-13
46 additions, 13 deletions
test/test_juniper_data.py
with
46 additions
and
13 deletions
test/test_juniper_data.py
+
46
−
13
View file @
cabfc5c7
...
@@ -119,16 +119,24 @@ def router_output(request):
...
@@ -119,16 +119,24 @@ def router_output(request):
return
output
return
output
def
test_ipv4_neighbors
(
router_output
):
def
test_ipv4_neighbors
(
mocker
,
router_output
):
old_v4_data
=
dict
([
old_v4_data
=
dict
([
(
x
[
"
neighbor
"
],
x
)
(
x
[
"
neighbor
"
],
x
)
for
x
in
for
x
in
_parsed_old_style_output_data
(
router_output
[
"
bgpv4
"
])])
_parsed_old_style_output_data
(
router_output
[
"
bgpv4
"
])])
parsers
=
dict
([(
c
[
"
key
"
],
c
[
"
parser
"
])
for
c
in
juniper
.
shell_commands
()])
def
_mocked_ssh_exec_commands
(
hostname
,
params
,
commands
):
neighbors
=
parsers
[
"
bgp
"
](
assert
len
(
commands
)
==
2
# the expected number
router_output
[
"
bgp
"
],
return
[
None
,
router_output
[
"
bgp
"
]]
mocker
.
patch
(
'
inventory_provider.juniper.ssh_exec_commands
'
,
_mocked_ssh_exec_commands
)
neighbors
=
juniper
.
fetch_bgp_config
(
None
,
None
,
group_expression
=
r
'
^GEANT-IX[\s-].*$
'
)
group_expression
=
r
'
^GEANT-IX[\s-].*$
'
)
assert
len
(
neighbors
)
==
len
(
old_v4_data
)
assert
len
(
neighbors
)
==
len
(
old_v4_data
)
...
@@ -138,16 +146,24 @@ def test_ipv4_neighbors(router_output):
...
@@ -138,16 +146,24 @@ def test_ipv4_neighbors(router_output):
assert
old_v4_data
[
address
][
"
description
"
]
==
description
assert
old_v4_data
[
address
][
"
description
"
]
==
description
def
test_ipv6_neighbors
(
router_output
):
def
test_ipv6_neighbors
(
mocker
,
router_output
):
old_v6_data
=
dict
([
old_v6_data
=
dict
([
(
x
[
"
neighbor
"
],
x
)
(
x
[
"
neighbor
"
],
x
)
for
x
in
for
x
in
_parsed_old_style_output_data
(
router_output
[
"
bgpv6
"
])])
_parsed_old_style_output_data
(
router_output
[
"
bgpv6
"
])])
parsers
=
dict
([(
c
[
"
key
"
],
c
[
"
parser
"
])
for
c
in
juniper
.
shell_commands
()])
def
_mocked_ssh_exec_commands
(
hostname
,
params
,
commands
):
neighbors
=
parsers
[
"
bgp
"
](
assert
len
(
commands
)
==
2
# the expected number
router_output
[
"
bgp
"
],
return
[
None
,
router_output
[
"
bgp
"
]]
mocker
.
patch
(
'
inventory_provider.juniper.ssh_exec_commands
'
,
_mocked_ssh_exec_commands
)
neighbors
=
juniper
.
fetch_bgp_config
(
None
,
None
,
group_expression
=
r
'
^GEANT-IXv6[\s-].*$
'
)
group_expression
=
r
'
^GEANT-IXv6[\s-].*$
'
)
assert
len
(
neighbors
)
==
len
(
old_v6_data
)
assert
len
(
neighbors
)
==
len
(
old_v6_data
)
...
@@ -157,7 +173,14 @@ def test_ipv6_neighbors(router_output):
...
@@ -157,7 +173,14 @@ def test_ipv6_neighbors(router_output):
assert
old_v6_data
[
address
][
"
description
"
]
==
description
assert
old_v6_data
[
address
][
"
description
"
]
==
description
def
test_juniper_shell_output_parsing
(
router_output
):
COMMAND_HANDLERS
=
{
'
bgp
'
:
juniper
.
fetch_bgp_config
,
'
vrr
'
:
juniper
.
fetch_vrr_config
,
'
interfaces
'
:
juniper
.
fetch_interfaces
}
def
test_juniper_shell_output_parsing
(
mocker
,
router_output
):
"""
"""
just call the correct parser for each type of shell output
just call the correct parser for each type of shell output
(not a proper test ... just verifies there
'
s no crash)
(not a proper test ... just verifies there
'
s no crash)
...
@@ -166,7 +189,17 @@ def test_juniper_shell_output_parsing(router_output):
...
@@ -166,7 +189,17 @@ def test_juniper_shell_output_parsing(router_output):
:param router_output:
:param router_output:
:return:
:return:
"""
"""
for
c
in
juniper
.
shell_commands
():
if
c
[
"
key
"
]
is
None
:
output
=
None
continue
c
[
"
parser
"
](
router_output
[
c
[
"
key
"
]])
def
_mocked_ssh_exec_commands
(
hostname
,
params
,
commands
):
assert
len
(
commands
)
==
2
# the expected number
return
[
None
,
output
]
mocker
.
patch
(
'
inventory_provider.juniper.ssh_exec_commands
'
,
_mocked_ssh_exec_commands
)
for
key
in
[
"
bgp
"
,
"
vrr
"
,
"
interfaces
"
]:
output
=
router_output
[
key
]
COMMAND_HANDLERS
[
key
](
None
,
None
)
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