def test_stack_connect3(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='stack_enable' + ',stack_enable'*2, stack=True) md.start() testbed = ''' devices: Router: type: router os: iosxe chassis_type: stack connections: defaults: class: 'unicon.Unicon' connections: [p1, p2, p3] p1: protocol: telnet ip: 127.0.0.1 port: {} p2: protocol: telnet ip: 127.0.0.1 port: {} p3: protocol: telnet ip: 127.0.0.1 port: {} '''.format(md.ports[0], md.ports[1], md.ports[2]) t = loader.load(testbed) d = t.devices.Router d.connect() self.assertTrue(d.active.alias == 'p1') d.execute('term width 0') d.configure('no logging console') d.disconnect() md.stop()
def setUpClass(cls): cls.md = MockDeviceTcpWrapperIOSXE( port=0, state='enable_reload_config_dialog,asr_exec_standby') cls.md.start() cls.testbed = """ devices: Router: os: iosxe type: router credentials: default: username: cisco password: cisco enable: password: Secret12345 connections: defaults: class: unicon.Unicon a: protocol: telnet ip: 127.0.0.1 port: {} b: protocol: telnet ip: 127.0.0.1 port: {} """.format(cls.md.ports[0], cls.md.ports[1]) tb = loader.load(cls.testbed) cls.r = tb.devices.Router cls.r.connect(init_config_commands=[])
def test_reload_image_from_rommon(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='cat9k_rommon') md.start() c = Connection(hostname='switch', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', platform='cat9k', mit=True, settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), credentials=dict(default=dict(username='******', password='******'), alt=dict(username='******', password='******'))) try: c.connect() self.assertEqual(c.state_machine.current_state, 'rommon') c.execute('unlock flash:') c.settings.POST_RELOAD_WAIT = 1 c.reload(image_to_boot='tftp://1.1.1.1/latest.bin') self.assertEqual(c.state_machine.current_state, 'enable') finally: c.disconnect() md.stop()
def setUpClass(cls): cls.md = MockDeviceTcpWrapperIOSXE(port=0, state='asr_login,asr_exec_standby') cls.md.start() cls.testbed = """ devices: Router: os: iosxe type: router tacacs: username: cisco passwords: tacacs: cisco connections: defaults: class: unicon.Unicon a: protocol: telnet ip: 127.0.0.1 port: {} b: protocol: telnet ip: 127.0.0.1 port: {} """.format(cls.md.ports[0], cls.md.ports[1])
def setUpClass(cls): cls.md = MockDeviceTcpWrapperIOSXE(port=0, state='general_enable') cls.md.start() telnet_port = cls.md.ports[0] tb_file = os.path.join(os.path.dirname(__file__), 'testbed.yaml') tb = loader.load(tb_file) tb.devices.pagent.connections.tgn['ip'] = '127.0.0.1' tb.devices.pagent.connections.tgn['port'] = telnet_port cls.dev = tb.devices.pagent
def test_quad_connect3(self): md = MockDeviceTcpWrapperIOSXE( port=0, quad=True, state='quad_login,quad_ics_login,quad_stby_login,quad_ics_login') md.start() testbed = ''' devices: Router: type: router os: iosxe chassis_type: quad credentials: default: password: cisco username: cisco enable: password: cisco username: cisco connections: defaults: class: 'unicon.Unicon' connections: [a, b, c, d] a: protocol: telnet ip: 127.0.0.1 port: {} member: 1 b: protocol: telnet ip: 127.0.0.1 port: {} member: 1 c: protocol: telnet ip: 127.0.0.1 port: {} member: 2 d: protocol: telnet ip: 127.0.0.1 port: {} member: 2 '''.format(md.ports[0], md.ports[1], md.ports[2], md.ports[3]) t = loader.load(testbed) d = t.devices.Router d.connect() self.assertTrue(d.active.alias == 'a') d.execute('term width 0') d.configure('no logging console') d.disconnect() md.stop()
def test_configure_with_msgs2(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='config_with_msgs2') md.start() c = Connection( hostname='Router', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', credentials=dict(default=dict(username='******', password='******')), mit=True) try: c.connect() c.configure('msg') finally: c.disconnect() md.stop()
def setUpClass(cls): cls.md = MockDeviceTcpWrapperIOSXE( port=0, quad=True, state='quad_login,quad_ics_login,quad_stby_login,quad_ics_login') cls.md.start() cls.d = Connection( hostname='Router', start=['telnet 127.0.0.1 ' + str(i) for i in cls.md.ports[:]], os='iosxe', chassis_type='quad', username='******', tacacs_password='******', enable_password='******') cls.d.connect()
def test_reload(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='stack_enable' + ',stack_enable'*4, stack=True) md.start() d = Connection(hostname='Router', start = ['telnet 127.0.0.1 ' + str(i) for i in md.ports[:]], os='iosxe', chassis_type='stack', username='******', tacacs_password='******', enable_password='******') d.settings.STACK_POST_RELOAD_SLEEP = 0 d.connect() self.assertTrue(d.active.alias == 'peer_1') d.reload() d.disconnect() md.stop()
def test_iol_pagent_start_send(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='enable', mock_data_dir='mock_data', hostname='pagent') md.start() telnet_port = md.ports[0] tb_file = os.path.join(os.path.dirname(__file__), 'testbed.yaml') tb = loader.load(tb_file) tb.devices.pagent.connections.tgn['ip'] = '127.0.0.1' tb.devices.pagent.connections.tgn['port'] = telnet_port dev = tb.devices.pagent try: dev.connect() dev.send_rawip(interface='Gi0/0', mac_src='00:de:ad:be:ef:ff', mac_dst='', ip_src='', ip_dst='') finally: md.stop()
def test_stack_connect(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='stack_login' + ',stack_login'*4, stack=True) md.start() d = Connection(hostname='Router', start = ['telnet 127.0.0.1 ' + str(i) for i in md.ports[:]], os='iosxe', chassis_type='stack', username='******', tacacs_password='******', enable_password='******') d.connect() self.assertTrue(d.active.alias == 'peer_2') d.execute('term width 0') d.configure('no logging console') d.disconnect() md.stop()
def test_execute_with_msgs(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='enable_with_msgs') md.start() c = Connection( hostname='Router', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), credentials=dict(default=dict(username='******', password='******')), mit=True) try: c.connect() c.execute('msg') finally: c.disconnect() md.stop()
def test_quad_connect(self): md = MockDeviceTcpWrapperIOSXE( port=0, quad=True, state='quad_login,quad_ics_login,quad_stby_login,quad_ics_login') md.start() d = Connection( hostname='Router', start=['telnet 127.0.0.1 ' + str(i) for i in md.ports[:]], os='iosxe', chassis_type='quad', username='******', tacacs_password='******', enable_password='******') d.connect() self.assertTrue(d.active.alias == 'a') d.disconnect() md.stop()
def test_login_console_server_post_cred_action(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='ts_login') md.start() c = Connection(hostname='Router', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', credentials=dict(default=dict(username='******', password='******'), ts=dict(username='******', password='******')), login_creds=['ts', 'default'], cred_action=dict(ts=dict(post='sendline()')), connection_timeout=10) try: c.connect() finally: c.disconnect() md.stop()
def test_slow_config_lock(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='config_locked') md.start() c = Connection( hostname='Router', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', mit=True, log_buffer=True, ) try: c.connect() c.settings.CONFIG_TIMEOUT = 5 c.settings.CONFIG_LOCK_RETRY_SLEEP = 3 c.configure(['no logging console']) finally: c.disconnect() md.stop()
def test_bash(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='stack_enable' + ',stack_enable'*4, stack=True) md.start() try: d = Connection(hostname='Router', start = ['telnet 127.0.0.1 ' + str(i) for i in md.ports[:]], os='iosxe', chassis_type='stack', username='******', tacacs_password='******', enable_password='******') d.connect() with d.bash_console() as console: console.execute('df /bootflash/') self.assertIn('exit', d.spawn.match.match_output) self.assertIn('Router#', d.spawn.match.match_output) d.disconnect() finally: md.stop()
def test_boot_from_rommon(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='cat9k_rommon') md.start() c = Connection( hostname='switch', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', platform='cat9k', settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), credentials=dict(default=dict(username='******', password='******'), alt=dict(username='******', password='******')) ) try: c.connect() self.assertEqual(c.state_machine.current_state, 'enable') finally: c.disconnect() md.stop()
def test_boot_from_rommon_with_image(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='cat3k_rommon') md.start() c = Connection( hostname='Router', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', platform='cat3k', settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2), credentials=dict(default=dict(username='******', password='******')), image_to_boot='flash:rp_super_universalk9.edison.bin', log_buffer=True) try: c.connect() self.assertEqual(c.state_machine.current_state, 'enable') finally: c.disconnect() md.stop()
def test_login_console_server_sendline_after(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='ts_login') md.start() c = Connection(hostname='Router', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', settings=dict(POST_DISCONNECT_WAIT_SEC=0, GRACEFUL_DISCONNECT_WAIT_SEC=0.2, SENDLINE_AFTER_CRED='ts'), credentials=dict(default=dict(username='******', password='******'), ts=dict(username='******', password='******')), login_creds=['ts', 'default'], connection_timeout=10) try: c.connect() finally: c.disconnect() md.stop()
def test_ping_failed_protocol(self): md = MockDeviceTcpWrapperIOSXE(port=0, state='ping_fail', hostname='PE1') md.start() c = Connection(hostname='PE1', start=['telnet 127.0.0.1 {}'.format(md.ports[0])], os='iosxe', connection_timeout=10, mit=True) try: c.connect() try: c.ping('10.10.10.10') except Exception: pass c.configure() except Exception: raise finally: c.disconnect() md.stop()
def setUpClass(self): self.md = MockDeviceTcpWrapperIOSXE(hostname='R1', port=0, state='general_enable') self.md.start() testbed = """ testbed: servers: http: dynamic: true protocol: http ftp: dynamic: true protocol: ftp tftp: dynamic: true protocol: tftp devices: R1: os: iosxe type: router tacacs: username: cisco passwords: tacacs: cisco connections: defaults: class: unicon.Unicon a: protocol: telnet ip: 127.0.0.1 port: {} """.format(self.md.ports[0]) self.testbed = loader.load(testbed) self.device = self.testbed.devices['R1'] self.device.connect(mit=True)