Exemple #1
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)
Exemple #2
0
    def genie_run_trigger_alias_context(self, name, device, alias, context):
        '''Call any trigger defined in the trigger datafile on device
        using a specific alias with a context (cli, xml, yang, ...)
        '''

        if not self.loaded_yamls:
            self.builtin.fail("Could not load the yaml files - Make sure you "
                              "have an uut device")

        # Set the variables to find the trigger
        device_handle = self._search_device(device)

        self.testscript.trigger_uids = Or(name + '$')
        self.testscript.trigger_groups = None
        self.testscript.triggers = deepcopy(self.trigger_datafile)
        self.testscript.verifications = None

        # Modify the parameters to include context
        self._add_abstraction_datafiles(datafile=self.testscript.triggers,
                                        name=name,
                                        context=context,
                                        device=device_handle)

        self._run_genie_trigger_verification(name=name,
                                             alias=alias,
                                             device=device,
                                             context=context)
Exemple #3
0
def main():
    datafile_path = os.path.dirname(os.path.abspath(__file__))
    datafile_path += '/datafiles'

    gRun(trigger_datafile=datafile_path + '/trigger_datafile.yaml',
         subsection_datafile=datafile_path + '/subsection_datafile.yaml',
         trigger_uids=Or(''))
Exemple #4
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)
    def test_genie_testbed_2(self):

        pyats_testbed = pyats.topology.loader.load(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'pyats_topology1.yaml'))

        self.assertCountEqual(pyats_testbed.devices.keys(), [
            'router1',
            'router2',
            'router3',
            'router4',
            'ixia',
        ])

        genie_testbed = genie.conf.base.loader.load(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'pyats_topology1.yaml'))

        self.assertCountEqual(genie_testbed.devices.keys(),
                              pyats_testbed.devices.keys())

        self.assertTrue(
            len(genie_testbed.find_devices()) == len(
                pyats_testbed.devices.values()))

        self.assertCountEqual(genie_testbed.find_devices(),
                              genie_testbed.devices.values())

        router1 = genie_testbed.devices['router1']
        self.assertEqual(router1.name, 'router1')
        self.assertEqual(router1.os, 'iosxr')

        self.assertCountEqual(genie_testbed.find_devices(),
                              genie_testbed.devices.values())

        self.assertIn(router1, genie_testbed.find_devices(os=Or('iosxr')))

        self.assertSetEqual(
            set([
                device.os
                for device in genie_testbed.find_devices(os=Or('iosxr'))
            ]), set(['iosxr']))
def main(runtime):
    parser = argparse.ArgumentParser()
    parser.add_argument('--local_users',
                        dest='expected_local_users',
                        nargs='+',
                        default=['cisco'])
    args, unknown = parser.parse_known_args()
    # Find the location of the script in relation to the job file
    local_user_check = os.path.join(os.path.dirname(__file__),
                                    'local_user_check.py')
    # Execute the testscript
    runtime.tasks.run(testscript=local_user_check,
                      taskid="Local User Check",
                      **vars(args),
                      groups=Or('golden_config', 'bar'))
Exemple #7
0
    def genie_run_verification_alias_context(self, name, device, alias,
                                             context):
        '''Call any verification defined in the verification datafile
           on device using a specific alias with a context (cli, xml, yang, ...)
        '''
        if not self.loaded_yamls:
            self.builtin.fail("Could not load the yaml files - Make sure you "
                              "have an uut device")

        # Set the variables to find the verification
        self.testscript.verification_uids = Or(name + '$')
        self.testscript.verification_groups = None
        self.testscript.verifications = deepcopy(self.verification_datafile)
        self.testscript.triggers = None

        # Modify the parameters to include context
        if name in self.testscript.verifications:
            # Add new parameters named context
            # No need to revert, as a deepcopy was taken, and after discovery
            # nothing is done with the datafiles after
            if 'devices' in self.testscript.verifications[name]:
                # For each device add context
                for dev in self.testscript.verifications[name]['devices']:
                    # To shorten the variable
                    verf = self.testscript.verifications[name]
                    if 'devices_attributes' not in verf or\
                        verf['devices_attributes'][dev] == 'None':
                        verf.setdefault('devices_attributes', {})
                        verf['devices_attributes'].setdefault(dev, {})
                        verf['devices_attributes'][dev] = {}

                    self.testscript.verifications[name]\
                                ['devices_attributes'][dev]['context'] = context

        self._run_genie_trigger_verification(name=name,
                                             alias=alias,
                                             device=device,
                                             context=context)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--trigger', dest='trigger', default=None)
    # parser.add_argument('--inventory',
    #                     dest='inventory',
    #                     default='inventory/test.yaml')
    args, unknown = parser.parse_known_args()

    test_path = os.path.dirname(os.path.abspath(__file__))
    # print(args)

    # mapping_datafile is mandatory
    # trigger_uids limit which test to execute

    if args.trigger:
        trigger = args.trigger
    else:
        trigger = RANDOM_TRIGGER

    gRun(mapping_datafile=os.path.join(test_path, 'mapping_datafile.yaml'),
         pts_datafile='pts_datafile.yaml',
         pts_features=['ospf', 'bgp'],
         trigger_uids=Or(trigger))
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')

    #
    # run the template script
    # 
    run(testscript= os.path.join(script_path, 'template.py'),
        runtime = runtime,
        labels = labels,
        routers = routers,
        links = links,
        tgns = tgns)

    #
    # run the variant script with custom args
    # 
    run(testscript= os.path.join(script_path, 'variant.py'),
        runtime = runtime,
        **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.
    #*
    #*  Read More:
    #*  http://wwwin-pyats.cisco.com/documentation/html/aetest/control.html

    #
    # eg, only run ExampleTestcase
    #
    run(testscript= os.path.join(script_path, 'template.py'),
        runtime = runtime,
        uids = Or('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.
    #*
    #*  Read More:
    #*  http://wwwin-pyats.cisco.com/documentation/html/aetest/control.html

    #
    # eg, only run testcases in group_A 
    #
    run(testscript= os.path.join(script_path, 'variant.py'),
        runtime = runtime,
        groups = Or('group_A'))
Exemple #10
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'))