Esempio n. 1
0
    def verify_ospf(self, uut, helper, steps, link_2, loopback_link_2):
        '''Verify if the Ospf configuration was done correctly'''

        # Verify for both device
        for dev in [uut, helper]:
            # Find the interface of this device
            dev_intf = link_2.find_interfaces(device=dev)[0]
            neighbor_intf = link_2.find_interfaces(device=Not(str(dev)))[0]

            # Same for loopback
            intf1_loop = loopback_link_2.find_interfaces(device=dev)[0]
            intf2_loop = loopback_link_2.find_interfaces(
                device=Not(str(dev)))[0]
            ospf = dev.lib.ops.ospf.ospf.Ospf(device=dev)
            try:
                ospf.learn_poll(verify=self.interface_up,
                                sleep=10,
                                attempt=10,
                                ospf_name=self.ospf_2,
                                vrf_name=self.vrf_name,
                                area=self.area_id,
                                dev_intf=dev_intf,
                                intf1_loop=intf1_loop)
            except StopIteration as e:
                self.failed(str(e))

        time.sleep(60)
        log.info("Configuration was applied correctly")
Esempio n. 2
0
def main():

    # Find the location of the script in relation to the job file
    test_path = os.path.dirname(os.path.abspath(__file__))
    testscript = os.path.join(test_path, 'uids_example_script.py')

    #####
    # Skip Example
    #####

    #Task-1
    # Skip Container/Section that match tc_two and my_looped_testcase
    run(testscript=testscript, uids=Not('tc_two', 'my_looped_testcase'))

    #Task-2
    # Skip Container/Section that match common_setup
    run(testscript=testscript, uids=Not('common_setup'))

    # Skip Container/Section that match common_setup, and also skip
    # Container/Section that begins with loop2

    #Task-3
    # ^loop2 will match a loop of a testcase section.
    # It also demonstrate that regex can be used
    run(testscript=testscript, uids=Not('common_setup', '^loop2$'))

    #####
    # Execute Example
    #####

    #Task-4
    # Execute Container/Section that match common_setup
    run(testscript=testscript, uids=And('common_setup'))

    #Task-5
    # Execute Container/Section that match tc_two or my_looped_testcase
    run(testscript=testscript, uids=Or('tc_two', 'my_looped_testcase'))

    #Task-6
    # Execute Container/Section that match common_setup or test_two, or begins
    # with loop2
    run(testscript=testscript, uids=Or('common_setup', '^loop2', 'test_two'))

    #####
    # Skip and Execute Example
    #####

    #Task-7
    # Skip loop1, and execute tc_two, my_looped_testcase
    run(testscript=testscript,
        uids=And(Not('loop1'), Or('tc_two', 'my_looped_testcase')))

    #####
    # Default behavior
    #####

    #Task-8
    # By default everything will be executed, as no uids is specified.
    run(testscript=testscript)
Esempio n. 3
0
def get_neighbor_interface_and_device(device, interface_alias):
    """ Get neighbor interface and device from topology

        Args:
            device (`obj`): Device object
            interface_alias (`str`): interface alias

        Returns:
            Tuple: (str: neighbor interface, obj: neighbor device)

        Raises:
            None
    """
    interface = device.interfaces[interface_alias].name
    link = device.interfaces[interface_alias].link
    interface_list = link.find_interfaces(device__name=Not(device.name))

    if interface_list:
        neighbor_interface = interface_list[0]
        log.info(
            "Found interface {intf} on {device.name} has neighbor "
            "interface {neighbor_intf.name} on {neighbor_intf.device.name}".
            format(intf=interface,
                   device=device,
                   neighbor_intf=neighbor_interface))
        return neighbor_interface.name, neighbor_interface.device
    else:
        return None, None
Esempio n. 4
0
def get_interface_interfaces(device, link_name=None, opposite=False, num=0):
    """ Get interface and device

        Args:
            device ('obj'): Device object
            link_name ('str'): link name
            opposite ('bool'): find opposite device interface
            num ('int'): num of interface to return

        Returns:
            topology dictionary

        Raises:
            None
    """
    if link_name:
        link = device.interfaces[link_name].link
        intf_list = link.find_interfaces(
            device__name=Not(device.name) if opposite else device.name)
    else:
        intf_list = device.find_interfaces()

    if intf_list:
        intf_list.sort()

        if num > 0 and num <= len(intf_list):
            return intf_list[num - 1]

        return intf_list
    else:
        return {}
Esempio n. 5
0
def main():
    # Find the location of the script in relation to the job file
    test_path = os.path.dirname(os.path.abspath(__file__))
    testscript = os.path.join(test_path, 'features_example_script.py')

    run(testscript=testscript,
        uids = Not("my_skipped_testcase1", "my_skipped_testcase2"),)
Esempio n. 6
0
    def verify_basic_ospf(self, uut, helper, steps, link_1):
        '''Verify if the basic configuration of Ospf was done correctly'''

        # Verify for both device
        for dev in [uut, helper]:

            # Find the interface of this device, and the neighbor one
            dev_intf = link_1.find_interfaces(device=dev)[0]
            # TODO - Bug here
            neighbor_intf = link_1.find_interfaces(device=Not(str(dev)))[0]

            # Create an instance of Ospf Ops object for a particular device
            ospf = dev.lib.ops.ospf.ospf.Ospf(device=dev)

            # Ops objects have a builtin polling mechanism to learn a feature.
            # It will try 20 times to learn the feature, with sleep of 10 in
            # between and to verify if it was learnt correctly, will call the
            # verify function. If this function does not raise an exception,
            # then will assume it was learnt correctly.
            try:
                ospf.learn_poll(verify=self.interface_up,
                                sleep=10,
                                attempt=10,
                                ospf_name=self.ospf_1,
                                vrf_name='default',
                                area=self.area_id,
                                dev_intf=dev_intf)
            except StopIteration as e:
                self.failed(str(e))

        log.info("Configuration was applied correctly")
Esempio n. 7
0
def main():
    # Find the location of the script in relation to the job file
    test_path = os.path.dirname(os.path.abspath(__file__))
    testscript = os.path.join(test_path, 'group_example_script.py')

    #Task-1
    # Execution Group by itself
    # Only execute group1
    run(testscript=testscript, groups=Or('group1'))

    #Task-2
    # Execute testcases that are member of group1 and group2
    # We expect only the common_ to be executed, no testcase
    run(testscript=testscript, groups=And('group1', 'group2'))

    #Task-3
    # Execute testcases that are member of group1 and group3
    # We expect tc_two to be executed
    run(testscript=testscript, groups=And('group2', 'group3'))

    #Task-4
    # Combine groups and ids.
    # Execute testcase part of Group 1 or Group2 , and not tc_two
    # We expect everything except tc_two to be executed
    run(testscript=testscript,
        groups=Or('group1', 'group2'),
        uids=Not('tc_two'))

    # Create a function that tests for testcases group
    # this api tests that a testcase belongs to group 1 but not group 2
    # The argument must be stared
    def group1_not_group2(*groups):
        # Groups is evaluated on run time,  will be replaced by the groups of
        # the testcase
        # Return True/False
        # if True the testcase will execute
        return 'group1' in groups and 'group2' not in groups

    #Task-5
    # Use the above function as group callable
    # we expect everything except tc_two to be executed
    run(testscript=testscript, groups=group1_not_group2)
Esempio n. 8
0
def main(runtime):

    #
    # parse custom command-line arguments
    #
    custom_args = parser.parse_known_args()[0]

    #**************************************
    #* Log Levels
    #*
    #*  within the job file main() section, you can set the various logger's
    #*  loglevels for your following testscripts. This allows users to modify
    #*  the logging output within the job file, for various modules & etc,
    #*  without modifying testscript and libraries.

    # set log levels for various modules
    # eg, set aetest to INFO, set your library to DEBUG
    logging.getLogger('pyats.aetest').setLevel('INFO')
    logging.getLogger('libs').setLevel('DEBUG')
    logging.getLogger('pyats.aetest').setLevel('INFO')
    logging.getLogger('libs').setLevel('DEBUG')

    #
    # run a test script and provide some script argumentss
    # this will overwrite the default values set in your script.
    # also showing passing topology information arguments into script
    #
    run(testscript=os.path.join(script_path, 'base_example.py'),
        runtime=runtime,
        parameter_A='jobfile value A',
        labels=labels,
        routers=routers,
        links=links,
        tgns=tgns)

    #
    # run with a specific router
    #
    run(testscript=os.path.join(script_path, 'base_example.py'),
        runtime=runtime,
        parameter_A='jobfile value A',
        labels=labels2,
        routers=routers2,
        links=links,
        tgns=tgns)

    #
    # run the variant script with parsed custom_args and loglevel
    #
    run(testscript=os.path.join(script_path, 'variant_example.py'),
        runtime=runtime,
        loglevel=loglevel,
        **vars(custom_args))

    #**************************************
    #* Run by ID
    #*
    #*  use 'uids' feature to specify which test section uids should run.
    #*  'uids' accepts a callable argument. In this example, instead of writing
    #*  a callable function, we'll leverage datastructure.logic classes.

    #
    # eg, only run testcases with 'Testcase' in the name,
    # but not LoopingTestcase
    #
    run(testscript=os.path.join(script_path, 'base_example.py'),
        runtime=runtime,
        uids=And('.*Testcase.*', Not('ExampleTestcase')))

    #**************************************
    #* Run by Groups
    #*
    #*  use 'groups' feature to specify which testcase groups should run.
    #*  'groups' accepts a callable argument. In this example, we'll also be
    #*  using datastructure.logic classes.

    #
    # eg, only run testcases in group_A and group_C
    #
    run(testscript=os.path.join(script_path, 'variant_example.py'),
        runtime=runtime,
        groups=Or('group_A', 'group_C'))