Пример #1
0
def test_function_return_value():
    service_section = (
        "service timestamps debug datetime msec localtime show-timezone\n"
        "service timestamps log datetime msec localtime show-timezone\n"
        "service tcp-keepalives-in\n"
        "service tcp-keepalives-out\n"
        "service password-encryption\n")
    alias_section = (
        "alias exec top sh proc cpu sorted | excl 0.00%__0.00%__0.00%\n"
        "alias exec diff sh archive config differences nvram:startup-config system:running-config\n"
        "alias exec bri show ip int bri | exc unass\n"
        "alias exec id show int desc\n")
    eem_section = (
        "event manager applet update-int-desc\n"
        " event neighbor-discovery interface regexp .*Ethernet.* cdp add\n"
        ' action 1.0 cli command "enable"\n'
        ' action 2.0 cli command "config t"\n'
        ' action 3.0 cli command "interface $_nd_local_intf_name"\n'
        ' action 4.0 cli command "description To $_nd_cdp_entry_name $_nd_port_id"\n'
    )

    template = "templates/cisco_router_base.txt"
    data = {"hostname": "R1"}
    return_value = render_jinja_template(template, data)
    assert (
        service_section
        in return_value), "There is no service commands in the configuration"
    assert (alias_section
            in return_value), "There is no alias commands in the configuration"
    assert (
        eem_section in return_value
    ), "There is no event manager commands in the configuration event manager"
    assert (
        data["hostname"]
        in return_value), "There is no hostname command in the configuration"
Пример #2
0
def test_function_different_input():
    correct_return_value = ("router ospf 1\n"
                            "router-id 10.0.0.1\n"
                            "auto-cost reference-bandwidth 30000\n"
                            "network 10.55.1.1 0.0.0.0 area 0\n"
                            "network 10.55.2.1 0.0.0.0 area 5\n"
                            "network 10.55.3.1 0.0.0.0 area 5\n"
                            "passive-interface Fa0/1.100\n"
                            "passive-interface Fa0/1.200\n"
                            "passive-interface Fa0/1.300\n")

    template = "templates/ospf.txt"
    data = {
        "ospf_intf": [
            {
                "area": 0,
                "ip": "10.55.1.1",
                "name": "Fa0/1.100",
                "passive": True
            },
            {
                "area": 5,
                "ip": "10.55.2.1",
                "name": "Fa0/1.200",
                "passive": True
            },
            {
                "area": 5,
                "ip": "10.55.3.1",
                "name": "Fa0/1.300",
                "passive": True
            },
        ],
        "process":
        1,
        "ref_bw":
        30000,
        "router_id":
        "10.0.0.1",
    }

    return_value = render_jinja_template(template, data)
    correct_lines = set(correct_return_value.splitlines())
    return_value = strip_empty_lines(return_value)
    return_lines = set(return_value.splitlines())

    assert (correct_lines == return_lines
            ), "Not all lines are present in the router ospf configuration"
def test_function_return_value():
    correct_return_value = ("router ospf 10\n"
                            "router-id 10.0.0.1\n"
                            "auto-cost reference-bandwidth 20000\n"
                            "network 10.255.0.1 0.0.0.0 area 0\n"
                            "network 10.255.1.1 0.0.0.0 area 0\n"
                            "network 10.255.2.1 0.0.0.0 area 0\n"
                            "network 10.0.10.1 0.0.0.0 area 2\n"
                            "network 10.0.20.1 0.0.0.0 area 2\n"
                            "passive-interface Fa0/0.10\n"
                            "passive-interface Fa0/0.20\n"
                            "interface Fa0/1\n"
                            "ip ospf hello-interval 1\n"
                            "interface Fa0/1.100\n"
                            "ip ospf hello-interval 1\n"
                            "interface Fa0/1.200\n"
                            "ip ospf hello-interval 1\n")

    template = "templates/ospf.txt"
    data = {
        "ospf_intf": [
            {
                "area": 0,
                "ip": "10.255.0.1",
                "name": "Fa0/1",
                "passive": False
            },
            {
                "area": 0,
                "ip": "10.255.1.1",
                "name": "Fa0/1.100",
                "passive": False
            },
            {
                "area": 0,
                "ip": "10.255.2.1",
                "name": "Fa0/1.200",
                "passive": False
            },
            {
                "area": 2,
                "ip": "10.0.10.1",
                "name": "Fa0/0.10",
                "passive": True
            },
            {
                "area": 2,
                "ip": "10.0.20.1",
                "name": "Fa0/0.20",
                "passive": True
            },
        ],
        "process":
        10,
        "ref_bw":
        20000,
        "router_id":
        "10.0.0.1",
    }

    return_value = render_jinja_template(template, data)
    correct_lines = set(correct_return_value.splitlines())
    return_value = strip_empty_lines(return_value)
    return_lines = set(return_value.splitlines())

    assert correct_lines == return_lines, "В итоговой конфигурации ospf не все строки"