def test_updates_repeat_parents(): expected_diff = [ "interface loopback0", "ip ospf 1 area 0.0.0.0", "interface GigabitEthernet0/1", "ip ospf 1 area 0.0.0.0", "interface GigabitEthernet0/2", "ip ospf 1 area 0.0.0.0", "router isis fabric", "is-type level-2", "net 49.0000.0000.0003.00", "interface loopback0", "ip router isis fabric", "interface GigabitEthernet0/1", "ip router isis fabric", "interface GigabitEthernet0/2", "ip router isis fabric", ] candidate_obj = config.NetworkConfig(indent=1) candidate_obj.load(WANT_SRC_2) running_obj = config.NetworkConfig(indent=1, contents=HAVE_SRC_2) configdiffobjs = candidate_obj.difference(running_obj) diff_list = config.dumps(configdiffobjs, "commands").split("\n") for generated_diff_line, candidate_diff_line in zip( diff_list, expected_diff): print(generated_diff_line, candidate_diff_line) assert generated_diff_line == candidate_diff_line.strip()
def test_updates_repeat_lines(): candidate_obj = config.NetworkConfig(indent=3) candidate_obj.load(WANT_SRC_1) running_obj = config.NetworkConfig(indent=3, contents=HAVE_SRC_1) configdiffobjs = candidate_obj.difference(running_obj) diff_list = config.dumps(configdiffobjs, "commands").split("\n") want_src_list = WANT_SRC_1.strip().split("\n") for generated_diff_line, candidate_diff_line in zip( diff_list, want_src_list): assert generated_diff_line == candidate_diff_line.strip()
def test_config_items(): net_config = config.NetworkConfig(indent=3, contents=RUNNING) assert len(net_config.items) == 10 net_config = config.NetworkConfig(indent=3, contents=RUNNING, ignore_lines=[r"\s*no .*"]) assert len(net_config.items) == 6 net_config = config.NetworkConfig(indent=3, contents=RUNNING, ignore_lines=[re.compile(r"\s*no .*")]) assert len(net_config.items) == 6
def test_config_items(): net_config = config.NetworkConfig(indent=3, contents=RUNNING) assert len(net_config.items) == 10 net_config = config.NetworkConfig(indent=3, contents=RUNNING, ignore_lines=[r"\s*no .*"]) assert len(net_config.items) == 6 net_config = config.NetworkConfig(indent=3, contents=RUNNING, ignore_lines=[re.compile(r"\s*no .*")]) assert len(net_config.items) == 6 # above updates the global DEFAULT_IGNORE_LINES_RE list, revert back the global # to it's original value config.DEFAULT_IGNORE_LINES_RE = ORIGINAL_DEFAULT_IGNORE_LINES_RE
def test_line_hierarchy(): net_config = config.NetworkConfig(indent=3, contents=RUNNING) lines = net_config.items assert lines[0].has_children assert not lines[0].has_parents assert not lines[1].has_children assert lines[1].has_parents
def test_config_get_block(): net_config = config.NetworkConfig(indent=3, contents=RUNNING) with pytest.raises(AssertionError, match="path argument must be a list object"): net_config.get_block("interface Ethernet2") with pytest.raises(ValueError, match="path does not exist in config"): net_config.get_block(["interface Ethernet3"]) block = net_config.get_block(["interface Ethernet2"]) assert len(block) == 4