Ejemplo n.º 1
0
 def test_config_timeout(self):
     d = Connection(hostname='Router',
                    start=['mock_device_cli --os iosxr --state enable'],
                    os='iosxr')
     d.connect()
     d.configure('large config', timeout=20)
     d.disconnect()
Ejemplo n.º 2
0
 def test_exception(self):
     d = Connection(hostname='Router',
                    start=['mock_device_cli --os iosxr --state enable'],
                    os='iosxr')
     d.connect()
     with self.assertRaises(StateMachineError):
         d.configure('large config', timeout=2)
     d.disconnect()
Ejemplo n.º 3
0
 def test_config_prompt(self):
     c = Connection(hostname='APC',
                    start=['mock_device_cli --os aci --state apic_connect'],
                    os='apic',
                    credentials={'default':{
                        'username': '******',
                        'password': '******'}})
     c.connect()
     c.configure('tenant test')
Ejemplo n.º 4
0
 def test_config_transaction_sdwan_iosxe(self):
     d = Connection(hostname='Router',
                    start=['mock_device_cli --os iosxe --state sdwan_enable'],
                    os='sdwan', series='iosxe',
                    username='******',
                    tacacs_password='******',
                    enable_password='******')
     d.connect()
     d.configure('no logging console')
 def test_general_config_ca_profile(self):
     c = Connection(
         hostname='Router',
         start=['mock_device_cli --os iosxe --state general_login'],
         os='iosxe',
         username='******',
         tacacs_password='******')
     c.connect()
     c.configure("crypto pki profile enrollment test", timeout=60)
     self.assertEqual(c.spawn.match.match_output, 'end\r\nRouter#')
Ejemplo n.º 6
0
 def test_configure_commit_cmd(self):
     c = Connection(hostname='junos_vmx2',
                    start=['mock_device_cli --os junos --state exec'],
                    os='junos',
                    mit=True)
     c.connect()
     c.configure.commit_cmd = ""
     c.configure("something")
     self.assertNotIn('commit', c.spawn.match.match_output)
     c.disconnect()
Ejemplo n.º 7
0
 def test_connect_to_non_default_vdc(self):
     c = Connection(hostname='admin',
                    start=['mock_device_cli --os nxos --state vdc_exec'],
                    os='nxos',
                    init_exec_commands=[],
                    init_config_commands=[],
                    log_buffer=True)
     c.connect()
     c.switchback()
     c.configure()
 def test_connection(self):
     c = Connection(hostname='junos_dev',
                    start=['mock_device_cli --os junos --state exec5'],
                    os='junos',
                    username='******',
                    tacacs_password='******',
                    init_exec_commands=[],
                    init_config_commands=[])
     c.connect()
     with self.assertRaises(Exception):
         c.configure('commit synchronize')
 def test_configure_commit_on_failure(self):
     c = Connection(hostname='junos_dev',
                    start=['mock_device_cli --os junos --state exec3'],
                    os='junos',
                    username='******',
                    tacacs_password='******',
                    init_exec_commands=[],
                    init_config_commands=[])
     c.connect()
     with self.assertRaises(SubCommandFailure):
         c.configure('commit')
Ejemplo n.º 10
0
    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()
Ejemplo n.º 11
0
 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 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')
Ejemplo n.º 13
0
 def test_configure_are_you_sure_ywtdt(self):
     c = Connection(
         hostname='RouterRP',
         start=['mock_device_cli --os iosxe --state general_enable'],
         os='iosxe',
         mit=True,
         init_exec_commands=[],
         init_config_commands=[],
         log_buffer=True)
     c.connect()
     c.configure(
         ['crypto pki trustpoint test', 'no crypto pki trustpoint test'])
     c.disconnect()
Ejemplo n.º 14
0
    def test_config_locked(self):
        c = Connection(
            hostname='RouterRP',
            start=['mock_device_cli --os iosxe --state general_enable'],
            os='iosxe',
            mit=True,
            init_exec_commands=[],
            init_config_commands=[],
            log_buffer=True)
        c.connect()

        c.execute('set config lock count 2')
        c.settings.CONFIG_LOCK_RETRIES = 0
        c.settings.CONFIG_LOCK_RETRY_SLEEP = 0

        with self.assertRaises(StateMachineError):
            c.configure('')

        c.execute('set config lock count 2')
        with self.assertRaises(StateMachineError):
            c.configure('', lock_retries=1, lock_retry_sleep=1)

        c.execute('set config lock count 3')
        c.settings.CONFIG_LOCK_RETRIES = 1
        c.settings.CONFIG_LOCK_RETRY_SLEEP = 1
        with self.assertRaises(StateMachineError):
            c.configure('')

        c.execute('set config lock count 3')
        c.settings.CONFIG_LOCK_RETRIES = 5
        c.settings.CONFIG_LOCK_RETRY_SLEEP = 1
        c.configure('')

        c.disconnect()
Ejemplo n.º 15
0
 def test_reload_skip_poap(self):
     dev = Connection(
         hostname='N93_1',
         start=['mock_device_cli --os nxos --state login2'],
         os='nxos',
         username='******',
         tacacs_password='******',
         enable_password='******',
     )
     dev.connect()
     dev.settings.RELOAD_RECONNECT_WAIT = 1
     dev.reload(reload_command='reload skip_poap')
     dev.configure('no logging console')
     dev.disconnect()
Ejemplo n.º 16
0
 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()
Ejemplo n.º 17
0
 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()
Ejemplo n.º 18
0
 def test_reload_config_lock_retries_succeed(self):
     dev = Connection(
         hostname='N93_1',
         start=['mock_device_cli --os nxos --state login2'],
         os='nxos',
         username='******',
         tacacs_password='******',
         enable_password='******',
     )
     dev.connect()
     dev.start = ['mock_device_cli --os nxos --state reconnect_login']
     dev.reload(config_lock_retries=2, config_lock_retry_sleep=1)
     dev.configure('no logging console')
     dev.disconnect()
 def test_gkm_local_server(self):
     c = Connection(
         hostname='Router',
         start=['mock_device_cli --os iosxe --state general_login'],
         os='iosxe',
         username='******',
         tacacs_password='******')
     c.connect()
     cmd = [
         "crypto gkm group g1", "identity number 101", "server local",
         "end", "end"
     ]
     c.configure(cmd, timeout=60)
     self.assertEqual(c.spawn.match.match_output, 'end\r\nRouter#')
Ejemplo n.º 20
0
    def test_config_locked(self):
        c = Connection(hostname='RouterRP',
                       start=['mock_device_cli --os nxos --state exec'],
                       os='nxos',
                       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.execute('set config lock count 2')
        c.settings.CONFIG_LOCK_RETRIES = 0
        c.settings.CONFIG_LOCK_RETRY_SLEEP = 0

        with self.assertRaises(StateMachineError):
            c.configure('')

        c.execute('set config lock count 2')
        with self.assertRaises(StateMachineError):
            c.configure('', lock_retries=1, lock_retry_sleep=1)

        c.execute('set config lock count 3')
        c.settings.CONFIG_LOCK_RETRIES = 1
        c.settings.CONFIG_LOCK_RETRY_SLEEP = 1
        with self.assertRaises(StateMachineError):
            c.configure('')

        c.execute('set config lock count 3')
        c.settings.CONFIG_LOCK_RETRIES = 5
        c.settings.CONFIG_LOCK_RETRY_SLEEP = 1
        c.configure('')

        c.disconnect()
 def test_general_configure(self):
     c = Connection(
         hostname='Router',
         start=['mock_device_cli --os iosxe --state general_login'],
         os='iosxe',
         username='******',
         tacacs_password='******')
     c.connect()
     cmd = [
         'crypto key generate rsa general-keys modulus 2048 label ca',
         'crypto pki server ca', 'grant auto', 'hash sha256',
         'lifetime ca-certificate 3650', 'lifetime certificate 3650',
         'database archive pkcs12 password 0 cisco123', 'no shutdown'
     ]
     c.configure(cmd, timeout=60, error_pattern=[], service_dialogue=None)
     self.assertEqual(c.spawn.match.match_output, 'end\r\nRouter#')
Ejemplo n.º 22
0
    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()
Ejemplo n.º 23
0
    def test_config_transaction_sdwan_iosxe(self):
        d = Connection(
            hostname='Router',
            start=['mock_device_cli --os iosxe --state sdwan_enable'],
            os='sdwan',
            platform='iosxe',
            username='******',
            tacacs_password='******',
            enable_password='******',
            settings=dict(POST_DISCONNECT_WAIT_SEC=0,
                          GRACEFUL_DISCONNECT_WAIT_SEC=0.2),
            log_buffer=True)

        d.connect()
        d.configure('no logging console')
        d.disconnect()
Ejemplo n.º 24
0
 def test_reload_config_lock_retries_succeed_with_default(self):
     dev = Connection(
         hostname='N93_1',
         start=['mock_device_cli --os nxos --state login2'],
         os='nxos',
         username='******',
         tacacs_password='******',
         enable_password='******',
     )
     dev.connect()
     dev.start = ['mock_device_cli --os nxos --state reconnect_login']
     dev.settings.RELOAD_RECONNECT_WAIT = 1
     dev.settings.CONFIG_LOCK_RETRY_SLEEP = 1
     dev.reload()
     dev.configure('no logging console')
     dev.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',
         platform='csr100v',
         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()
Ejemplo n.º 26
0
 def test_cisco_config_error(self):
     c = Connection(hostname='ncs',
                    start=['mock_device_cli --os confd --state cisco_exec'],
                    os='confd',
                    username='******',
                    tacacs_password='******')
     c.connect()
     try:
         cmd = 'services sw-init-l3vpn foo endpoint PE1 pe-interface 0/0/0/1 ce CE1 ce-interface 0/1 ce-address 1.1.1.1 pe-address 1.1.1.2'
         c.configure(cmd)
     except SubCommandFailure as e:
         self.assertEqual(
             str(e),
             "('sub_command failure, patterns matched in the output:', ['Aborted'])",
             'Commit error not detected\n%s' % e)
     else:
         raise AssertionError('Commit error not detected')
Ejemplo n.º 27
0
 def test_cisco_config_error(self):
     c = Connection(hostname='ncs',
                    start=['mock_device_cli --os confd --state cisco_exec'],
                    os='confd',
                    username='******',
                    tacacs_password='******')
     c.connect()
     try:
         cmd = 'services sw-init-l3vpn foo endpoint PE1 pe-interface 0/0/0/1 ce CE1 ce-interface 0/1 ce-address 1.1.1.1 pe-address 1.1.1.2'
         c.configure(cmd)
     except SubCommandFailure as e:
         self.assertEqual(
             str(e),
             "('sub_command failure, patterns matched in the output:', ['Aborted'], 'service result', 'commit\\r\\nAborted: Network Element Driver: device CE1: out of sync\\r\\nadmin@ncs(config-endpoint-PE1)# *** ALARM out-of-sync: Device CE1 is out of sync\\r\\nadmin@ncs(config-endpoint-PE1)# ')"
         )
     else:
         raise AssertionError('Commit error not detected')
    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()
Ejemplo n.º 29
0
 def test_cisco_configure_command_list(self):
     c = Connection(hostname='ncs',
                    start=['mock_device_cli --os confd --state cisco_exec'],
                    os='confd',
                    username='******',
                    tacacs_password='******')
     c.connect()
     r = c.configure(['services abc', 'commit'], style='cisco')
     self.assertEqual(r, {'commit': 'Commit complete.', 'services abc': ''})
Ejemplo n.º 30
0
    def test_configure_with_msgs(self):
        md = MockDeviceTcpWrapperIOSXE(port=0, state='config_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='******')),
            connection_timeout=3,
            mit=True)
        try:
            c.connect()
            c.configure('msg')
        finally:
            c.disconnect()
            md.stop()