def send_commands(device, show='', filename='', config=None): if show: return send_show_command(device, show) elif filename: return send_commands_from_file(device, filename) else: return send_config_commands(device, config)
def send_commands(device, show = False, config = False): with netmiko.ConnectHandler(**device) as ssh: ssh.enable() if show: return send_show_command(device, show) else: return send_config_commands(device, config)
def send_commands(device, show=None, config=None): r = '' if show: r = send_show_command(device, show) elif config: r = send_config_commands(device, config) return r
def send_commands(device, com): #show - функция send_show_command из задания 19.1 if com == show: result = send_show_command(device, com) return result #config - функция send_config_commands из задания 19.2 elif com == config: result = send_config_commands(device, com) return result
def send_commands(device, show='', config=''): commands = [ "logging 10.255.255.1", "logging buffered 20010", "no logging console" ] command = "sh ip int br" if show: out = (send_show_command(device, command)) if config: out = (send_config_commands(device, config)) return out
def test_function_return_value(r1_test_connection, first_router_from_devices_yaml): test_commands = [ 'logging 10.255.255.1', 'logging buffered 20010', 'no logging console' ] correct_return_value = r1_test_connection.send_config_set(test_commands) return_value = task_19_2.send_config_commands( first_router_from_devices_yaml, test_commands) assert return_value != None, "Функция ничего не возвращает" assert type(return_value) == str, "Функция должна возвращать строку" assert return_value == correct_return_value, "Функция возвращает неправильное значение"
def send_commands(device, show=False, config=False): """ Function connects to device by ssh and runs commands depending on argument(show, config). :param device: dict with parameters of device :param show: calls function send_show_command from task 19.1 :param config: calls function end_config_commands from task 19.2 :return: string with results of running commands """ if show != False: result = send_show_command(device, command) if config != False: result = send_config_commands(device, commands) return result
def send_commands(device, **kwargs): if 'show' in kwargs: #если есть show выполняем функцию send_show_command из задания 19.1 # print('we need show') command = kwargs['show'] # print(command) result = send_show_command(device, command) elif 'config' in kwargs: #если есть config выполняем функцию send_config_commands из задания 19.2 # print('we have config') conf_commands = kwargs['config'] #список команд # print(conf_commands) result = send_config_commands(device, conf_commands) else: # Если нет ни show ни config print('something wrong in ' + kwargs) return result
def test_function_return_value_different_args(r1_test_connection, first_router_from_devices_yaml): """ Проверка работы функции с другими аргументами """ test_commands = [ "interface Loopback 100", "ip address 10.1.1.100 255.255.255.255", ] correct_return_value = r1_test_connection.send_config_set(test_commands) return_value = task_19_2.send_config_commands( first_router_from_devices_yaml, test_commands) assert return_value != None, "Функция ничего не возвращает" assert ( type(return_value) == str ), f"По заданию функция должна возвращать строку, а возвращает {type(return_value).__name__}" assert strip_empty_lines(return_value) == strip_empty_lines( correct_return_value), "Функция возвращает неправильное значение"
def test_function_return_value(r1_test_connection, first_router_from_devices_yaml): """ Проверка работы функции """ test_commands = [ "logging 10.255.255.1", "logging buffered 20010", "no logging console", ] correct_return_value = r1_test_connection.send_config_set(test_commands) return_value = task_19_2.send_config_commands( first_router_from_devices_yaml, test_commands) assert return_value != None, "Функция ничего не возвращает" assert ( type(return_value) == str ), f"По заданию функция должна возвращать строку, а возвращает {type(return_value).__name__}" assert strip_empty_lines(return_value) == strip_empty_lines( correct_return_value), "Функция возвращает неправильное значение"
def send_commands(device, show=False, config=False): if show: return send_show_command(device, show) elif config: return send_config_commands(device, config)
def test_function_2(device_example, device_connection): command = "logging 1.1.1.1" result = send_config_commands(device_example, command) assert "%" not in result, "При выполнении команды возникла ошибка"
def test_function_1(device_example, device_connection): command = "logging 1.1.1.1" result = send_config_commands(device_example, command) assert command in result