diff --git a/test/test_juniper_data.py b/test/test_juniper_data.py index 3157a7d5528ef45177fc07595d664d294fa70464..b35403f97424728a9c02043ca25f944cbd4d7da1 100644 --- a/test/test_juniper_data.py +++ b/test/test_juniper_data.py @@ -119,16 +119,24 @@ def router_output(request): return output -def test_ipv4_neighbors(router_output): +def test_ipv4_neighbors(mocker, router_output): old_v4_data = dict([ (x["neighbor"], x) for x in _parsed_old_style_output_data(router_output["bgpv4"])]) - parsers = dict([(c["key"], c["parser"]) for c in juniper.shell_commands()]) - neighbors = parsers["bgp"]( - router_output["bgp"], + def _mocked_ssh_exec_commands(hostname, params, commands): + assert len(commands) == 2 # the expected number + 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-].*$') assert len(neighbors) == len(old_v4_data) @@ -138,16 +146,24 @@ def test_ipv4_neighbors(router_output): assert old_v4_data[address]["description"] == description -def test_ipv6_neighbors(router_output): +def test_ipv6_neighbors(mocker, router_output): old_v6_data = dict([ (x["neighbor"], x) for x in _parsed_old_style_output_data(router_output["bgpv6"])]) - parsers = dict([(c["key"], c["parser"]) for c in juniper.shell_commands()]) - neighbors = parsers["bgp"]( - router_output["bgp"], + def _mocked_ssh_exec_commands(hostname, params, commands): + assert len(commands) == 2 # the expected number + 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-].*$') assert len(neighbors) == len(old_v6_data) @@ -157,7 +173,14 @@ def test_ipv6_neighbors(router_output): 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 (not a proper test ... just verifies there's no crash) @@ -166,7 +189,17 @@ def test_juniper_shell_output_parsing(router_output): :param router_output: :return: """ - for c in juniper.shell_commands(): - if c["key"] is None: - continue - c["parser"](router_output[c["key"]]) + + output = None + + 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)