コード例 #1
0
ファイル: task_21_4.py プロジェクト: pool80/pythonAdm
def send_and_parse_show_command(device_dict, command, templates_path, index="index"):
    attributes = {"Command": command, "Vendor": device_dict["device_type"]}
    with ConnectHandler(**device_dict) as ssh:
        ssh.enable()
        output = ssh.send_command(command)
        parsed_data = parse_command_dynamic(
            output, attributes, templ_path=templates_path, index_file=index
        )
    return parsed_data
コード例 #2
0
def test_function_return_value():
    """
    Проверка работы функции
    """
    correct_return_value = [
        {
            "address": "15.0.15.1",
            "intf": "FastEthernet0/0",
            "protocol": "up",
            "status": "up",
        },
        {
            "address": "10.0.12.1",
            "intf": "FastEthernet0/1",
            "protocol": "up",
            "status": "up",
        },
        {
            "address": "10.0.13.1",
            "intf": "FastEthernet0/2",
            "protocol": "up",
            "status": "up",
        },
        {
            "address": "unassigned",
            "intf": "FastEthernet0/3",
            "protocol": "up",
            "status": "up",
        },
        {
            "address": "10.1.1.1",
            "intf": "Loopback0",
            "protocol": "up",
            "status": "up"
        },
        {
            "address": "100.0.0.1",
            "intf": "Loopback100",
            "protocol": "up",
            "status": "up",
        },
    ]
    with open("output/sh_ip_int_br.txt") as f:
        sh_ip_int_br = f.read()
    attributes = {"Command": "show ip int br", "Vendor": "cisco_ios"}

    return_value = task_21_3.parse_command_dynamic(sh_ip_int_br, attributes)
    assert return_value is not None, "Функция ничего не возвращает"
    assert (
        type(return_value) == list
    ), f"По заданию функция должна возвращать список, а возвращает {type(return_value).__name__}"
    assert (correct_return_value == return_value
            ), "Функция возвращает неправильное значение"
コード例 #3
0
def test_function_return_value():
    """
    Function check
    """
    correct_return_value = [
        {
            "address": "15.0.15.1",
            "intf": "FastEthernet0/0",
            "protocol": "up",
            "status": "up",
        },
        {
            "address": "10.0.12.1",
            "intf": "FastEthernet0/1",
            "protocol": "up",
            "status": "up",
        },
        {
            "address": "10.0.13.1",
            "intf": "FastEthernet0/2",
            "protocol": "up",
            "status": "up",
        },
        {
            "address": "unassigned",
            "intf": "FastEthernet0/3",
            "protocol": "up",
            "status": "up",
        },
        {
            "address": "10.1.1.1",
            "intf": "Loopback0",
            "protocol": "up",
            "status": "up"
        },
        {
            "address": "100.0.0.1",
            "intf": "Loopback100",
            "protocol": "up",
            "status": "up",
        },
    ]
    with open("output/sh_ip_int_br.txt") as f:
        sh_ip_int_br = f.read()
    attributes = {"Command": "show ip int br", "Vendor": "cisco_ios"}

    return_value = task_21_3.parse_command_dynamic(sh_ip_int_br, attributes)
    assert return_value != None, "The function returns None"
    assert (
        type(return_value) == list
    ), f"The function should return a list, instead it returns a {type(return_value).__name__}"
    assert correct_return_value == return_value, "Function returns wrong value"
コード例 #4
0
def test_function_return_value_different_args():
    """
    Checking the function with different arguments
    """
    correct_return_value = [{
        "hostname": "R1_LONDON",
        "version": "15.3(2)S1",
    }]
    with open("output/sh_version.txt") as f:
        sh_version = f.read()
    attributes = {"Command": "show version", "Vendor": "cisco_ios"}

    return_value = task_21_3.parse_command_dynamic(sh_version, attributes)
    assert return_value != None, "The function returns None"
    assert (
        type(return_value) == list
    ), f"The function should return a list, instead it returns a {type(return_value).__name__}"
    assert correct_return_value == return_value, "Function returns wrong value"
コード例 #5
0
def test_function_return_value_different_args():
    """
    Проверка работы функции с другими аргументами
    """
    correct_return_value = [{
        "hostname": "R1_LONDON",
        "version": "15.3(2)S1",
    }]
    with open("output/sh_version.txt") as f:
        sh_version = f.read()
    attributes = {"Command": "show version", "Vendor": "cisco_ios"}

    return_value = task_21_3.parse_command_dynamic(sh_version, attributes)
    assert return_value is not None, "Функция ничего не возвращает"
    assert (
        type(return_value) == list
    ), f"По заданию функция должна возвращать список, а возвращает {type(return_value).__name__}"
    assert (correct_return_value == return_value
            ), "Функция возвращает неправильное значение"