Exemple #1
0
def test_function_return_value():
    data = {
        "tun_num": 17,
        "wan_ip_1": "80.241.1.1",
        "wan_ip_2": "90.18.10.2",
        "tun_ip_1": "10.255.1.1 255.255.255.252",
        "tun_ip_2": "10.255.1.2 255.255.255.252",
    }
    correct_value_1 = ("interface Tunnel 17\n"
                       "ip address 10.255.1.1 255.255.255.252\n"
                       "tunnel source 80.241.1.1\n"
                       "tunnel destination 90.18.10.2\n"
                       "tunnel protection ipsec profile GRE")
    correct_value_2 = ("interface Tunnel 17\n"
                       "ip address 10.255.1.2 255.255.255.252\n"
                       "tunnel source 90.18.10.2\n"
                       "tunnel destination 80.241.1.1\n"
                       "tunnel protection ipsec profile GRE")

    template1 = "templates/gre_ipsec_vpn_1.txt"
    template2 = "templates/gre_ipsec_vpn_2.txt"

    return_cfg1, return_cfg2 = task_21_5.create_vpn_config(
        template1, template2, data)
    return_cfg1 = strip_empty_lines(return_cfg1)
    return_cfg2 = strip_empty_lines(return_cfg2)

    assert (
        correct_value_1 in return_cfg1
    ), "В итоговой конфигурации неправильно указаны настройки Tunnel для первой стороны"
    assert (
        correct_value_2 in return_cfg2
    ), "В итоговой конфигурации неправильно указаны настройки Tunnel для второй стороны"
Exemple #2
0
def test_function_return_value():
    data = {
        'tun_num': 17,
        'wan_ip_1': '80.241.1.1',
        'wan_ip_2': '90.18.10.2',
        'tun_ip_1': '10.255.1.1 255.255.255.252',
        'tun_ip_2': '10.255.1.2 255.255.255.252'
    }
    correct_value_1 = ('interface Tunnel 17\n'
                       'ip address 10.255.1.1 255.255.255.252\n'
                       'tunnel source 80.241.1.1\n'
                       'tunnel destination 90.18.10.2\n'
                       'tunnel protection ipsec profile GRE')
    correct_value_2 = ('interface Tunnel 17\n'
                       'ip address 10.255.1.2 255.255.255.252\n'
                       'tunnel source 90.18.10.2\n'
                       'tunnel destination 80.241.1.1\n'
                       'tunnel protection ipsec profile GRE')

    template1 = 'templates/gre_ipsec_vpn_1.txt'
    template2 = 'templates/gre_ipsec_vpn_2.txt'

    return_cfg1, return_cfg2 = task_21_5.create_vpn_config(
        template1, template2, data)
    return_cfg1 = strip_empty_lines(return_cfg1)
    return_cfg2 = strip_empty_lines(return_cfg2)

    assert correct_value_1 in return_cfg1, \
        "В итоговой конфигурации неправильно указаны настройки Tunnel для первой стороны"
    assert correct_value_2 in return_cfg2, \
        "В итоговой конфигурации неправильно указаны настройки Tunnel для второй стороны"
Exemple #3
0
def configure_vpn(src_device_params, dst_device_params, src_template,
                  dst_template, vpn_data_dict):
    with open(src_device_params) as f:
        src_device = yaml.safe_load(f)
    with open(dst_device_params) as f:
        dst_device = yaml.safe_load(f)
    src_num = tunnel_num(src_device, tunnels=tunnels1)
    dst_num = tunnel_num(dst_device, tunnels=tunnels2)
    if src_num >= dst_num:
        t_num = src_num + 1
    else:
        t_num = dst_num + 1
    vpn_data_dict['tun_num'] = t_num
    conf1, conf2 = create_vpn_config(src_template, dst_template, vpn_data_dict)
    with open('task_21_6_result1.txt', 'w') as f:
        f.write(conf1)
    with open('task_21_6_result2.txt', 'w') as f:
        f.write(conf2)
    commands1 = conf1.split('\n')
    commands2 = conf2.split('\n')
    print("The number of tunnel is {}".format(t_num))
    pprint(commands1)
    pprint(commands2)
    pprint(send_show_command(src_device, commands1))
    pprint(send_show_command(dst_device, commands2))