def test_guestshell_enable(self): c = Connection(hostname='switch', start=['mock_device_cli --os nxos --state exec'], os='nxos', username='******', tacacs_password='******') with c.guestshell(enable_guestshell=True, retries=5) as gs: gs.execute('pwd') self.assertIn('exit', c.spawn.match.match_output) self.assertIn('switch#', c.spawn.match.match_output) # Attempt to activate again - guestshell is already active with c.guestshell(enable_guestshell=True, retries=5) as gs: gs.execute('pwd')
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_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_guestshell_activate(self): c = Connection( hostname='Router', start=[ 'mock_device_cli --os iosxe --state general_enable --hostname Router' ], os='iosxe', credentials=dict(default=dict(username='******', password='******')), log_buffer=True) with c.guestshell(enable_guestshell=True) as console: output = console.execute('pwd') self.assertEqual(output, '/home/guestshell') self.assertIn('exit', c.spawn.match.match_output) self.assertIn('Router#', c.spawn.match.match_output) c.disconnect()
def test_ha_guestshell_basic(self): ha = MockDeviceTcpWrapperNXOS(port=0, state='exec,nxos_exec_standby') ha.start() d = Connection(hostname='Router', start=['telnet 127.0.0.1 ' + str(ha.ports[0]), 'telnet 127.0.0.1 ' + str(ha.ports[1])], os='nxos', username='******', tacacs_password='******') d.connect() with d.guestshell() as gs: output = gs.execute('pwd') self.assertEqual('/home/admin', output) self.assertIn('exit', d.active.spawn.match.match_output) self.assertIn('switch#', d.active.spawn.match.match_output) d.disconnect() ha.stop()