Example #1
0
def test_function_return_value(r1_test_connection,
                               first_router_from_devices_yaml):
    """
    Проверка работы функции
    """
    show_command = "sh ip int br"
    cfg_commands = [
        "logging 10.255.255.1",
        "logging buffered 20010",
        "no logging console",
    ]
    correct_return_value_show = r1_test_connection.send_command(show_command)
    correct_return_value_cfg = r1_test_connection.send_config_set(cfg_commands)
    return_value_show = task_19_3.send_commands(first_router_from_devices_yaml,
                                                show=show_command)
    return_value_cfg = task_19_3.send_commands(first_router_from_devices_yaml,
                                               config=cfg_commands)
    assert return_value_show != None, "Функция ничего не возвращает"
    assert (
        type(return_value_show) == str
    ), f"По заданию функция должна возвращать строку, а возвращает {type(return_value).__name__}"
    assert strip_empty_lines(correct_return_value_show) == strip_empty_lines(
        return_value_show
    ), "Функция возвращает неправильное значение при передаче команды show"
    assert strip_empty_lines(correct_return_value_cfg) == strip_empty_lines(
        return_value_cfg
    ), "Функция возвращает неправильное значение при передаче конфигурационных команд"
Example #2
0
def test_function_return_value(r1_test_connection,
                               first_router_from_devices_yaml):
    show_command = 'sh ip int br'
    cfg_commands = [
        'logging 10.255.255.1', 'logging buffered 20010', 'no logging console'
    ]
    correct_return_value_show = r1_test_connection.send_command(show_command)
    correct_return_value_cfg = r1_test_connection.send_config_set(cfg_commands)
    return_value_show = task_19_3.send_commands(first_router_from_devices_yaml,
                                                show=show_command)
    return_value_cfg = task_19_3.send_commands(first_router_from_devices_yaml,
                                               config=cfg_commands)
    assert return_value_show != None, "Функция ничего не возвращает"
    assert type(return_value_show) == str, "Функция должна возвращать строку"
    assert correct_return_value_show == return_value_show, \
        "Функция возвращает неправильное значение при передаче команды show"
    assert correct_return_value_cfg == return_value_cfg, \
        "Функция возвращает неправильное значение при передаче конфигурационных команд"
Example #3
0
def send_commands_to_devices(devices_list, show='', filename='', config=None):
    user = input('Username: '******'Password: '******'Enable password: '******'username'] = user
        dev['password'] = password
        dev['secret'] = enable

        result.append(send_commands(dev, show, filename, config))

    return result
Example #4
0
def send_commands_to_device(device_list,
                            show=False,
                            filename=False,
                            config=False):
    username = input('Username:'******'Password:'******'Enable secret:')
    device_list['username'] = username
    device_list['password'] = password
    device_list['secret'] = secret
    result = send_commands(device_list,
                           show=show,
                           filename=filename,
                           config=config)
    return result
Example #5
0
def send_commands_to_device(devices, limit = 2, show = False, filename = False, config = False):
    username = input('Username:'******'Password:'******'Enable secret:')
    
    ips = [device['ip'] for device in devices['routers']]
    pinger = list(check_ip_threads(check_ip_address, ips, limit))
    
    result_list = []
    for device in devices['routers']:
        if device['ip'] in pinger:
            device['username'] = username
            device['password'] = password
            device['secret'] = secret
            result = send_commands(device, show = show, filename = filename, config = config)
            result_list.append(result)
        else:
            print('{} is DOWN'.format(device['ip']))
    return result_list
Example #6
0
def send_commands_to_devices(devices_list, show='', filename='', config=None):
    user = input('Username: '******'Password: '******'Enable password: '******'ip']):
            dev = device.copy()
            dev['username'] = user
            dev['password'] = password
            dev['secret'] = enable

            result.append(send_commands(dev, show, filename, config))
        else:
            print('Device with ip address {} is not accessible'.format(
                device['ip']))

    return result
Example #7
0
def send_commands_to_device(device_list,
                            show=False,
                            filename=False,
                            config=False):
    reply = subprocess.run(['ping', '-c', '3', '-n', device_list['ip']],
                           stdout=subprocess.DEVNULL)
    if reply.returncode == 0:
        username = input('Username:'******'Password:'******'Enable secret:')
        device_list['username'] = username
        device_list['password'] = password
        device_list['secret'] = secret
        result = send_commands(device_list,
                               show=show,
                               filename=filename,
                               config=config)
        return result
    else:
        return ('The IP:{} id dead...'.format(device_list['ip']))
Example #8
0
def send_commands_to_devices(devices_list, show='', filename='', config=''):
    r = ss.send_commands(devices_list, show, filename, config)
    return r