예제 #1
0
 def setUpClass(self):
     testbed = """
     devices:
       sisf-c9500-21-8-26-2:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os iosxe --mock_data_dir mock_data --state connect
             protocol: unknown
         os: iosxe
         platform: ios
         type: ios
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['sisf-c9500-21-8-26-2']
     self.device.connect()
예제 #2
0
 def setUpClass(self):
     testbed = """
     devices:
       II23-FCCORE:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os nxos --mock_data_dir mock_data --state connect
             protocol: unknown
         os: nxos
         platform: MDS
         type: MDS
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['II23-FCCORE']
     self.device.connect()
예제 #3
0
 def setUpClass(self):
     testbed = """
     devices:
       R1_xe:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os iosxe --mock_data_dir mock_data --state connect
             protocol: unknown
         os: iosxe
         platform: csr1000v
         type: CSR1000v
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['R1_xe']
     self.device.connect()
 def setUpClass(self):
     testbed = """
     devices:
       R3_nx:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os nxos --mock_data_dir mock_data --state connect
             protocol: unknown
         os: nxos
         platform: n9kv
         type: NX-OSv 9000
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['R3_nx']
     self.device.connect()
 def test_connect_timeout(self):
     testbed = """
     devices:
       lnx-server:
         type: linux
         os: linux
         connections:
           defaults:
             class: unicon.Unicon
           cli:
             command: mock_device_cli --os linux --state login_ssh_delay
     """
     tb = loader.load(testbed)
     l = tb.devices['lnx-server']
     l.connect(connection_timeout=20)
     self.assertEqual(l.is_connected(), True)
     l.disconnect()
예제 #6
0
 def setUpClass(self):
     testbed = """
     devices:
       DCS-W5:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os iosxe --mock_data_dir mock_data --state connect
             protocol: unknown
         os: iosxe
         platform: sdwan
         type: generic
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['DCS-W5']
     self.device.connect()
 def test_connect_timeout_error(self):
     testbed = """
     devices:
       lnx-server:
         type: linux
         os: linux
         connections:
           defaults:
             class: unicon.Unicon
           cli:
             command: mock_device_cli --os linux --state login_ssh_delay
     """
     tb = loader.load(testbed)
     l = tb.devices['lnx-server']
     with self.assertRaises(UniconConnectionError) as err:
         l.connect(connection_timeout=0.5)
     l.disconnect()
예제 #8
0
 def setUpClass(self):
     testbed = """
     devices:
       LG-PK:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os iosxe --mock_data_dir mock_data --state connect
             protocol: unknown
         os: iosxe
         platform: cat9k
         type: c9300
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['LG-PK']
     self.device.connect()
 def setUpClass(self):
     testbed = """
     devices:
       leaf1-laas-c9500-4:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os iosxe --mock_data_dir mock_data --state connect
             protocol: unknown
         os: iosxe
         platform: cat
         type: cat
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['leaf1-laas-c9500-4']
     self.device.connect()
예제 #10
0
 def setUpClass(self):
     testbed = """
     devices:
       Authenticator_9400:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os iosxe --mock_data_dir mock_data --state connect
             protocol: unknown
         os: iosxe
         platform: cat9k
         type: single_rp
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['Authenticator_9400']
     self.device.connect()
예제 #11
0
 def test_connect_assign_ports_multichassis(self):
     tb_file = os.path.join(os.path.dirname(__file__), 'testbed.yaml')
     tb = loader.load(tb_file)
     dev = tb.devices.ixia5
     dev.instantiate()
     ixnet_mock = dev.default.ixNet = Mock()
     ixnet_mock.connect = Mock(return_value=True)
     ixnet_mock.OK = True
     ixnet_mock.getList = Mock(return_value=[])
     ixnet_mock.getRoot = Mock(return_value='root')
     self.assertEqual(dev.default.via, 'tgn')
     dev.connect()
     dev.assign_ixia_ports(wait_time=1)
     ixnet_mock.execute.assert_called_with(
         'assignPorts', [['1.1.1.1', '1', '1'], ['1.1.1.1', '1', '2'],
                         ['2.2.2.2', '2', '1'], ['2.2.2.2', '2', '2']], [],
         [], True)
 def setUpClass(self):
     testbed = """
     devices:
       vWLC:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os aireos --mock_data_dir mock_data --state connect
             protocol: unknown
         os: aireos
         platform: single_rp
         type: ap
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['vWLC']
     self.device.connect()
예제 #13
0
 def test_connect_timeout(self):
     testbed = """
     devices:
       lnx-server:
         type: linux
         os: linux
         connections:
           defaults:
             class: unicon.Unicon
           cli:
             command: mock_device_cli --os linux --state login_ssh_delay
     """
     tb = loader.load(testbed)
     l = tb.devices['lnx-server']
     l.connect(connection_timeout=20)
     self.assertEqual(l.spawn.match.match_output,
                      'stty rows 200\r\n[user@host ~]$ ')
     l.disconnect()
예제 #14
0
 def test_enable_secret_topology_legacy(self):
     tb = loader.load("""
     devices:
       R1:
         os: iosxe
         passwords:
             enable: Secret12345
         connections:
           cli:
             command: mock_device_cli --os iosxe --state initial_config_dialog --hostname R1
             arguments:
               log_buffer: True
               init_exec_commands: []
               init_config_commands: []
     """)
     dev = tb.devices.R1
     dev.connect()
     dev.disconnect()
예제 #15
0
    def sync_testbed(self, username, password):
        """Syncs the the testbed from the server. Note that this
        will always fetch the latest topology data from the server.

        :param username: the username that will be inserted into
            the testbed data
        :type username: str
        :param password: the password that will be inserted into
            the testbed data
        :type password: str
        """
        self._check_pyats_installed()
        from pyats.topology import loader
        testbed_yaml = self._lab.get_pyats_testbed()
        data = loader.load(io.StringIO(testbed_yaml))
        data.devices.terminal_server.connections.cli.username = username
        data.devices.terminal_server.connections.cli.password = password
        self._testbed = data
예제 #16
0
    def setUp(self):

        global testbed, testbed_file, config_file, config_file2
        global runinfo_dir, script, section, clean_up

        directory = os.path.dirname(os.path.abspath(__file__))
        testbed_file = os.path.join(directory, 'scripts', 'testbed.yaml')
        config_file = os.path.join(directory, 'scripts', 'config.yaml')
        config_file2 = os.path.join(directory, 'scripts', 'config2.yaml')

        testbed = loader.load(testbed_file)
        runinfo_dir = mkdtemp(prefix='runinfo_dir')

        script = MockTestScript()
        section = MockSection()
        clean_up = MockCleanup()
        section.parent = script
        clean_up.parent = script
예제 #17
0
파일: test_yang.py 프로젝트: ashojosh/yang
    def setUp(self):
        self.yaml = \
            'devices:\n' \
            '    dummy:\n' \
            '        type: dummy_device\n' \
            '        connections:\n' \
            '            netconf:\n' \
            '                class: yang.connector.Netconf\n' \
            '                ip : "1.2.3.4"\n' \
            '                port: 830\n' \
            '                username: admin\n' \
            '                password: admin\n'

        self.testbed = loader.load(self.yaml)
        self.device = self.testbed.devices['dummy']
        self.nc_device = yang.connector.Netconf(device=self.device,
                                                alias='nc',
                                                via='netconf')
예제 #18
0
    def perform_show_2_file(self,
                            dst_device_hostname="",
                            show_command="",
                            output_name="",
                            testbed_file=""):
        if dst_device_hostname == "":
            dst_device_hostname = self.dst_device_hostname
        if show_command == "":
            show_command = self.show_command
        if output_name == "":
            output_name = self.output_name

        testbed = load(f'/pyats/users/testbed_files/{testbed_file}')
        device = testbed.devices[dst_device_hostname]
        device.connect()
        show_command_output = device.execute(show_command)
        self.output_storage_string(output_name, show_command_output)
        return show_command_output
    def test_connect_cat9k_rommon_init_commands(self):
        steps = Steps()

        md = MockDeviceTcpWrapperIOSXECat9k(port=0,
                                            state='cat9k_rommon',
                                            hostname='R1')
        md.start()

        testbed = dedent("""
        devices:
            R1:
                os: iosxe
                platform: cat9k
                credentials:
                    default:
                        password: cisco
                connections:
                    cli:
                        command: 'telnet 127.0.0.1 {}'
                        settings:
                            POST_DISCONNECT_WAIT_SEC: 0
                            GRACEFUL_DISCONNECT_WAIT_SEC: 0.2
                            FIND_BOOT_IMAGE: False,
                            ROMMON_INIT_COMMANDS:
                                - set
                                - ping 1.1.1.1
                        arguments:
                            image_to_boot: tftp://1.1.1.1/cat9k_iosxe.SSA.bin
                            log_buffer: True
            """.format(md.ports[0]))
        tb = loader.load(testbed)
        device = tb.devices.R1

        cls = Connect()

        try:
            cls.connect(steps=steps, device=device)
        except Exception:
            raise
        finally:
            device.disconnect()
            md.stop()

        self.assertEqual(Passed, steps.details[0].result)
 def test_connect_passphrase(self):
     testbed = """
     devices:
       lnx-server:
         type: linux
         os: linux
         credentials:
           default:
             username: admin
             password: cisco
         connections:
           defaults:
             class: unicon.Unicon
           cli:
             command: mock_device_cli --os linux --state login_passphrase
     """
     tb = loader.load(testbed)
     l = tb.devices['lnx-server']
     l.connect()
예제 #21
0
 def test_linux_ENV(self):
     testbed = """
   devices:
     lnx:
       os: linux
       type: linux
       connections:
         defaults:
           class: unicon.Unicon
         vty:
           command: bash
   """
     tb = loader.load(testbed)
     l = tb.devices.lnx
     l.connect()
     term = l.execute('echo $TERM')
     self.assertEqual(term, l.settings.ENV['TERM'])
     lc = l.execute('echo $LC_ALL')
     self.assertEqual(lc, l.settings.ENV['LC_ALL'])
 def setUpClass(self):
     testbed = """
     devices:
       R3_nx:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os nxos --mock_data_dir mock_data --state connect
             protocol: unknown
         os: nxos
         platform: n9k
         type: switch
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['R3_nx']
     self.device.connect(learn_hostname=True,
                         init_config_commands=[],
                         init_exec_commands=[])
예제 #23
0
 def test_topology(self):
     testbed = """
     devices:
      Firepower:
        os: fxos
        type: fw
        credentials:
         default:
           username: admin
           password: admin
        connections:
          cli:
            command: mock_device_cli --os fxos --state fp2k_fxos_console
            arguments:
              console: True
     """
     tb = loader.load(testbed)
     tb.devices.Firepower.connect()
     tb.devices.Firepower.disconnect()
 def setUpClass(self):
     testbed = """
     devices:
       C9400-SVL:
         connections:
           defaults:
             class: unicon.Unicon
           a:
             command: mock_device_cli --os iosxe --mock_data_dir mock_data --state connect
             protocol: unknown
         os: iosxe
         platform: cat9k
         type: C9400
     """
     self.testbed = loader.load(testbed)
     self.device = self.testbed.devices['C9400-SVL']
     self.device.connect(learn_hostname=True,
                         init_config_commands=[],
                         init_exec_commands=[])
    def test_switchover(self):
        tb = loader.load(self.testbed)
        r = tb.devices.Router
        r.connect()
        asm = r.active.state_machine

        # The mocked active device immediately switches over to
        # disable mode on switchover, so ensure the dialog exits if this
        # pattern is detected.
        #
        # The reason we want this behavior is that the mocked device
        # currently does not simulate a reset cycle (in which the
        # disable state on the newly standby is a transitory state
        # seen just before reload).
        asm.add_default_statements(
            Statement(pattern=asm.get_state('disable').pattern,
                      loop_continue=False))
        r.switchover()
        r.disconnect()
def main():

    # Read the testbed.yaml file with the conection parameters (login, passwords, etc.)
    pyats_testbed = loader.load("testbed.yaml")

    # Select a device with its name
    ios1 = pyats_testbed.devices["R2"]

    # Connect to the device
    ios1.connect()

    # Run the command
    output = ios1.configure('''
        interface Ethernet2/0
            ip address 198.168.1.2 255.255.255.0
            no shut
    ''')

    # Display command output
    print("Command send:\n", output)
    def perform_parsing_command_list(self,
                                     dst_device_hostname="",
                                     output_folder_name="",
                                     testbed_file="",
                                     command_list=[]):
        if dst_device_hostname == "":
            dst_device_hostname = self.dst_device_hostname
        if output_folder_name == "":
            output_folder_name = self.output_folder_name

        os.system(f"mkdir /pyats/users/output/{output_folder_name}")
        testbed = load(f'/pyats/users/testbed_files/{testbed_file}')
        device = testbed.devices[dst_device_hostname]
        device.connect()
        for com in command_list:
            show_command_output = device.parse(com)
            output_name = output_folder_name + com.replace(" ", "")
            self.output_storage(output_folder_name, output_name,
                                show_command_output)
        return output_name
예제 #28
0
 def test_linux_TERM(self):
     testbed = """
     devices:
       lnx:
         os: linux
         type: linux
         connections:
           defaults:
             class: unicon.Unicon
           vty:
             command: bash
     """
     tb = loader.load(testbed)
     l = tb.devices.lnx
     l.connect()
     l.execute('PS1=bash#')
     # forcing the prompt pattern without $
     # echo $TERM is matched as a prompt pattern depending on timing
     l.state_machine.get_state('shell').pattern = r'^(.*?([>~%]|[^#\s]#))\s?$'
     term = l.execute('echo $TERM')
     self.assertEqual(term, l.settings.TERM)
 def test_connect_disconnect_without_learn_hostname(self):
     testbed = """
       devices:
         lnx:
           os: linux
           type: linux
           tacacs:
               username: admin
           passwords:
               linux: admin
           connections:
             defaults:
               class: unicon.Unicon
             cli:
               command: mock_device_cli --os linux --state exec
       """
     tb = loader.load(testbed)
     lnx = tb.devices.lnx
     lnx.connect()
     lnx.disconnect()
     lnx.connect()
    def setUpClass(cls):
        cls.md = MockDeviceTcpWrapperIOSXR(port=0,
                                           state='login,console_standby')
        cls.md.start()

        cls.testbed = """
        devices:
          Router:
            os: iosxr
            series: asr9k
            type: router
            tacacs:
                username: admin
            passwords:
                tacacs: admin
            connections:
              defaults:
                class: unicon.Unicon
              a:
                protocol: telnet
                ip: 127.0.0.1
                port: {}
                settings:
                  POST_HA_RELOAD_CONFIG_SYNC_WAIT: 30
                  IOSXR_INIT_EXEC_COMMANDS: []
                  IOSXR_INIT_CONFIG_COMMANDS: []
                  HA_INIT_CONFIG_COMMANDS: []
              b:
                protocol: telnet
                ip: 127.0.0.1
                port: {}
                settings:
                  POST_HA_RELOAD_CONFIG_SYNC_WAIT: 30
                  IOSXR_INIT_EXEC_COMMANDS: []
                  IOSXR_INIT_CONFIG_COMMANDS: []
                  HA_INIT_CONFIG_COMMANDS: []
        """.format(cls.md.ports[0], cls.md.ports[1])
        tb = loader.load(cls.testbed)
        cls.r = tb.devices.Router
        cls.r.connect()