Esempio n. 1
0
def test_send_config_command_str(first_router_from_devices_yaml):
    r1 = task_22_2b.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_config_commands")

    cfg_comand = "logging 10.1.1.1"
    return_value = r1.send_config_commands(cfg_comand)
    assert cfg_comand in return_value, "send_config_commands method returns wrong value"
def test_class_inheritance(first_router_from_devices_yaml):
    ssh = task_24_2.MyNetmiko(**first_router_from_devices_yaml)
    assert isinstance(
        ssh, CiscoIosSSH), "Класс MyNetmiko должен наследовать CiscoIosSSH"
    ssh.disconnect()
    check_attr_or_method(ssh, method="send_command")
    check_attr_or_method(ssh, method="send_config_set")
def test_send_show_command_different_command(first_router_from_devices_yaml,
                                             r1_test_telnet_connection):
    full_pth = os.path.join(os.getcwd(), "templates")
    os.environ["NET_TEXTFSM"] = full_pth

    r1 = task_22_2a.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_show_command")

    correct_return_value = r1_test_telnet_connection.send_command(
        "sh int desc",
        use_textfsm=True,
        strip_command=False,
        strip_prompt=False)
    return_value = r1.send_show_command("sh int desc",
                                        parse=True,
                                        templates="templates",
                                        index="index")
    assert (
        correct_return_value == return_value
    ), "Метод send_show_command возвращает неправильное значение с parse=True"

    correct_return_value = r1_test_telnet_connection.send_command(
        "sh version | include IOS", strip_command=False, strip_prompt=False)
    return_value = r1.send_show_command("sh version | include IOS",
                                        parse=False,
                                        templates="templates",
                                        index="index")
    assert strip_empty_lines(correct_return_value) == strip_empty_lines(
        return_value
    ), "Метод send_show_command возвращает неправильное значение с parse=False"
Esempio n. 4
0
def test_class_inheritance(first_router_from_devices_yaml):
    r1 = task_24_2a.MyNetmiko(**first_router_from_devices_yaml)
    r1.disconnect()
    assert isinstance(
        r1, CiscoIosSSH), "Класс MyNetmiko должен наследовать CiscoIosSSH"
    check_attr_or_method(r1, method="send_command")
    check_attr_or_method(r1, method="_check_error_in_command")
Esempio n. 5
0
def test_class_inheritance(first_router_from_devices_yaml):
    ssh = task_24_1a.CiscoSSH(**first_router_from_devices_yaml)
    ssh.ssh.disconnect()
    assert isinstance(ssh,
                      BaseSSH), "Класс CiscoSSH должен наследовать BaseSSH"
    check_attr_or_method(ssh, method="send_show_command")
    check_attr_or_method(ssh, method="send_cfg_commands")
Esempio n. 6
0
def test_attr_topology():
    """Проверяем, что в объекте IPAddress есть атрибуты ip и mask"""
    return_ip = task_23_1.IPAddress("10.1.1.1/24")
    check_attr_or_method(return_ip, attr="ip")
    check_attr_or_method(return_ip, attr="mask")
    assert "10.1.1.1" == return_ip.ip, "Значение return_ip.ip должно быть равным 10.1.1.1"
    assert 24 == return_ip.mask, "Значение return_ip.mask должно быть равным 24"
Esempio n. 7
0
def test_attr_ipaddress():
    """Verify that the IPAddress object has ip and mask attributes"""
    ip1 = task_23_1.IPAddress("10.1.1.1/24")
    check_attr_or_method(ip1, attr="ip")
    check_attr_or_method(ip1, attr="mask")
    assert ip1.ip == "10.1.1.1", "ip1.ip attribute must be equal to 10.1.1.1"
    assert ip1.mask == 24, "ip1.mask attribute must be equal to 24"
Esempio n. 8
0
def test_attr_ipaddress():
    return_ip = task_23_1a.IPAddress("10.1.1.1/24")
    check_attr_or_method(return_ip, attr="ip")
    check_attr_or_method(return_ip, attr="mask")
    assert ("10.1.1.1" == return_ip.ip
            ), "return_ip.ip attribute must be equal to 10.1.1.1"
    assert 24 == return_ip.mask, "return_ip.mask attribute must be equal to 24"
Esempio n. 9
0
def test_attr_topology():
    """Проверяем, что в объекте IPAddress есть атрибуты ip и mask"""
    ip1 = task_23_1.IPAddress("10.1.1.1/24")
    check_attr_or_method(ip1, attr="ip")
    check_attr_or_method(ip1, attr="mask")
    assert ip1.ip == "10.1.1.1", "Значение ip1.ip должно быть равным 10.1.1.1"
    assert ip1.mask == 24, "Значение ip1.mask должно быть равным 24"
Esempio n. 10
0
def test_class_inheritance(first_router_from_devices_yaml):
    r1 = task_24_2b.MyNetmiko(**first_router_from_devices_yaml)
    r1.disconnect()
    assert isinstance(
        r1, CiscoIosSSH), "MyNetmiko class must inherit from CiscoIosSSH"
    check_attr_or_method(r1, method="send_command")
    check_attr_or_method(r1, method="_check_error_in_command")
Esempio n. 11
0
def test_send_config_command_str(first_router_from_devices_yaml):
    r1 = task_22_2b.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_config_commands")

    cfg_comand = "logging 10.1.1.1"
    return_value = r1.send_config_commands(cfg_comand)
    assert (cfg_comand in return_value
            ), "Метод send_config_commands возвращает неправильное значение"
Esempio n. 12
0
def test_send_config_commands_list(first_router_from_devices_yaml):
    r1 = task_22_2b.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_config_commands")

    cfg_comands = ["interface loop55", "ip address 5.5.5.5 255.255.255.255"]
    return_value = r1.send_config_commands(cfg_comands)
    assert (cfg_comands[0] in return_value and cfg_comands[1]
            in return_value), "send_config_commands method returns wrong value"
Esempio n. 13
0
def test_attr_ipaddress():
    """Verify that the IPAddress object has ip and mask attributes"""
    return_ip = task_23_1.IPAddress("10.1.1.1/24")
    check_attr_or_method(return_ip, attr="ip")
    check_attr_or_method(return_ip, attr="mask")
    assert (
        "10.1.1.1" == return_ip.ip
    ), "return_ip.ip attribute must be equal to 10.1.1.1"
    assert 24 == return_ip.mask, "return_ip.mask attribute must be equal to 24"
def test_send_show_command(first_router_from_devices_yaml,
                           r1_test_telnet_connection):
    r1 = task_22_2.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="_write_line")
    check_attr_or_method(r1, method="send_show_command")

    correct_return_value = strip_empty_lines(
        r1_test_telnet_connection.send_command("sh ip int br"))
    return_value = strip_empty_lines(r1.send_show_command("sh ip int br"))
    assert (correct_return_value in return_value
            ), "Метод send_show_command возвращает неправильное значение"
Esempio n. 15
0
def test_send_config_commands_correct_commands(first_router_from_devices_yaml,
                                               capsys):
    r1 = task_22_2c.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_config_commands")

    # команды без ошибок
    correct_commands = [
        "interface loop55", "ip address 5.5.5.5 255.255.255.255"
    ]
    return_value = r1.send_config_commands(correct_commands)
    assert (correct_commands[0] in return_value
            and correct_commands[1] in return_value
            ), "Метод send_config_commands возвращает неправильное значение"
Esempio n. 16
0
def test_send_show_command_parse_true(first_router_from_devices_yaml,
                                      r1_test_telnet_connection):
    full_pth = os.path.join(os.getcwd(), "templates")
    os.environ["NET_TEXTFSM"] = full_pth

    r1 = task_22_2a.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_show_command")

    correct_return_value = r1_test_telnet_connection.send_command(
        "sh ip int br", use_textfsm=True)
    return_value = r1.send_show_command("sh ip int br",
                                        parse=True,
                                        templates="templates",
                                        index="index")
    assert (correct_return_value == return_value
            ), "send_show_command method returns wrong value with parse=True"
Esempio n. 17
0
def test_send_config_commands_different_command(
        first_router_from_devices_yaml):
    r1 = task_22_2b.CiscoTelnet(**first_router_from_devices_yaml)
    check_attr_or_method(r1, method="send_config_commands")

    cfg_comand = "no ip http server"
    return_value = r1.send_config_commands(cfg_comand)
    assert cfg_comand in return_value, "send_config_commands method returns wrong value"

    cfg_comands = [
        "alias configure sh do sh",
        "alias exec ospf sh run | s ^router ospf",
    ]
    return_value = r1.send_config_commands(cfg_comands)
    assert (cfg_comands[0] in return_value and cfg_comands[1]
            in return_value), "send_config_commands method returns wrong value"
Esempio n. 18
0
def test_method__add__(normalized_topology_example):
    top1 = task_23_3.Topology(normalized_topology_example)
    top1_size_before_add = len(top1.topology)
    top2 = task_23_3.Topology({
        ("R1", "Eth0/4"): ("R7", "Eth0/0"),
        ("R1", "Eth0/6"): ("R9", "Eth0/0")
    })
    top2_size_before_add = len(top2.topology)

    check_attr_or_method(top1, method="__add__")
    top3 = top1 + top2
    assert isinstance(
        top3, task_23_3.Topology
    ), "The __add__ method should return a new instance of the Topology class"
    assert len(top3.topology) == 8
    assert (
        len(top1.topology) == top1_size_before_add
    ), "After the addition, the size of the first topology changed. The __add__ method should not change the original topologies"
    assert (
        len(top2.topology) == top2_size_before_add
    ), "After the addition, the size of the second topology changed. The __add__ method should not change the original topologies"
def test_method__add__(normalized_topology_example):
    """Проверка наличия метода __add__ и его работы"""
    top1 = task_23_3.Topology(normalized_topology_example)
    top1_size_before_add = len(top1.topology)
    top2 = task_23_3.Topology({
        ("R1", "Eth0/4"): ("R7", "Eth0/0"),
        ("R1", "Eth0/6"): ("R9", "Eth0/0")
    })
    top2_size_before_add = len(top2.topology)

    check_attr_or_method(top1, method="__add__")
    top3 = top1 + top2
    assert isinstance(
        top3, task_23_3.Topology
    ), "Метод __add__ должен возвращать новый экземпляр класса Topology"
    assert len(top3.topology) == 8
    assert (
        len(top1.topology) == top1_size_before_add
    ), "После сложения изменился размер первой топологии. Метод __add__ не должен менять исходные топологии"
    assert (
        len(top2.topology) == top2_size_before_add
    ), "После сложения изменился размер второй топологии. Метод __add__ не должен менять исходные топологии"
Esempio n. 20
0
def test_method_delete_link_created(topology_with_dupl_links,
                                    normalized_topology_example):
    norm_top = task_22_1b.Topology(normalized_topology_example)
    check_attr_or_method(norm_top, method="delete_link")
def test_attr_topology(topology_with_dupl_links):
    """Проверяем, что в объекте Topology есть атрибут topology"""
    top_with_data = task_23_3a.Topology(topology_with_dupl_links)
    check_attr_or_method(top_with_data, attr="topology")
Esempio n. 22
0
def test_method_delete_node_created(topology_with_dupl_links,
                                    normalized_topology_example):
    return_value = task_22_1c.Topology(normalized_topology_example)
    check_attr_or_method(return_value, method="delete_node")
Esempio n. 23
0
def test_attr_topology(topology_with_dupl_links):
    """Checking that the Topology object has a topology attribute"""
    top_with_data = task_22_1b.Topology(topology_with_dupl_links)
    check_attr_or_method(top_with_data, attr="topology")
Esempio n. 24
0
def test_method_add_link_created(normalized_topology_example):
    """Проверяем, что в объекте Topology есть метод add_link"""
    norm_top = task_22_1d.Topology(normalized_topology_example)
    check_attr_or_method(norm_top, method="add_link")
def test_method_delete_node_created(
    topology_with_dupl_links, normalized_topology_example
):
    """Проверяем, что в объекте Topology есть метод delete_node"""
    return_value = task_22_1c.Topology(normalized_topology_example)
    check_attr_or_method(return_value, method="delete_node")
Esempio n. 26
0
def test_method_normalize(topology_with_dupl_links):
    """Проверяем, что в объекте Topology есть метод _normalize"""
    top_with_data = task_22_1a.Topology(topology_with_dupl_links)
    check_attr_or_method(top_with_data, method="_normalize")
Esempio n. 27
0
def test_attr_ipaddress():
    ip1 = task_23_1a.IPAddress("10.1.1.1/24")
    check_attr_or_method(ip1, attr="ip")
    check_attr_or_method(ip1, attr="mask")
    assert ip1.ip == "10.1.1.1", "ip1.ip attribute must be equal to 10.1.1.1"
    assert ip1.mask == 24, "ip1.mask attribute must be equal to 24"
Esempio n. 28
0
def test_method_add_link_created(normalized_topology_example):
    norm_top = task_22_1d.Topology(normalized_topology_example)
    check_attr_or_method(norm_top, method="add_link")
Esempio n. 29
0
def test_attr_topology(topology_with_dupl_links):
    """Проверяем, что в объекте Topology есть атрибут topology"""
    return_value = task_22_1d.Topology(topology_with_dupl_links)
    check_attr_or_method(return_value, attr="topology")
Esempio n. 30
0
def test_class_inheritance(first_router_from_devices_yaml):
    ssh = task_24_2c.MyNetmiko(**first_router_from_devices_yaml)
    ssh.disconnect()
    assert isinstance(ssh, CiscoIosSSH), "MyNetmiko class must inherit from CiscoIosSSH"
    check_attr_or_method(ssh, method="send_command")