How to use the genie.libs.sdk.libs.utils.mapping.Mapping function in genie

To help you get started, we’ve selected a few genie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / unconfigconfig / vlan / nxos / unconfigconfig.py View on Github external
(e.g) interface: '(?PEthernet1*)' (Regex supported)
                         OR
                         interface: 'Ethernet1/1/1' (Specific value)
        steps:
            1. Learn Vlan Ops object and store the "unshut" vlan(s) if has any, otherwise, SKIP the trigger
            2. Save the current device configurations through "method" which user uses
            3. Unconfigure the learned vn_segment_id with Vlan Conf object
            4. Verify the vlan(s) from step 3 are no longer existed
            5. Recover the device configurations to the one in step 2
            6. Learn Vlan Ops again and verify it is the same as the Ops in step 1

        """

    # Mapping of Information between Ops and Conf
    # Also permit to dictates which key to verify
    mapping = Mapping(requirements={'ops.vlan.vlan.Vlan':{
                                          'requirements':[['info','vlans','(?P.*)','vn_segment_id','(?P.*)']],
                                          'kwargs':{'attributes':['info[vlans][(.*)][vn_segment_id]']},
                                          'all_keys':True,
                                          'exclude': vlan_exclude}},
                      config_info={'conf.vlan.Vlan':{
                                     'requirements':[['device_attr','{uut}','vlan_attr','(?P.*)',
                                                      'vn_segment_id','(?P.*)']],
                                     'verify_conf':False,
                                     'kwargs':{}}},
                      verify_ops={'ops.vlan.vlan.Vlan':{
                                    'requirements':[['info','vlans',NotExists('(?P.*)')]],
                                    'kwargs':{'attributes':['info[vlans][(.*)][vn_segment_id]']},
                                    'exclude': vlan_exclude}},
                      num_values={'vlan':1})
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / ha / reload / iosxr / reload.py View on Github external
tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10

    steps:
        1. Learn Platform Ops object and store the "standby" RP
           if has any, otherwise, SKIP the trigger
        2. Do reload by command "admin reload location "
        3. Learn Platform Ops again and the ops are the same as the Ops in step 1
        4. Update platform PTS if feature pts is enabled,
           Update global/local veirifications if enabled

    """

    # Mapping of Information between Ops and Conf
    # Also permit to dictates which key to verify
    mapping = Mapping(requirements={'ops.platform.platform.Platform':{
                                        'requirements': [\
                                             ['virtual_device', '(?P.*)',
                                              'membership', '(?P.*)',
                                              'vd_ms_red_state', 'Backup'],
                                             ['virtual_device', '(?P.*)',
                                              'membership', '(?P.*)',
                                              'vd_ms_status', 'IOS XR RUN'],
                                          ],
                                        'exclude': platform_exclude}},
                      verify_ops={'ops.platform.platform.Platform':{
                                      'requirements': [\
                                           ['virtual_device', '(?P.*)',
                                            'membership', '(?P.*)',
                                            'vd_ms_red_state', 'Backup']],
                                    'exclude': platform_exclude}},
                      num_values={'virtual_device':1, 'standby_device': 1})
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / unconfigconfig / mld / nxos / unconfigconfig.py View on Github external
steps:
        1. Learn Mld Ops object and store the enabled Mld interface(s)'s static-groups
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Unconfigure the learned Mld interface(s)'s static-groups from step 1 
           with Mld Conf object
        4. Verify the Mld interface(s)'s static-groups from step 3
           are no longer existed
        5. Recover the device configurations to the one in step 2
        6. Learn Mld Ops again and verify it is the same as the Ops in step 1

    """
    # Mapping of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={
                          'ops.mld.mld.Mld':{
                                'requirements':[\
                                    ['info', 'vrfs', '(?P.*)', 'interfaces',
                                     '(?P.*)', 'static_group', '(?P.*)',
                                     'group', '(?P.*)'],
                                    ['info', 'vrfs', '(?P.*)', 'interfaces',
                                     '(?P.*)', 'static_group', '(?P.*)',
                                     'source', '(?P<source>\*)']],
                                'all_keys': True,
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)][interfaces][(.*)][join_group]',
                                    'info[vrfs][(.*)][interfaces][(.*)][static_group]',
                                    'info[vrfs][(.*)][interfaces][(.*)][group]']},
                                'exclude': mld_exclude + ['last_reporter']}},
                      config_info={'conf.mld.Mld':{
                                       'requirements':[
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / addremove / trm / nxos / addremove.py View on Github external
is no vrf configured on the device.
           2. Save the current device configurations using "method" specified.
           3. Add advertise evpn multicast that using Genie Vxlan Conf.
           4. Verify the newly advertise evpn multicast is reflected in
              device configuration.
           5. Restore the device configuration to the original configuration saved
              in step 2.
           6. Learn Vxaln Conf object again and verify it is the same as step 1.
    """

    @aetest.test
    def verify_configuration(self, uut, abstract, steps):
        time.sleep(30)
        super().verify_configuration(uut, abstract, steps)

    mapping = Mapping( \
        requirements={ \
            'conf.vxlan.Vxlan': {
                'requirements': [ \
                    ['device_attr', '{uut}', NotExists('advertise_evpn_multicast')]],
                'exclude': trm_exclude}},
        config_info={ \
            'conf.vxlan.Vxlan': {
                'requirements': [['device_attr', '{uut}', 'advertise_evpn_multicast', True]],
                'verify_conf': False,
                'kwargs': {}}},
        verify_ops={ \
            'conf.vxlan.Vxlan': {
                'requirements': [ \
                    ['device_attr', '{uut}', 'advertise_evpn_multicast', True]],
                'exclude': trm_exclude}},
        num_values={})
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / disableenable / bgp / nxos / disableenable.py View on Github external
steps:
        1. Learn BGP Ops object and store the BGP instance(s)
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Disable BGP feature with command "no feature bgp"
           via BGP Conf object
        4. Verify the state of feature hsrp is "disabled"
        5. Recover the device configurations to the one in step 2
        6. Verify the state of feature hsrp is "enabled" and
           learn BGP Ops again and verify it is the same as the Ops in step 1

    """

    # Mapping of Information between Ops and Conf
    # Also permit to dictates which key to verify
    mapping = Mapping(requirements={'ops.bgp.bgp.Bgp':{
                                          'requirements':[['info', 'instance', '(?P.*)',
                                                           'bgp_id', '(?P.*)']],
                                          'kwargs':{'attributes':['info']},
                                          'exclude': bgp_exclude}},
                      config_info={'conf.bgp.Bgp':{
                                     'requirements':[['device_attr', '{uut}', 'enabled', True]],
                                     'verify_conf':False,
                                     'kwargs':{'mandatory':{'bgp_id': '(?P.*)'}}}},
                      verify_ops={'ops.bgp.bgp.Bgp':{
                                    'requirements':[['info', 'instance', '(?P.*)', 'vrf',
                                                   '(?P.*)', 'neighbor', '(?P.*)',
                                                   'bgp_session_transport', 'connection', 'state',
                                                   '(^[I|i]dle.*|^[A|a]ctive.*|^[0-9].*)'],
                                                    ['info', 'instance', '(?P.*)', 'vrf',
                                                   '(?P.*)', 'neighbor', '(?P.*)',
                                                   'bgp_session_transport', 'session_state',
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / modify / dot1x / iosxe / modify.py View on Github external
# shut no shut the interface on UUT to let the session restart
        for key in self.mapping.keys:
            if hasattr(uut, 'interfaces') and key['interface'] in uut.interfaces:
                intf_conf = uut.interfaces[key['interface']]
            else:
                intf_conf = abstract.conf.interface.Interface(device=uut, name=key['interface'])
            intf_conf.enabled = False
            intf_conf.build_config()
            intf_conf.build_unconfig(attributes={'enabled': None})
            del(uut.interfaces[key['interface']])


    # Mapping of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={'ops.dot1x.dot1x.Dot1x':{
                                       'requirements':[['info', 'interfaces', '(?P.*)',
                                                        'clients', '(?P.*)', 'status', 'authorized']],
                                       'all_keys': True,
                                       'kwargs':{'attributes':['info[interfaces][(.*)][clients][(.*)][status]',
                                                               'info[sessions]']},
                                       'exclude': dot1x_exclude},
                                    'ops.fdb.fdb.Fdb':{
                                       'requirements':[['info', 'mac_table', 'vlans', '(?P.*)',
                                                        'mac_addresses', '(?P.*)',
                                                        'interfaces', '(?P.*)', 'entry_type', 'static']],
                                       'all_keys': True,
                                       'kwargs':{'attributes':['info[mac_table][vlans][(.*)]']},
                                       'exclude': fdb_exclude + ['mac_addresses']}},
                      config_info={'conf.dot1x.Dot1x':{
                                       'requirements':[['device_attr', '{uut}', 'credentials_attr', 'wrong',
                                                        'credential_username', 'wrong'],
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / addremove / acl / iosxe / addremove.py View on Github external
interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn acl Ops object and store the acls info if has any.
           Learn Interface ops object to select one trunk interface to add mac acl
        2. Save the current device configurations through "method" which user uses
        3. Add the configuration of acl with acl Conf object
        4. Verify the acl from step 3 has configured
        5. Remove the acl configurations.
        6. Recover the device configurations to the one in step 2
        7. Learn acl Ops again and verify it is the same as the Ops in step 1

    """
    ADD_ACL_NAME = 'etherent_mac_acl_add'


    mapping = Mapping(requirements={'ops.acl.acl.Acl':{
                                            'requirements':[['info', 'acls', NotExists(ADD_ACL_NAME)]],
                                            'exclude': acl_exclude},
                                    'ops.interface.interface.Interface':{
                                            'requirements':[['info', '(?P\w+Ethernet[\d\/]+$)',
                                                             'switchport_mode', 'trunk'],
                                                            ['info', '(?P\w+Ethernet[\d\/]+$)',
                                                             'oper_status', 'up']],
                                            'exclude': interface_exclude,
                                            'kwargs': {'attributes': ['info[(.*)][switchport_mode]',
                                                                      'info[(.*)][oper_status]']}}},
                      config_info={'conf.acl.Acl':{
                                      'requirements':[['device_attr', '{uut}',
                                                       'acl_attr', ADD_ACL_NAME,
                                                       'acl_type', 'eth-acl-type'],
                                                      ['device_attr', '{uut}',
                                                       'acl_attr', ADD_ACL_NAME,
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / unconfigconfig / interface / iosxr / unconfigconfig.py View on Github external
(e.g) interface: '(?PEthernet1*)' (Regex supported)
                          OR
                          interface: 'Ethernet1/1/1' (Specific value)
        steps:
            1. Learn Interface Ops object and store the "up" ethernet interface(s)
               if has any, otherwise, SKIP the trigger
            2. Save the current device configurations through "method" which user uses
            3. Unconfigure the learned ethernet interface(s) from step 1
               with Interface Conf object
            4. Verify the learned ethernet interface(s) are "down"
            5. Recover the device configurations to the one in step 2
            6. Learn Interface Ops again and verify it is the same as the Ops in step 1

        """

    mapping = Mapping(requirements={'ops.interface.interface.Interface':{
                                        'requirements':[['info', '(?P(GigabitEthernet|gigabitEthernet|TenGigE|HundredGigE)[0-9\/]+)',
                                                         'enabled', True],
                                                        ['info', '(?P(GigabitEthernet|gigabitEthernet|TenGigE|HundredGigE)[0-9\/]+)',
                                                         'oper_status', 'up']],
                                        'exclude': interface_exclude}},
                      config_info={'conf.interface.Interface':{
                                        'requirements':[],
                                        'verify_conf':False,
                                        'kwargs':{'mandatory':{'name': '(?P.*)',
                                                               'attach': False}}}},
                      verify_ops={'ops.interface.interface.Interface':{
                                        'requirements':[['info', '(?P.*)', NotExists('access_vlan')],
                                                        ['info', '(?P.*)', NotExists('switchport_enable')],
                                                        ['info', '(?P.*)', NotExists('switchport_mode')],
                                                        ['info', '(?P.*)', NotExists('trunk_vlans')],
                                                        ['info', '(?P.*)', NotExists('vrf')],
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / ha / reload / nxos / n9k / n9kv / reload.py View on Github external
steps:
        1. Learn Platform Ops object and store the "ok|active|ha-standby|standby" slot(s)
           if has any, otherwise, SKIP the trigger
        2. Do reload by command "reload"
        3. Learn Platform Ops again and verify the state of RP(s) is 
           "active|ha-standby"
           and verify the attributes from the ops are the same as the Ops in step 1
        4. Update platform PTS if feature pts is enabled,
           Update global/local veirifications if enabled

    """

    # Mapping of Information between Ops and Conf
    # Also permit to dictates which key to verify
    mapping = Mapping(requirements={'ops.platform.platform.Platform':{
                                        'requirements': [\
                                            ['slot', 'rp', '(?P<rp>.*)',
                                             'state', '(active|ha-standby)']
                                          ],
                                        'exclude': platform_exclude}},
                      verify_ops={'ops.platform.platform.Platform':{
                                      'requirements': [\
                                            ['slot', 'rp', '(?P<rp>.*)',
                                             'state', '(active|ha-standby)']],
                                    'exclude': platform_exclude}},
                      num_values={'rp': 'all'})
</rp></rp>
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / triggers / unconfigconfig / bgp / iosxe / unconfigconfig.py View on Github external
(e.g) interface: '(?PEthernet1*)' (Regex supported)
                      OR
                      interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn BGP Ops object and store the BGP instance(s)
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Unconfigure the learned BGP instance(s) from step 1
           with BGP Conf object
        4. Verify the BGP instance(s) from step 3 are no longer existed
        5. Recover the device configurations to the one in step 2
        6. Learn BGP Ops again and verify it is the same as the Ops in step 1

    """

    mapping = Mapping(requirements={'ops.bgp.bgp.Bgp':{
                                          'requirements':[['info', 'instance', '(?P.*)',
                                                           'bgp_id', '(?P.*)']],
                                        'kwargs':{'attributes':['info']},
                                        'exclude': bgp_exclude}},
                      config_info={'conf.bgp.Bgp':{
                                     'requirements':[['device_attr', '{uut}']],
                                     'verify_conf':False,
                                     'kwargs':{'mandatory':{'bgp_id': '(?P.*)'}}}},
                      verify_ops={'ops.bgp.bgp.Bgp':{
                                    'requirements': [[NotExists('info')]],
                                    'kwargs':{'attributes':['info']},
                                    'exclude': bgp_exclude}},
                      num_values={'bgp_id':'all', 'instance':'all'})