def test_reload_credentials_nondefault(self): dev = Connection( hostname='', start=['mock_device_cli --os nxos --state n5k_exec'], os='nxos', series='n5k', credentials=dict(default=dict( username='******', password='******'), alt=dict( username='******', password='******')), ) dev.connect() dev.reload(reload_command="reload2", reload_creds='alt') dev.disconnect()
def test_reload(self): c = Connection( hostname='ASA', start=[ 'mock_device_cli --os asa --state asa_fp2k_console_disable' ], os='asa', platform='fp2k', credentials=dict(default=dict(username='******', password='******'), enable=dict(password='******')), ) c.connect() c.reload() c.disconnect()
def test_reload_credentials_nondefault(self): dev = Connection(hostname='', start=['mock_device_cli --os nxos --state n5k_exec'], os='nxos', platform='n5k', credentials=dict(default=dict(username='******', password='******'), alt=dict(username='******', password='******')), mit=True) dev.connect() dev.settings.RELOAD_RECONNECT_WAIT = 1 dev.reload(reload_command="reload2", reload_creds='alt') dev.disconnect()
def test_stack_config(self): c = Connection( hostname='Router', start=['mock_device_cli --os iosxe --state stack_login'] * 5, os='iosxe', chassis_type='stack', username='******', tacacs_password='******', enable_password='******') c.connect() c.configure('no logging console', target='standby') c.configure('no logging console', target='peer_3') c.peer_1.configure('no logging console')
def test_config_prompt(self): c = Connection( hostname='APC', start=['mock_device_cli --os apic --state apic_connect'], os='apic', credentials={ 'default': { 'username': '******', 'password': '******' } }) c.connect() c.configure('tenant test') c.disconnect()
def test_ha_connect_with_custom_auth_prompt(self): d = Connection(hostname='Router', start=['mock_device_cli --os ios --state custom_login,exec_standby'], username='******', tacacs_password='******', os='ios', enable_password='******') d.settings.LOGIN_PROMPT = r'Identifier:' d.settings.PASSWORD_PROMPT = r'Passe:' d.connect() d.disconnect()
def test_slow_config_mode(self): c = Connection( hostname='Switch', start=['mock_device_cli --os iosxe --state slow_config_mode'], os='iosxe', mit=True, init_exec_commands=[], init_config_commands=[], settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), log_buffer=True) c.connect() c.configure(['no logging console']) c.disconnect()
def test_juniper_to_cisco_config_clistyle(self): c = Connection( hostname='ncs', start=['mock_device_cli --os confd --state juniper_config'], os='confd', username='******', tacacs_password='******') c.connect() c.execute('configure') c.cli_style(style='c') self.assertEqual("\n".join(c.spawn.match.match_output.splitlines()), """\ switch cli user@ncs(config)# """)
def test_rommon_enable_break(self): c = Connection(hostname='switch', start=['mock_device_cli --os iosxe --state cat9k_enable_reload_to_rommon_break'], os='iosxe', platform='cat9k', mit=True, credentials=dict(default=dict(username='******', password='******'), alt=dict(username='******', password='******')), settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), log_buffer=True) c.connect() c.rommon() self.assertEqual(c.state_machine.current_state, 'rommon') c.disconnect()
def test_enable_secret(self): c = Connection( hostname='R1', start=[ 'mock_device_cli --os iosxe --state initial_config_dialog --hostname R1' ], os='iosxe', init_exec_commands=[], init_config_commands=[], credentials=dict(default=dict(password='******')), log_buffer=True) c.connect() c.configure(['no logging console']) c.disconnect()
def test_config_no_service_prompt_config(self): c = Connection( hostname='Switch', start=[ 'mock_device_cli --os iosxe --state enable_no_service_prompt_config' ], os='iosxe', mit=True, init_exec_commands=[], init_config_commands=[], log_buffer=True) c.connect() c.configure(['no logging console']) c.disconnect()
def setUpClass(cls): cls.c1 = Connection(hostname='Router1', start=['mock_device_cli --os ios --state enable'], os='ios', username='******', tacacs_password='******', enable_password='******') cls.c2 = Connection(hostname='Router2', start=['mock_device_cli --os ios --state enable'], os='ios', username='******', tacacs_password='******', enable_password='******') cls.c3 = Connection(hostname='Router3', start=['mock_device_cli --os ios --state enable'], os='ios', username='******', tacacs_password='******', enable_password='******') cls.c1.connect() cls.c2.connect() cls.c3.connect()
def setUpClass(cls): cls.c = Connection(hostname='Router', start=['mock_device_cli --os ios --state exec'], os='ios', username='******', tacacs_password='******', enable_password='******', init_exec_commands=[], init_config_commands=[]) cls.c.connect() with open(os.path.join(mockdata_path, 'ios/ios_mock_data.yaml'), 'rb') as datafile: cls.command_data = yaml.safe_load(datafile.read())
def test_connect_shell(self): c = Connection( hostname='APC', start=['mock_device_cli --os apic --state apic_shell_connect'], os='apic', credentials=dict(default=dict(username='******', password='******'))) c.connect() self.assertEqual(c.state_machine.current_state, 'shell') out = c.execute('pwd') self.assertEqual(out, '/root') c.disconnect()
def test_multi_thread_connect(self): dev_dic = { 'os': 'ios', 'hostname': 'Router', 'start': ['mock_device_cli --os ios --state login'], 'username': '******', 'tacacs_password': '******', 'enable_password': '******' } with ThreadPoolExecutor(max_workers=3) as executor: all_task = [executor.submit(Connection(**dev_dic).connect) for _ in range(3)] results = [task.result() for task in all_task]
def setUpClass(cls): cls.c = Connection( hostname='iosxrv-1', start=['mock_device_cli --os iosxr --state iosxrv9k_connect'], os='iosxr', platform='iosxrv9k', username='******', enable_password='******', learn_hostname=True, init_exec_commands=[], init_config_commands=[], connection_timeout=1, )
def setUpClass(cls): cls.c = Connection( hostname='switch', start=['mock_device_cli --os iosxe --state cat3k_exec'], os='iosxe', platform='cat3k', credentials=dict(default=dict(username='******', password='******'), alt=dict(username='******', password='******')), settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), log_buffer=True) cls.c.connect()
def test_ping_options(self): c = Connection(hostname='Router', start=['mock_device_cli --os ios --state exec'], os='ios', username='******', tacacs_password='******', enable_password='******') r = c.ping('3.3.3.3', size=1500, count=5, ping_packet_timeout=2) self.assertEqual(r, "\r\n".join("""ping Protocol [ip]: Target IP address: 3.3.3.3 Repeat count [5]: 5 Datagram size [100]: 1500 Timeout in seconds [2]: 2 Extended commands [n]: n Sweep range of sizes [n]: n Type escape sequence to abort. Sending 5, 1500-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms """.splitlines()))
def test_ping_success_vrf(self): c = Connection(hostname='Router', start=['mock_device_cli --os iosxr --state enable'], os='iosxr', username='******', tacacs_password='******', enable_password='******') r = c.ping('10.0.0.2', vrf='management') self.assertEqual(r.strip(), "\r\n".join("""ping vrf management Protocol [ip]: Target IP address: 10.0.0.2 Repeat count [5]: Datagram size [100]: Timeout in seconds [2]: Extended commands? [no]: n Sweep range of sizes? [no]: n Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 10.0.0.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/3 ms RP/0/RP0/CPU0:""".\ splitlines()))
def test_log_message_before_prompt(self): c = Connection(hostname='R1', start=['mock_device_cli --hostname R1 --os iosxr --state enable'], os='iosxr', username='******', enable_password='******', init_config_commands=[], init_exec_commands=[] ) c.connect() c.settings.IGNORE_CHATTY_TERM_OUTPUT = False c.sendline('process_restart_msg') r = c.execute('show telemetry | inc ACTIVE') self.assertIn("""process_restart_msg 0/RP0/ADMIN0:Jul 7 10:07:42.979 UTC: pm[2890]: %INFRA-Process_Manager-3-PROCESS_RESTART : Process tams (IID: 0) restarted""", r.replace('\r', '')) c.settings.IGNORE_CHATTY_TERM_OUTPUT = True c.sendline('process_restart_msg') r = c.execute('show telemetry | inc ACTIVE') self.assertEqual(r, 'Sat Jul 7 10:08:02.976 UTC\r\nState: ACTIVE')
def test_mpls_ping_success(self): c = Connection(hostname='mlx8', start=['mock_device_cli --os ironware --state exec'], os='ironware', credentials={ 'default': { 'username': '******', 'password': '******' }, 'enable': { 'password': '******' } }) c.mpls_ping(lsp='mlx8.1_to_ces.2') self.assertEqual( "\n".join(c.spawn.match.match_output.splitlines()), """ping mpls rsvp lsp mlx8.1_to_ces.2 Send 5 96-byte MPLS Echo Requests over RSVP LSP mlx8.1_to_ces.2, timeout 5000 msec Type Control-c to abort !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max=0/1/3 ms SSH@mlx8#""")
def setUpClass(cls): cls.ha = MockDeviceTcpWrapperIOS(port=0, state='login,exec_standby') md = unicon.mock.mock_device.MockDevice(device_os='ios', state='exec') cls.expected_output = md.mock_data['reload_confirm_prompt']['commands']['']['response'] cls.ha.start() cls.ha_device = Connection( hostname='Router', start=['telnet 127.0.0.1 ' + str(cls.ha.ports[0]), 'telnet 127.0.0.1 ' + str(cls.ha.ports[1])], os='ios', username='******', tacacs_password='******', enable_password='******' ) cls.ha_device.connect()
def test_admin_configure3(self): conn = Connection(hostname='Router', start=['mock_device_cli --os iosxr --state enable2'], os='iosxr', enable_password='******') conn.connect() out = conn.admin_configure('username root\nsecret 123\ngroup cisco-support\nexit') self.assertEqual('username root\r\nRP/0/0/CPU0:secret 123\r\nRP/0/0/CPU0:group cisco-support\r\n' 'RP/0/0/CPU0:exit\r\nRP/0/0/CPU0:commit\r\nRP/0/0/CPU0:', out) self.assertEqual(conn.state_machine.current_state, 'enable') conn.disconnect()
def test_ping_success_no_vrf(self): c = Connection(hostname='Router', start=['mock_device_cli --os iosxe --state isr_exec'], os='iosxe', username='******', tacacs_password='******', enable_password='******') r = c.ping('192.0.0.5', count=30) self.maxDiff = None self.assertEqual(r.strip(), "\r\n".join("""ping Protocol [ip]: Target IP address: 192.0.0.5 Repeat count [5]: 30 Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: n Sweep range of sizes [n]: n Type escape sequence to abort. Sending 30, 100-byte ICMP Echos to 192.0.0.5, timeout is 2 seconds: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Success rate is 100 percent (30/30), round-trip min/avg/max = 1/1/3 ms""".\ splitlines()))
def setUpClass(cls): cls.c = Connection( hostname='Router', start=['mock_device_cli --os iosxr --state connect_ssh'], os='iosxr', platform='asr9k', username='******', enable_password='******', line_password='******', init_exec_commands=[], init_config_commands=[], ) cls.c.connect()
def setUpClass(cls): cls.d = Connection(hostname='Router', start=['mock_device_cli --os ios --state exec'], os='ios', enable_password='******', username='******', tacacs_password='******') cls.d.connect() cls.md = MockDevice(device_os='ios', state='exec') cls.ha = MockDeviceTcpWrapperIOS(port=0, state='login,exec_standby') cls.ha.start() cls.ha_device = Connection( hostname='Router', start=[ 'telnet 127.0.0.1 ' + str(cls.ha.ports[0]), 'telnet 127.0.0.1 ' + str(cls.ha.ports[1]) ], os='ios', username='******', tacacs_password='******', enable_password='******') cls.ha_device.connect()
def test_connect_different_prompt_format(self): c = Connection(hostname='KLMER02-SU1', start=['mock_device_cli --os iosxr --state enable4'], os='iosxr') c.connect() self.assertEqual(c.spawn.match.match_output,'end\r\nRP/B0/CB0/CPU0:KLMER02-SU1#') c.disconnect()
def test_console_execute(self): c = Connection( hostname='Firepower', start=['mock_device_cli --os fxos --state chassis_exec'], os='fxos', series='ftd', username='******', tacacs_password='******', enable_password='******', line_password='******') c.connect() c.switchto('ftd expert') c.execute(['sudo su -'], reply=Dialog([password_stmt, escape_char_stmt]), allow_state_change=True)
def test_reload_credentails(self): c = Connection( hostname='APC', start=['mock_device_cli --os apic --state apic_connect'], os='apic', credentials={ 'default': { 'username': '******', 'password': '******' } }) c.connect() c.settings.POST_RELOAD_WAIT = 1 c.reload() c.disconnect()
def test_asav_reload(self): c = Connection(hostname='ASA', start=['mock_device_cli --os asa --state asa_reload'], os='asa', platform='asav', credentials=dict(default=dict(username='******', password='******'))) c.connect() c.reload()