def test_connect_escape_codes_learn_hostname_old(self): c = Connection( hostname='APC', start=[ 'mock_device_cli --os aci --state apic_hostname_with_escape_codes' ], os='aci', series='apic', username='******', tacacs_password='******', learn_hostname=True) c.connect()
def test_incorrect_login(self): dev = Connection(hostname='switch', start=['mock_device_cli --os nxos --state password4'], os='nxos', credentials={ 'default': { 'username': '******', 'password': '******' } }) dev.connect() dev.disconnect()
def test_reload_credentials(self): dev = Connection( hostname='', start=['mock_device_cli --os nxos --state n5k_exec'], os='nxos', series='n5k', credentials=dict(default=dict( username='******', password='******')), ) dev.connect() dev.reload() dev.disconnect()
def setUpClass(cls): cls.c = Connection( hostname='switch', start=['mock_device_cli --os iosxe --state c8kv_exec'], os='iosxe', platform='c8kv', 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_guestshell_basic(self): c = Connection(hostname='switch', start=['mock_device_cli --os nxos --state exec'], os='nxos', username='******', tacacs_password='******') with c.guestshell() as gs: output = gs.execute('pwd') self.assertEqual('/home/admin', output) self.assertIn('exit', c.spawn.match.match_output) self.assertIn('switch#', c.spawn.match.match_output)
def test_reload(self): c = Connection( hostname='LEAF', start=[ 'mock_device_cli --os nxos --state n9k_login --hostname LEAF' ], os='nxos', platform='aci', tacacs_password='******') c.connect() c.reload() c.disconnect()
def test_learn_hostname(self): c = Connection( hostname='Controller', start=[ 'mock_device_cli --os aireos --state aireos_exec --hostname "{}"' .format(hostname) ], os='aireos', username='******', learn_hostname=True, connection_timeout=3) c.connect()
def test_login_connect_invalid_connectReply(self): with self.assertRaises(SubCommandFailure) as err: c = Connection(hostname='Router', start=['mock_device_cli --os ios --state login'], os='ios', username='******', enable_password='******', tacacs_password='******', connect_reply='invalid_dialog') self.assertEqual( str(err.exception), "dialog passed via 'connect_reply' must be an instance of Dialog")
def setUpClass(cls): cls.c = Connection( hostname='Router', start=['mock_device_cli --os ios --state exec'], os='ios', credentials=dict(default=dict(username='******', password='******')), init_exec_commands=[], init_config_commands=[], settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), ) cls.c.connect()
def test_juniper_config(self): c = Connection( hostname='ncs', start=['mock_device_cli --os confd --state juniper_login'], os='confd', username='******', tacacs_password='******') c.connect() cmd = 'services sw-init-l3vpn foo endpoint PE2 pe-interface 0/0/0/1 ce CE1 ce-interface 0/1 ce-address 1.1.1.1 pe-address 1.1.1.2' r = c.configure(cmd) self.assertEqual(r['commit'], 'Commit complete.') self.assertEqual(r[cmd].replace(' \x08', ''), '')
def test_command_cisco_config(self): c = Connection(hostname='ncs', start=['mock_device_cli --os confd --state cisco_exec'], os='confd', username='******', tacacs_password='******') c.connect() r = c.command('config') self.assertEqual( "\n".join(r.splitlines()), """config Entering configuration mode terminal user@ncs(config)# """)
def test_juniper_execute_configure(self): c = Connection( hostname='ncs', start=['mock_device_cli --os confd --state juniper_login'], os='confd', username='******', tacacs_password='******') c.connect() r = c.execute('configure') self.assertEqual( r, """Entering configuration mode private\r [ok][1970-01-01 00:00:00] \r\n\n[edit]""")
def test_connect_reboot_console(self): c = Connection( hostname='vedge', start=['mock_device_cli --os sdwan --state sdwan_console'], os='sdwan', series='viptela', username='******', tacacs_password='******') c.connect() c.reload() c.execute('') self.assertEqual(c.spawn.match.match_output.split()[-1], 'vedge#')
def test_reload_credentials(self): dev = Connection( hostname='', start=['mock_device_cli --os nxos --state n5k_exec'], os='nxos', platform='n5k', credentials=dict(default=dict(username='******', password='******')), mit=True) dev.connect() dev.settings.RELOAD_RECONNECT_WAIT = 1 dev.reload() dev.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=[], log_buffer=True) c.connect() c.configure(['no logging console']) c.disconnect()
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_reload_vty(self): c = Connection( hostname='Router', start=['mock_device_cli --os iosxr --state ncs5k_enable_vty'], os='iosxr', platform='ncs5k', username='******', password='******') c.connect() c.settings.RELOAD_WAIT = 2 c.reload() self.assertIn('\r\nRP/0/RP0/CPU0:Router#', c.spawn.match.match_output)
def test_login_connect_connectReply(self): c = Connection(hostname='Router', start=['mock_device_cli --os ios --state login'], os='ios', username='******', enable_password='******', tacacs_password='******', connect_reply=Dialog([[r'^(.*?)Connected.']])) c.connect() self.assertEqual(c.spawn.match.match_output, 'end\r\nRouter#') self.assertIn("^(.*?)Connected.", str(c.connection_provider.get_connection_dialog())) c.disconnect()
def test_login_connect_ssh(self): c = Connection( hostname='ASA', start=['mock_device_cli --os asa --state connect_ssh'], os='asa', credentials=dict(default=dict(username='******', password='******'))) r = c.connect() self.assertEqual( r, 'Are you sure you want to continue connecting (yes/no)? yes\r\nPassword: cisco\r\nASA#' )
def test_bad_connect_for_password_credential_no_recovery(self): """ Ensure password retry does not happen if a credential fails. """ c = Connection( hostname='agent-lab11-pm', start=['mock_device_cli --os linux --state connect_for_password'], os='linux', credentials=dict(default=dict(username='******', password='******'), bad=dict(username='******', password='******')), login_creds=['bad', 'default']) with self.assertRaisesRegex(UniconConnectionError, 'failed to connect to agent-lab11-pm'): c.connect()
def setUpClass(cls): cls.c = Connection( hostname='Router', start=['mock_device_cli --os iosxe --state isr_exec'], os='iosxe', username='******', tacacs_password='******', enable_password='******', settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), log_buffer=True) cls.c.connect()
def test_stack_connect2(self): d = Connection( hostname='Router', start=['mock_device_cli --os iosxe --state stack_login'] * 5, os='iosxe', chassis_type='stack', username='******', tacacs_password='******', enable_password='******') d.connect() d.execute('term width 0') self.assertEqual(d.spawn.match.match_output, 'term width 0\r\nRouter#')
def test_bash(self): c = Connection(hostname='switch', start=['mock_device_cli --os nxos --state exec'], os='nxos', username='******', tacacs_password='******') with c.bash_console() as console: console.execute('ls') self.assertIn('exit', c.spawn.match.match_output) self.assertIn('switch#', c.spawn.match.match_output) c.disconnect()
def test_bash_asr(self): c = Connection( hostname='Router', start=['mock_device_cli --os iosxe --state asr_exec'], os='iosxe', credentials=dict(default=dict(username='******', password='******')), log_buffer=True) with c.bash_console() as console: console.execute('df /bootflash/') self.assertIn('exit', c.spawn.match.match_output) self.assertIn('Router#', c.spawn.match.match_output) c.disconnect()
def test_guestshell_retries_exceeded_activate(self): c = Connection(hostname='switch', start=['mock_device_cli --os nxos --state exec'], os='nxos', username='******', tacacs_password='******') with self.assertRaises(SubCommandFailure) as err: with c.guestshell(enable_guestshell=True, retries=3) as gs: gs.execute("pwd") self.assertEqual("Guestshell failed to become activated after 3 tries", str(err.exception))
def test_config_transaction_sdwan_iosxe(self): d = Connection( hostname='Router', start=['mock_device_cli --os iosxe --state sdwan_enable'], os='sdwan', platform='iosxe', credentials=dict(default=dict(username='******', password='******')), log_buffer=True) d.connect() d.configure('no logging console') d.disconnect()
def test_reload(self): dev = Connection( hostname='', start=['mock_device_cli --os nxos --state n5k_exec'], os='nxos', series='n5k', username='******', tacacs_password='******', ) dev.connect() dev.reload() dev.disconnect()
def test_configure_error_pattern(self): c = Connection( hostname='RouterRP', start=['mock_device_cli --os iosxe --state general_enable'], os='iosxe', init_exec_commands=[], log_buffer=True) c.connect() for cmd in ['ntp server vrf foo 1.2.3.4']: with self.assertRaises(SubCommandFailure) as err: r = c.configure(cmd) c.disconnect()
def test_connect_connectReply(self): c = Connection( hostname='linux', start=['mock_device_cli --os linux --state connect_ssh'], os='linux', username='******', password='******', connect_reply=Dialog([[r'^(.*?)Password:']])) c.connect() self.assertIn("^(.*?)Password:", str(c.connection_provider.get_connection_dialog())) c.disconnect()
def test_login_connect_credentials_old(self): c = Connection(hostname='APC', start=['mock_device_cli --os aci --state apic_connect'], os='aci', series='apic', credentials={ 'default': { 'username': '******', 'password': '******' } }) c.connect()