Skip to content
Snippets Groups Projects
Commit cabfc5c7 authored by Erik Reid's avatar Erik Reid
Browse files

updated unit tests to match new api

parent 5484f87b
No related branches found
No related tags found
No related merge requests found
...@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment