Example #1
0
class TriggerUnconfigConfigEthernetInterface(TriggerUnconfigConfig):
    """Unconfigure and reapply the whole configurations of dynamically learned Ethernet interface(s)."""

    __description__ = """Unconfigure and reapply the whole configurations of dynamically learned Ethernet interface(s).

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                interface: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (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 configurations are all gone for the learned Ethernet interface(s)
        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

    """

    def remove_related_subinterface(item, interface, **kwargs):
        # Easiest way is to split at the dot, and see if it exists in name
        modified_item = item.split('.')[0]

        # If it remained the same, dont waste time
        if item == modified_item:
            return False

        # See if the modified_item exists in the list of name
        if modified_item in interface:
            return True
        return False

    mapping = Mapping(requirements={'ops.interface.interface.Interface':{
                                        'requirements':[['info', '(?P<interface>(GigabitEthernet|gigabitEthernet|Ethernet|ethernet)[0-9\/]+$)',
                                                         'enabled', True],
                                                        ['info', '(?P<interface>(GigabitEthernet|gigabitEthernet|Ethernet|ethernet)[0-9\/]+$)',
                                                         'port_channel', 'port_channel_member', False],
                                                        ['info', '(?P<interface>(GigabitEthernet|gigabitEthernet|Ethernet|ethernet)[0-9\/]+$)',
                                                         'oper_status', 'up']],
                                        'exclude': interface_exclude}},
                      config_info={'conf.interface.Interface':{
                                        'requirements':[],
                                        'verify_conf':False,
                                        'kwargs':{'mandatory':{'name': '(?P<interface>.*)',
                                                               'attach': False}}}},
                      verify_ops={'ops.interface.interface.Interface':{
                                        'requirements':[['info', '(?P<interface>.*)', 'vrf', 'default'],
                                                        ['info', '(?P<interface>.*)', 'enabled', False],
                                                        ['info', '(?P<interface>.*)', 'oper_status', 'down'],
                                                        ['info', '(?P<interface>.*)', 'delay', '(\d+)'],
                                                        ['info', '(?P<interface>.*)', 'bandwidth', '(\d+)'],
                                                        ['info', '(?P<interface>.*)', 'encapsulation', 'encapsulation', '(\S+)'],
                                                        ['info', '(?P<interface>.*)', 'mac_address', '(\S+)'],
                                                        ['info', '(?P<interface>.*)', 'medium', '(\S+)'],
                                                        ['info', '(?P<interface>.*)', 'mtu', '(\d+)'],
                                                        ['info', '(?P<interface>.*)', 'port_channel', 'port_channel_member', False]],
                                        'exclude': interface_exclude +\
                                                   [remove_related_subinterface, '(Vlan.*)']}},
                      num_values={'interface': 1})
Example #2
0
class TriggerShutNoShutBgpNeighbors(TriggerShutNoShut):
    """Shut and unshut the dynamically learned BGP neighbore(s)."""

    __description__ = """Shut and unshut the dynamically learned BGP neighbore(s).

        trigger_datafile:
            Mandatory:
                timeout:
                    max_time (`int`): Maximum wait time for the trigger,
                                    in second. Default: 180
                    interval (`int`): Wait time between iteration when looping is needed,
                                    in second. Default: 15
            Optional:
                tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                     restored to the reference rate,
                                     in second. Default: 60
                tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                                   in second. Default: 10
                timeout_recovery:
                    Buffer recovery timeout make sure devices are recovered at the end
                    of the trigger execution. Used when previous timeouts have been exhausted.

                    max_time (`int`): Maximum wait time for the last step of the trigger,
                                    in second. Default: 180
                    interval (`int`): Wait time between iteration when looping is needed,
                                    in second. Default: 15
                static:
                     The keys below are dynamically learnt by default.
                     However, they can also be set to a custom value when provided in the trigger datafile.

                     instance: `str`
                     vrf: `str`
                     neighbor: `str`
                     bgp_id: `int`

                    (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                          OR
                          interface: 'Ethernet1/1/1' (Specific value)
        steps:
            1. Learn BGP Ops object and verify if has established state, otherwise, Skip the trigger.
            2. Shut the BGP neighbor that learned from step 1 with BGP Conf object
            3. Verify the state of learned neighbor(s)
               from step 2 is "down"
            4. Unshut the BGP neighbor(s)
            5. 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<instance>.*)',
                        'vrf', '(?P<vrf>.*)', 'neighbor', '(?P<neighbor>.*)',
                        'session_state', 'established'],
                        ['info', 'instance', '(?P<instance>.*)', 'bgp_id', '(?P<bgp_id>.*)']],
                    'all_keys':True, 
                    'kwargs':
                        {'attributes':['info']},
                    'exclude': bgp_exclude}},
            config_info={\
                'conf.bgp.Bgp': {
                    'requirements':[\
                        ['device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                        'neighbor_attr', '(?P<neighbor>.*)', 'nbr_shutdown', True]],
                    'verify_conf':False,
                    'kwargs':{'mandatory':{'bgp_id': '(?P<bgp_id>.*)'}}}},
            verify_ops={\
                'ops.bgp.bgp.Bgp': {
                    'requirements':[\
                        ['info', 'instance', '(?P<instance>.*)', 'vrf',
                        '(?P<vrf>.*)', 'neighbor', '(?P<neighbor>.*)',
                        'session_state', 'idle'],
                        ['info', 'instance', '(?P<instance>.*)', 'vrf',
                        '(?P<vrf>.*)', 'neighbor', '(?P<neighbor>.*)',
                        'shutdown', True]],
                    'kwargs':
                        {'attributes':['info']},
                    'exclude': bgp_exclude}},
            num_values={'instance':1, 'vrf':1, 'neighbor': 'all'})
Example #3
0
class TriggerUnconfigConfigVxlanNveOverlayInterface(TriggerUnconfigConfig):
    """Unconfigure and reapply the dynamically learned Nve onverlay interface(s)."""

    __description__ = """Unconfigure and reapply the dynamically learned Nve onverlay interface(s).

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn VxLan Ops object and verify if has any "up" Nve interface(s),
           otherwise, SKIP the trigger
        2. Unconfigure the learned Nve interface(s) from step 1 with Interface Conf object
        3. Verify the state of learned Nve interface(s) from step 2 is removed
        4. Reapply the configuration of Nve interface(s) with checkpoint
        5. Learn VxLan 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.vxlan.vxlan.Vxlan': {
                'requirements': [['nve', '(?P<name>.*)', 'if_state', 'up']],
                'kwargs': {
                    'attributes':
                    ['nve[(.*)][if_state]', 'nve[(.*)][vni][(.*)][vni]']
                },
                'exclude': nve_exclude
            }
        },
        config_info={
            'conf.interface.Interface': {
                'requirements': [],
                'verify_conf': False,
                'kwargs': {
                    'mandatory': {
                        'name': '(?P<name>.*)',
                        'attach': False
                    }
                }
            }
        },
        verify_ops={
            'ops.vxlan.vxlan.Vxlan': {
                'requirements': [['nve', '(?P<name>.*)']],
                'kwargs': {
                    'attributes':
                    ['nve[(.*)][if_state]', 'nve[(.*)][vni][(.*)][vni]']
                },
                'exclude': nve_exclude
            }
        },
        num_values={'name': 1})
Example #4
0
class TriggerShutNoShutBgp(TriggerShutNoShut):
    """Shut BGP protocol by shutdown the dynamically learned BGP process,
    then unshut it by restart bpm. """

    __description__ = """Shut BGP protocol by shutdown the dynamically learned BGP process,
    then unshut it by restart bpm.

    trigger_datafile:
        Mandatory:
            timeout:
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery:
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                 The keys below are dynamically learnt by default.
                 However, they can also be set to a custom value when provided in the trigger datafile.

                 instance: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (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. Do "process shutdown bgp"
        3. Verify the state of BGP instance(s) is "KILLED"
        4. Do "process restart bpm"
        5. 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<instance>.*)',
              '(?P<instance_info>.*)']],
            'kwargs': {
                'attributes': ['info']
            },
            'exclude':
            bgp_exclude
        }
    },
                      verify_ops={
                          'ops.bgp.bgp.Bgp': {
                              'requirements': [[
                                  'info', 'instance', '(?P<instance>.*)',
                                  'protocol_state', 'KILLED'
                              ],
                                               [
                                                   'info', 'instance',
                                                   '(?P<instance>.*)', '(.*)'
                                               ]],
                              'kwargs': {
                                  'attributes': ['info']
                              },
                              'exclude':
                              bgp_exclude
                          }
                      },
                      num_values={'instance': 'all'})
Example #5
0
class TriggerUnconfigConfigPhysicalTrunkInterface(TriggerUnconfigConfig):
    """Unconfigure and reapply the whole configurations of dynamically learned physical trunk interface(s)."""

    __description__ = """Unconfigure and reapply the whole configurations of dynamically learned physical trunk interface(s).

    trigger_datafile:
        Mandatory:
            timeout:
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery:
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                interface: `str`
                port_channel_int: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                      OR
                      interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn Interface Ops object and store the "up" physical trunk interface(s)
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Unconfigure the learned physical trunk interface(s) from step 1
           with Interface Conf object
        4. Verify the learned physical trunk 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 of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={'ops.interface.interface.Interface':{
                                       'requirements':[['info', '(?P<interface>\w+Ethernet[\d\/\.]+)',
                                                        'switchport_mode', 'trunk'],
                                                       ['info', '(?P<interface>\w+Ethernet[\d\/\.]+)',
                                                        'port_channel', 'port_channel_int', '(?P<port_channel_int>.*)']],
                                       'exclude': interface_exclude}},
                      config_info={'conf.interface.Interface':{
                                       'requirements':[],
                                       'verify_conf':False,
                                       'kwargs':{'mandatory':{'name': '(?P<interface>.*)',
                                                              'attach': False}}}},
                      verify_ops={'ops.interface.interface.Interface':{
                                       'requirements':[['info', '(?P<interface>.*)', 'oper_status', 'down'],
                                                       ['info', '(?P<interface>.*)', 'enabled', False],
                                                       ['info', '(?P<interface>.*)', 'port_channel',
                                                        'port_channel_member', False],
                                                       ['info', '(?P<interface>.*)', 'mac_address', '([\w\.]+)'],
                                                       ['info', '(?P<interface>.*)', '(.*)'],
                                                       ['info', '(?P<port_channel_int>.*)', 'port_channel', 'port_channel_member_intfs', '(.*)'],
                                                       ['info', '(Port-channel.*)', 'mac_address', '(.*)'],
                                                       ['info', '(Port-channel.*)', 'phys_address', '(.*)']],
                                       'exclude': interface_exclude}},
                      num_values={'interface':1})
Example #6
0
class TriggerAddRemoveBgpNeighborRoutemapPrefixlist(TriggerAddRemove):
    """Apply the inbound dynamically learned "prefix-list" route-map
    to the dynamically learned BGP neighbor(s), and remove the
    added route-map configurations.
    """

    __description__ = """Apply the inbound dynamically learned "prefix-list" route-map
    to the dynamically learned BGP neighbor(s), and remove the
    added route-map configurations.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iterations when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iterations when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                instance: `str`
                vrf: `str`
                address_family: `str`
                neighbor: `str`
                policy_definition: `str`
                statements: `str`
                bgp_id: `int`
                bgp_table_version: `int`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                    OR
                    interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn BGP Ops object and store the BGP neighbor(s) if has any,
           otherwise, SKIP the trigger. Learn RoutePolicy Ops object
           to store the route-map name with prefix-list configured if has any,
           otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Add the configuration of the inbound route-map (step 1) to learned
           BGP neighbor(s) from step 1 with BGP Conf object
        4. Verify the BGP neighbor(s) from step 3 has inbound route-map (step 1) configured
        5. Remove the route-map (step 1) configurations from the learned
           BGP neighbor(s) from step 1
        6. Recover the device configurations to the one in step 2
        7. Learn BGP Ops again and verify it is the same as the Ops in step 1

    """
    mapping = Mapping(
        requirements={
            'ops.route_policy.route_policy.RoutePolicy': {
                'requirements': [[
                    'info', '(?P<policy_definition>.*)', 'statements',
                    '(?P<statements>.*)', 'conditions', 'match_prefix_list',
                    '(?P<match_prefix_list>.*)'
                ]],
                'exclude':
                route_map_exclude
            },
            'ops.bgp.bgp.Bgp': {
                'requirements': [[
                    'info', 'instance', '(?P<instance>.*)', 'vrf',
                    '(?P<vrf>.*)', 'neighbor', '(?P<neighbor>.*)',
                    'address_family', '(?P<address_family>.*)',
                    'bgp_table_version', '(?P<bgp_table_version>.*)'
                ],
                                 [
                                     'info', 'instance', '(?P<instance>.*)',
                                     'bgp_id', '(?P<bgp_id>.*)'
                                 ]],
                'all_keys':
                True,
                'kwargs': {
                    'attributes': ['info']
                },
                'exclude':
                bgp_exclude
            }
        },
        config_info={
            'conf.bgp.Bgp': {
                'requirements': [[
                    'device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                    'neighbor_attr', '(?P<neighbor>.*)', 'address_family_attr',
                    '(?P<address_family>.*)', 'nbr_af_route_map_name_in',
                    '(?P<policy_definition>.*)'
                ]],
                'verify_conf':
                False,
                'kwargs': {
                    'mandatory': {
                        'bgp_id': '(?P<bgp_id>.*)'
                    }
                }
            }
        },
        verify_ops={
            'ops.bgp.bgp.Bgp': {
                'requirements': [[
                    'info', 'instance', '(?P<instance>.*)', 'vrf',
                    '(?P<vrf>.*)', 'neighbor', '(?P<neighbor>.*)',
                    'address_family', '(?P<address_family>.*)',
                    'route_map_name_in', '(?P<policy_definition>.*)'
                ]],
                'kwargs': {
                    'attributes': ['info']
                },
                'exclude':
                bgp_exclude
            }
        },
        num_values={
            'policy_definition': 1,
            'statements': 'all',
            'match_prefix_list': 1,
            'instance': 1,
            'vrf': 1,
            'address_family': 1,
            'neighbor': 1,
            'bgp_id': 1,
            'bgp_table_version': 1
        })
Example #7
0
class TriggerSwitchover(CommonSwitchover):
    """Do switchover on device."""

    __description__ = """Do switchover on device.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                active_rp: `str`
                standby_rp: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                    OR
                    interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn Platform Ops object and store the "active" RP and "standby" RP
           if has any, otherwise, SKIP the trigger
        2. Do switchover by command "redundancy force-switchover"
        3. Learn Platform Ops again and verify the roles of 
           "active" RP and "standby" RP are swapped,
           and verify left 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<active_rp>.*)',
                                              'redundancy_state', 'ACTIVE'],
                                            ['slot', 'rp', '(?P<active_rp>.*)',
                                              'state', 'ok, active']],
                                            [['slot', 'rp', '(?P<standby_rp>.*)',
                                              'redundancy_state', 'STANDBY HOT'],
                                            ['slot', 'rp', '(?P<standby_rp>.*)',
                                              'state', 'ok, standby']],
                                            [['redundancy_communication', True]],
                                          ],
                                        'all_keys': True,
                                        'exclude': platform_exclude}},
                      verify_ops={'ops.platform.platform.Platform':{
                                      'requirements': [\
                                          ['slot', 'rp', '(?P<active_rp>.*)',
                                           'redundancy_state', 'STANDBY HOT'],
                                          ['slot', 'rp', '(?P<active_rp>.*)',
                                           'state', 'ok, standby'],
                                          ['slot', 'rp', '(?P<standby_rp>.*)',
                                           'redundancy_state', 'ACTIVE'],
                                          ['slot', 'rp', '(?P<standby_rp>.*)',
                                           'state', 'ok, active']],
                                    'exclude': platform_exclude}},
                      num_values={'active_rp':1, 'standby_rp':1})
Example #8
0
class TriggerUnconfigConfigMsdpSaFilterIn(TriggerUnconfigConfig):
    """Unconfigure and reapply the whole configurations of dynamically
    learned MSDP peer(s) sa-filter in."""

    __description__ = """Unconfigure and reapply the whole configurations of dynamically
    learned MSDP peer(s) sa-filter in.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                vrf: `str`
                peer: `str`
                sa_filter_in: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                      OR
                      interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn Msdp Ops object and store the "established" MSDP peer(s) sa-filter in
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Unconfigure the learned MSDP peer(s) sa-filter in from step 1 
           with Msdp Conf object
        4. Verify the MSDP peer(s) sa-filter in from step 3 are no longer existed
        5. Recover the device configurations to the one in step 2
        6. Learn Msdp 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.msdp.msdp.Msdp':{
                                          'requirements':[\
                                              ['info', 'vrf', '(?P<vrf>.*)', 'peer',
                                               '(?P<peer>.*)', 'session_state', 'established'],
                                              ['info', 'vrf', '(?P<vrf>.*)', 'peer', '(?P<peer>.*)',
                                               'sa_filter', 'in', '(?P<sa_filter_in>.*)']],
                                          'kwargs':{'attributes': [
                                              'info[vrf][(.*)][peer][(.*)][session_state]',
                                              'info[vrf][(.*)][peer][(.*)][sa_filter]']},
                                          'exclude': msdp_exclude}},
                      config_info={'conf.msdp.Msdp':{
                                       'requirements':[
                                         ['device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                                          'peer_attr', '(?P<peer>.*)', 'sa_filter_in','(?P<sa_filter_in>.*)']],
                                       'verify_conf':False,
                                       'kwargs':{}}},
                      verify_ops={'ops.msdp.msdp.Msdp':{
                                    'requirements':[\
                                      ['info', 'vrf', '(?P<vrf>.*)', 'peer', '(?P<peer>.*)',
                                       'sa_filter', NotExists('in')]], # , '(?P<sa_filter_in>.*)'
                                    'kwargs':{'attributes': ['info[vrf][(.*)][peer][(.*)][session_state]',
                                                             'info[vrf][(.*)][peer][(.*)][sa_filter]']},
                                    'exclude': msdp_exclude}},
                      num_values={'vrf': 1, 'peer':1})
Example #9
0
class TriggerAddRemoveIgmpVersion(TriggerAddRemove):
    """Apply Igmp interface version, and remove added Igmp interface version"""

    __description__ = """Apply Igmp interface version, and remove added Igmp interface version.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn Igmp Ops object and store the Igmp which interface version is default value.
        2. Save the current device configurations through "method" which user uses
        3. Add the configuration of igmp interface version with Igmp Conf object
        4. Verify the igmp interface version from step 3 has configured
        5. Remove the igmp interface version configurations.
        6. Recover the device configurations to the one in step 2
        7. Learn Igmp Ops again and verify it is the same as the Ops in step 1

    """
    ADD_VERSION = 3
    # Mapping of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={
                          'ops.igmp.igmp.Igmp':{
                                'requirements':[\
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<igmp_intf>.*)', 'enable', True],
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<igmp_intf>.*)', 'version', '(?P<version>2)']],
                                'all_keys': True,
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)]']},
                                'exclude': igmp_exclude}},
                      config_info={'conf.igmp.Igmp':{
                                       'requirements':[
                                         ['device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                                          'interface_attr', '(?P<igmp_intf>.*)', 'version',
                                          ADD_VERSION]],
                                       'verify_conf':False,
                                       'kwargs':{}}},
                      verify_ops={
                          'ops.igmp.igmp.Igmp':{
                                'requirements':[\
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<igmp_intf>.*)', 'version', ADD_VERSION]],
                                'missing': False,
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)]']},
                                'exclude': igmp_exclude}},
                      num_values={'vrf': 1, 'igmp_intf': 1})
Example #10
0
class TriggerAddRemoveNveAdvertiseVirtualRmac(TriggerAddRemove):
    """Add Virtual rmac advertised under vxlan and then restore the
            configuration by reapplying the whole running configuration"""

    __description__ = """Add msite bgw delay restore time under Vxlan then restore the
                           configuration by reapplying the whole running configuration

           trigger_datafile:
               Mandatory Arguments:
                   timeout:
                       max_time (`int`): Maximum wait time for the trigger in seconds.
                                         Default: 180
                       interval (`int`): Wait time between iteration when looping is
                                         needed in seconds. Default: 15
                       method (`str`): Method to recover the device configuration.
                                       Supported methods:
                                           'checkpoint': Rollback the configuration
                                                         using checkpoint (nxos),
                                                         archive file (iosxe),
                                                         load the saved running-config
                                                         file on disk (iosxr)
               Optional Arguments:
                   tgn_timeout (`int`): Maximum wait time for all traffic streams to be
                                        restored to the reference rate in seconds.
                                        Default: 60
                   tgn_delay (`int`): Wait time between each poll to verify if traffic
                                      is resumed in seconds. Default: 10
                   timeout_recovery:
                       Buffer recovery timeout make sure devices are recovered at the
                       end of the trigger execution. Used when previous timeouts have
                       been exhausted.
                       max_time (`int`): Maximum wait time for the last step of the
                                         trigger in seconds. Default: 180
                       interval (`int`): Wait time between iteration when looping is
                                         needed in seconds. Default: 15
                   static:
                       The keys below are dynamically learnt by default.
                       However, they can also be set to a custom value when provided in the trigger datafile.

                        nve_name: `str`

                        (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                              OR
                              interface: 'Ethernet1/1/1' (Specific value)
           Steps:
               1. Learn Vxlan Ops configured on device. SKIP the trigger if there
                  is no vxlan configured on the device.
               2. Save the current device configurations using "method" specified.
               3. Add virtual rmac advertised that using Genie Interface Conf.
               4. Verify the newly Virtual rmac advertised under Vxlan is reflected in
                  device configuration.
               5. Restore the device configuration to the original configuration saved
                  in step 2.
               6. Learn Vxlan Ops again and verify it is the same as the Ops in step 1.
                   """
    mapping = Mapping(requirements={
        'ops.vxlan.vxlan.Vxlan': {
            'requirements': [['nve', '(?P<nve_name>.*)', 'if_state', 'up'],
                             ['nve', '(?P<nve_name>.*)', 'adv_vmac', False]],
            'kwargs': {
                'attributes': [
                    'nve[(.*)][adv_vmac]', 'nve[(.*)][if_state]',
                    'nve[(.*)][vni]', 'bgp_l2vpn_evpn', 'l2route'
                ]
            },
            'all_keys':
            True,
            'exclude':
            vxlan_exclude + multisite_exclude + l2route_exclude
        }
    },
                      config_info={
                          'conf.interface.Interface': {
                              'requirements': [['nve_adv_virtual_rmac', True]],
                              'verify_conf': False,
                              'kwargs': {
                                  'mandatory': {
                                      'name': '(?P<nve_name>.*)',
                                      'attach': False
                                  }
                              }
                          }
                      },
                      verify_ops={
                          'ops.vxlan.vxlan.Vxlan': {
                              'requirements':
                              [['nve', '(?P<nve_name>.*)', 'if_state', 'up'],
                               ['nve', '(?P<nve_name>.*)', 'adv_vmac', True]],
                              'kwargs': {
                                  'attributes': [
                                      'nve[(.*)][adv_vmac]',
                                      'nve[(.*)][if_state]', 'nve[(.*)][vni]',
                                      'bgp_l2vpn_evpn', 'l2route'
                                  ]
                              },
                              'exclude':
                              vxlan_exclude + ['bgp_l2vpn_evpn', 'l2route']
                          }
                      },
                      num_values={'nve_name': 1})
Example #11
0
class TriggerAddRemoveNveMultisiteBgwInterface(TriggerAddRemove):
    """Add multisite bgw interface under vxlan and then restore the
       configuration by reapplying the whole running configuration"""

    __description__ = """Add Add multisite bgw interface under Vxlan then restore the
                          configuration by reapplying the whole running configuration

              trigger_datafile:
                  Mandatory Arguments:
                      timeout:
                          max_time (`int`): Maximum wait time for the trigger in seconds.
                                            Default: 180
                          interval (`int`): Wait time between iteration when looping is
                                            needed in seconds. Default: 15
                          method (`str`): Method to recover the device configuration.
                                          Supported methods:
                                              'checkpoint': Rollback the configuration
                                                            using checkpoint (nxos),
                                                            archive file (iosxe),
                                                            load the saved running-config
                                                            file on disk (iosxr)
                  Optional Arguments:
                      tgn_timeout (`int`): Maximum wait time for all traffic streams to be
                                           restored to the reference rate in seconds.
                                           Default: 60
                      tgn_delay (`int`): Wait time between each poll to verify if traffic
                                         is resumed in seconds. Default: 10
                      timeout_recovery:
                          Buffer recovery timeout make sure devices are recovered at the
                          end of the trigger execution. Used when previous timeouts have
                          been exhausted.
                          max_time (`int`): Maximum wait time for the last step of the
                                            trigger in seconds. Default: 180
                          interval (`int`): Wait time between iteration when looping is
                                            needed in seconds. Default: 15
                      static:
                          The keys below are dynamically learnt by default.
                          However, they can also be set to a custom value when provided in the trigger datafile.

                          nve_name: `str`
                          source_if: `str`

                          (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                                OR
                                interface: 'Ethernet1/1/1' (Specific value)

              Steps:
                  1. Learn Vxlan Ops configured on device. SKIP the trigger if there
                     is no Vxlan configured on the device.
                  2. Save the current device configurations using "method" specified.
                  3. Add multisite bgw interface that using Genie Interface Conf.
                  4. Verify the newly multisite bgw interface under Vxlan is reflected in
                     device configuration.
                  5. Restore the device configuration to the original configuration saved
                     in step 2.
                  6. Learn Vxlan Ops again and verify it is the same as the Ops in step 1.
              """

    # configuration steps callable
    # adding new value for multisite bgw interface
    def configure_multisite_bgw_interface(self, conf_obj, unconfig, **kwargs):
        ret = ""
        for key in self.keys:
            if key['source_if'] != key['intf_name']:
                ret = key['intf_name']

        self.keys[0]['multisite_bgw_intf'] = ret
        conf_obj.nve_multisite_bgw_intf = ret
        if not unconfig:
            conf_obj.build_config()
        else:
            conf_obj.build_unconfig(apply=True,
                                    attributes={'nve_multisite_bgw_intf': ret})

        @aetest.test
        def verify_configuration(self, uut, abstract, steps):
            # modify self.keys to modify the multisite bgw interface value
            for item in self.mapping.keys:
                try:
                    ret = item['multisite_bgw_intf']
                    req = ['nve', '(?P<nve_name>.*)', 'multisite_bgw_if']
                    req.insert(len(req), ret)
                    self.mapping._verify_ops_dict['ops.vxlan.vxlan.Vxlan'][
                        'requirements'].append(req)
                    log.info("\n\nVerifying the following requirements: {req}".
                             format(req=req))
                except Exception as e:
                    self.failed('Failed to verify the '
                                'added feature',
                                from_exception=e)

            super().verify_configuration(uut, abstract, steps)


    mapping = Mapping(requirements={'ops.vxlan.vxlan.Vxlan':{
                                            'requirements': [[['nve', '(?P<nve_name>.*)', 'source_if', '(?P<source_if>.*)']],
                                                             [['nve', '(?P<nve_name>.*)', NotExists('multisite_bgw_if')]]],
                                            'all_keys': True,
                                            'kwargs': {'attributes': ['nve']},
                                            'exclude': vxlan_exclude},
                                    'ops.interface.interface.Interface':{
                                            'requirements': [['info', '(?P<intf_name>loopback.*)', 'oper_status', 'up']],
                                            'kwargs': {'attributes': ['info']},
                                            'exclude': interface_exclude}},
                        config_info={'conf.interface.Interface': {
                                            'requirements': [[partial(configure_multisite_bgw_interface,\
                                                                      nve_multisite_bgw_intf='(?P<source_if>.*)')]],
                                            'verify_conf': False,
                                            'kwargs': {'mandatory': {'name': '(?P<nve_name>.*)', 'attach': False}}}},
                        verify_ops={'ops.vxlan.vxlan.Vxlan': {
                                            'requirements': [],
                                            'kwargs': {'attributes': ['nve']},
                                            'exclude': vxlan_exclude}},
                        num_values={'nve_name':'all', 'source_if': 'all', 'intf_name':'all'})
Example #12
0
class TriggerModifyPimNeighborFilter(TriggerModify):
    """Modify dynamically learned PIM interface(s)'s neighbor-filter then restore the
      configuration by reapplying the whole running configuration."""

    __description__ = """Modify dynamically learned PIM interface(s)'s neighbor-filter
      then restore the configuration by reapplying the whole running configuration.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                vrf: `str`
                address_family: `str`
                interface: `str`
                neighbor_filter: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                      OR
                      interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn Pim Ops object and store the PIM interface(s)'s neighbor-filter
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Modify the learned PIM interface(s)'s neighbor-filter from step 1 
           with Pim Conf object
        4. Verify the PIM interface(s)'s neighbor-filter from step 3 is
           reflected in device configuration
        5. Recover the device configurations to the one in step 2
        6. Learn Pim Ops again and verify it is the same as the Ops in step 1

    """
    MODIFY_NAME = 'modified_pim_neighbor_policy'

    # Mapping of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={
                          'ops.pim.pim.Pim':{
                                'requirements':[\
                                    ['info', 'vrf', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<interface>.*)', 'address_family', '(?P<address_family>.*)',
                                     'neighbor_filter', '(?P<neighbor_filter>.*)'],
                                    ['info', 'vrf', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<interface>.*)', 'address_family', '(?P<address_family>.*)',
                                     'oper_status', 'up']],
                                'kwargs':{'attributes': [
                                    'info[vrf][(.*)][interfaces][(.*)][address_family][(.*)][oper_status]',
                                    'info[vrf][(.*)][interfaces][(.*)][address_family][(.*)][neighbor_filter]']},
                                'exclude': pim_exclude}},
                      config_info={'conf.pim.Pim':{
                                       'requirements':[
                                         ['device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                                          'address_family_attr', '(?P<address_family>.*)', 'interface_attr',
                                          '(?P<interface>.*)', 'neighbor_filter', MODIFY_NAME]],
                                       'verify_conf':False,
                                       'kwargs':{}}},
                      verify_ops={
                          'ops.pim.pim.Pim':{
                                'requirements':[\
                                    ['info', 'vrf', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<interface>.*)', 'address_family', '(?P<address_family>.*)',
                                     'neighbor_filter', MODIFY_NAME],
                                    ['info', 'vrf', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<interface>.*)', 'address_family', '(?P<address_family>.*)',
                                     'oper_status', 'up']],
                                'kwargs':{'attributes': [
                                    'info[vrf][(.*)][interfaces][(.*)][address_family][(.*)][oper_status]',
                                    'info[vrf][(.*)][interfaces][(.*)][address_family][(.*)][neighbor_filter]']},
                                'exclude': pim_exclude}},
                      num_values={'vrf': 1, 'address_family': 1, 'interface': 1})
Example #13
0
class TriggerUnconfigConfigVlanVnsegment(TriggerUnconfigConfig):
    """Unconfigure and reapply the whole configurations of dynamically learned vlan(s)."""

    __description__ = """Unconfigure and reapply the whole configurations of dynamically learned vlan(s).

        trigger_datafile:
            Mandatory:
                timeout:
                    max_time (`int`): Maximum wait time for the trigger,
                                    in second. Default: 180
                    interval (`int`): Wait time between iteration when looping is needed,
                                    in second. Default: 15
                    method (`str`): Method to recover the device configuration,
                                  Support methods:
                                    'checkpoint': Rollback the configuration by
                                                  checkpoint (nxos),
                                                  archive file (iosxe),
                                                  load the saved running-config file on disk (iosxr)
            Optional:
                tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                     restored to the reference rate,
                                     in second. Default: 60
                tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                                   in second. Default: 10
                timeout_recovery:
                    Buffer recovery timeout when the previous timeout has been exhausted,
                    to make sure the devices are recovered before ending the trigger

                    max_time (`int`): Maximum wait time for the last step of the trigger,
                                    in second. Default: 180
                    interval (`int`): Wait time between iteration when looping is needed,
                                    in second. Default: 15
                static:
                    The keys below are dynamically learnt by default.
                    However, they can also be set to a custom value when provided in the trigger datafile.

                    vlan: `str`
                    vn_segment_id: `int`
                    (e.g) interface: '(?P<interface>Ethernet1*)' (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<vlan>.*)', 'vn_segment_id',
                '(?P<vn_segment_id>.*)'
            ]],
            '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<vlan>.*)', 'vn_segment_id',
                                  '(?P<vn_segment_id>.*)'
                              ]],
                              'verify_conf':
                              False,
                              'kwargs': {}
                          }
                      },
                      verify_ops={
                          'ops.vlan.vlan.Vlan': {
                              'requirements':
                              [['info', 'vlans',
                                NotExists('(?P<vlan>.*)')]],
                              'kwargs': {
                                  'attributes':
                                  ['info[vlans][(.*)][vn_segment_id]']
                              },
                              'exclude':
                              vlan_exclude
                          }
                      },
                      num_values={'vlan': 1})
Example #14
0
class TriggerUnconfigConfigEthernetInterfaceSub(TriggerUnconfigConfig):
    """Unconfigure and reapply the whole configurations of dynamically learned Ethernet SubInterface(s)."""

    __description__ = """Unconfigure and reapply the whole configurations of dynamically learned Ethernet SubInterface(s).

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
           static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                interface: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                      OR
                      interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn Interface Ops object and store the "up" Ethernet SubInterface(s)
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Unconfigure the learned Ethernet SubInterface(s) from step 1 
           with Interface Conf object
        4. Verify the learned Ethernet SubInterface(s) are no longer existed
        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<interface>(GigabitEthernet|gigabitEthernet|Ethernet|ethernet)[0-9\/]+\.[0-9]+)',
                'enabled', True
            ],
             [
                 'info',
                 '(?P<interface>(GigabitEthernet|gigabitEthernet|Ethernet|ethernet)[0-9\/]+\.[0-9]+)',
                 'oper_status', 'up'
             ]],
            'exclude':
            interface_exclude
        }
    },
                      config_info={
                          'conf.interface.Interface': {
                              'requirements': [],
                              'verify_conf': False,
                              'kwargs': {
                                  'mandatory': {
                                      'name': '(?P<interface>.*)',
                                      'attach': False
                                  }
                              }
                          }
                      },
                      verify_ops={
                          'ops.interface.interface.Interface': {
                              'requirements':
                              [['info', NotExists('(?P<interface>.*)')]],
                              'exclude':
                              interface_exclude + ['(Vlan.*)']
                          }
                      },
                      num_values={'interface': 1})
Example #15
0
class TriggerShutNoShutDot1xInterface(TriggerShutNoShut):
    """Shut and unshut the dynamically learned Dot1x Ethernet interface(s)."""

    __description__ = """Shut and unshut the dynamically learned Dot1x Ethernet interface(s).

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                interface: `str`
                vlan: `str`
                client: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (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, then check if the status of dot1x is 'auth',
           and the peer mac-address in UUT's table is 'static', if not, SKIP the trigger
           And Learn Dot1x Ops object and store the dot1x interface whcih are from the
           interface ops.
        2. Shut the learned Dot1x Ethernet interface(s) from step 1 with Interface Conf object
        3. Verify the state of learned Dot1x Ethernet interface(s) from step 2 is "down"
        4. Unshut the Dot1x Ethernet interface(s) with Interface Conf object
        5. Learn Interface 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.interface.interface.Interface': {
                'requirements':
                [[
                    'info', '(?P<interface>\w+Ethernet[\d\/]+$)', 'enabled',
                    True
                ], ['info', '(?P<interface>.*)', 'switchport_enable', True],
                 [
                     'info', '(?P<interface>.*)', 'switchport_mode',
                     'static access'
                 ], ['info', '(?P<interface>.*)', 'oper_status', 'up']],
                'all_keys':
                True,
                'kwargs': {
                    'attributes': [
                        'info[(.*)][switchport_mode]',
                        'info[(.*)][oper_status]', 'info[(.*)][enabled]',
                        'info[(.*)][switchport_enable]',
                        'info[(.*)][operational_mode]'
                    ]
                },
                'exclude':
                interface_exclude
            },
            'ops.fdb.fdb.Fdb': {
                'requirements': [
                    [
                        'info', 'mac_table', 'vlans', '(?P<vlan>.*)',
                        'mac_addresses', '(?P<client>.*)', 'interfaces',
                        '(?P<interface>.*)', 'entry_type', 'static'
                    ]
                ],
                'all_keys':
                True,
                'kwargs': {
                    'attributes': ['info[mac_table][vlans][(.*)]']
                },
                'exclude':
                fdb_exclude + ['mac_addresses']
            },
            'ops.dot1x.dot1x.Dot1x': {
                'requirements': [
                    [
                        'info', 'interfaces', '(?P<interface>.*)', 'clients',
                        '(?P<client>.*)', 'status', 'authorized'
                    ]
                ],
                'kwargs': {
                    'attributes':
                    ['info[interfaces][(.*)][clients][(.*)][status]']
                },
                'all_keys':
                True,
                'exclude':
                dot1x_exclude
            }
        },
        config_info={
            'conf.interface.Interface': {
                'requirements': [['enabled', False]],
                'verify_conf': False,
                'kwargs': {
                    'mandatory': {
                        'name': '(?P<interface>.*)',
                        'attach': False
                    }
                }
            }
        },
        verify_ops={
            'ops.interface.interface.Interface': {
                'requirements':
                [['info', '(?P<interface>.*)', 'enabled', False],
                 ['info', '(?P<interface>.*)', 'oper_status', 'down'],
                 ['info', '(?P<interface>.*)', 'switchport_enable', False]],
                'kwargs': {
                    'attributes':
                    [
                        'info[(.*)][switchport_mode]',
                        'info[(.*)][oper_status]', 'info[(.*)][enabled]',
                        'info[(.*)][switchport_enable]',
                        'info[(.*)][operational_mode]'
                    ]
                },
                'exclude':
                interface_exclude
            },
            'ops.fdb.fdb.Fdb': {
                'requirements': [[
                    'info', 'mac_table', 'vlans', '(?P<vlan>.*)',
                    'mac_addresses',
                    NotExists('(?P<client>.*)')
                ]],
                'kwargs': {
                    'attributes':
                    ['info[mac_table][vlans][(.*)]']
                },
                'exclude':
                fdb_exclude +
                ['mac_addresses']
            },
            'ops.dot1x.dot1x.Dot1x': {
                'requirements':
                [['info', 'interfaces',
                  NotExists('(?P<interface>.*)')]],
                'kwargs': {
                    'attributes':
                    ['info[interfaces][(.*)][clients][(.*)][status]']
                },
                'all_keys':
                True,
                'exclude':
                dot1x_exclude + ['attributes']
            }
        },
        num_values={'interface': 'all'})
Example #16
0
class TriggerAddRemoveIgmpEnable(TriggerAddRemove):
    """Apply the Igmp interface enable, add remove added Igmp interface enable"""

    __description__ = """Apply the Igmp interface enable, add remove added Igmp interface enable.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn Igmp Ops/Conf object and store the Igmp interface enable, learn Interface ops to 
           get interface with ip address and not same to the existing igmp interface.
        2. Save the current device configurations through "method" which user uses
        3. Add the configuration of interface as igmp originator-id with Igmp Conf object
        4. Verify the igmp interface enable from step 3 has configured
        5. Remove the igmp interface enable configurations.
        6. Recover the device configurations to the one in step 2
        7. Learn Igmp Ops again and verify it is the same as the Ops in step 1
    """

    @aetest.setup
    def verify_prerequisite(self, uut, abstract, steps, timeout):
        # learn existing igmp interfaces
        super().verify_prerequisite(uut, abstract, steps, timeout)
        igmp_keys = self.mapping.keys

        # learn interafce ops to get ipv4 up interfaces
        self.mapping.requirements = {}
        self.mapping.requirements['ops.interface.interface.Interface'] = \
            {'requirements':[['info', '(?P<igmp_intf>^(?!mgmt).*)', 'ipv4',
                              '(?P<ip>.*)', 'ip', '(?P<address>.*)'],
                             ['info', '(?P<igmp_intf>.*)', 'vrf',
                              '(?P<add_igmp_intf_vrf>.*)']],
            'all_keys': True,
            'kwargs':{'attributes': [
                'info[(.*)][ipv4][(.*)][ip]',
                'info[(.*)][vrf]']},
            'exclude': interface_exclude}
        super().verify_prerequisite(uut, abstract, steps, timeout)
        intf_keys = self.mapping.keys

        # find interface
        with steps.start("Extracting ipv4 interfaces "
                         "which are not igmp interfaces") as step:

            add_keys = {}
            for item in intf_keys:
                if all(item['igmp_intf'] not in \
                    i['igmp_intf'] for i in igmp_keys):
                    # attach the add value to mapping keys
                    add_keys.update({
                        'add_igmp_intf':
                        item['igmp_intf'],
                        'add_igmp_intf_vrf':
                        item['add_igmp_intf_vrf']
                    })
                    break

            if not add_keys:
                step.skipped('Could not find up ipv4 interface which is '
                             'not existed igmp interface')
                self.skipped(
                    'Could not find up ipv4 interface which is '
                    'not existed igmp interface',
                    goto=['next_tc'])

        self.mapping.keys = [add_keys]

    # Mapping of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={'ops.igmp.igmp.Igmp':{
                                          'requirements':[\
                                              ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                               '(?P<igmp_intf>.*)']],
                                          'kwargs':{'attributes': [
                                              'info[vrfs][(.*)][interfaces]']},
                                          'exclude': igmp_exclude}},
                      config_info={'conf.igmp.Igmp':{
                                       'requirements':[
                                         ['device_attr', '{uut}', 'vrf_attr', '(?P<add_igmp_intf_vrf>.*)',
                                          'interface_attr', '(?P<add_igmp_intf>.*)', 'enable', True]],
                                       'verify_conf':False,
                                       'kwargs':{}}},
                      verify_ops={'ops.igmp.igmp.Igmp':{
                                          'requirements':[\
                                              ['info', 'vrfs', '(?P<add_igmp_intf_vrf>.*)', 'interfaces',
                                               '(?P<add_igmp_intf>.*)', 'enable', True]],
                                          'kwargs':{'attributes': ['info[vrfs][(.*)][interfaces]']},
                                          'exclude': igmp_exclude}},
                      num_values={'vrf': 'all', 'igmp_intf': 'all'})
Example #17
0
class TriggerModifyVlanVnsegment(TriggerModify):
    """Modify and revert the vnsegemnt for dynamically learned vlan(s)."""

    __description__ = """Modify and revert the vnsegemnt for dynamically learned vlan(s).

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                vlan: `str`
                vn_segment: `int`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                      OR
                      interface: 'Ethernet1/1/1' (Specific value)

    steps:
        1. Learn Vlan Ops object and store the vlan which is active and has vnsegment.
            SKIP the trigger if there is no VLAN(s) found
        2. Save the current device configurations through "method" which user uses
        3. Modify the vnsegment of the learned VLAN from step 1 with VLAN Conf object
        4. Verify the vnsegment of the learned VLAN  from step 3
           changes to the modified value in step 3,
        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

    """

    VN_SEGMENT = 1111

    @aetest.test
    def modify_configuration(self, uut, abstract, steps):
        '''Modify configuration on the uut device

           Args:
               uut (`obj`): Device object.
               abstract (`obj`): Abstract object.
               steps (`step obj`): aetest step object

           Returns:
               None

           Raises:
               pyATS Results
        '''
        # Flap vlan for config change to take effect
        cmd = "vlan (?P<vlan>.*)\n" \
              " no vn-segment\n" \
              " vn-segment {}\n".format(self.VN_SEGMENT)
        x = re.findall(r'\S+|\n', cmd)
        req = self.mapping._path_population([x], uut)
        req_str = []
        for item in req[0]:
            req_str.append(str(item))

        cmd = ' '.join(req_str)
        try:
            uut.configure(cmd)
        except Exception as e:
            self.failed('Failed to modify the configuration', from_exception=e)

    # 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<vlan>.*)', 'state', 'active'],
                                                          ['info', 'vlans', '(?P<vlan>.*)', 'vn_segment_id', '(?P<vn_segment>^(?!1111).*)$']],
                                          'kwargs':{'attributes':['info[vlans][(.*)][vn_segment_id]',
                                                                  'info[vlans][(.*)][state]']},
                                          'all_keys':True,
                                          'exclude': vlan_exclude}},
                      config_info={'conf.vlan.Vlan':{
                                     'requirements':[['device_attr', '{uut}', 'vlan_attr', '(?P<vlan>.*)',\
                                                      'vn_segment_id', VN_SEGMENT]],
                                     'verify_conf':False,
                                     'kwargs':{}}},
                      verify_ops={'ops.vlan.vlan.Vlan':{
                                    'requirements':[['info','vlans','(?P<vlan>.*)','state','active'],
                                                    ['info','vlans','(?P<vlan>.*)','vn_segment_id',VN_SEGMENT]],
                                    'kwargs':{'attributes':['info[vlans][(.*)][vn_segment_id]',
                                                            'info[vlans][(.*)][state]']},
                                    'exclude': vlan_exclude}},
                      num_values={'vlan': 1})
Example #18
0
class TriggerAddRemoveIgmpStaticGroup(TriggerAddRemove):
    """Apply the Igmp interface static-group, and remove added Igmp interface static-group"""

    __description__ = """Apply the Igmp interface static-group,
    and remove added Igmp interface static-group.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn Igmp Ops object and store the Igmp interface(s) which does not have added static-group.
        2. Save the current device configurations through "method" which user uses
        3. Add the configuration of igmp interface static-group with Igmp Conf object
        4. Verify the igmp interface static-group from step 3 has configured
        5. Remove the igmp interface static-group configurations.
        6. Recover the device configurations to the one in step 2
        7. Learn Igmp Ops again and verify it is the same as the Ops in step 1

    """
    ADD_STATIC_GROUP = '234.1.1.2 *'

    @aetest.setup
    def verify_prerequisite(self,
                            uut,
                            abstract,
                            steps,
                            timeout,
                            add_igmp_group=None):

        self.timeout = timeout

        try:
            self.pre_snap = self.mapping.learn_ops(device=uut,
                                                   abstract=abstract,
                                                   steps=steps,
                                                   timeout=timeout)
        except Exception as e:
            self.errored("Section failed due to: '{e}'".format(e=e))

        # nothing in the static groups,
        # then learn if any groups to have some vrf interface value
        if any(not item for item in self.mapping.keys):
            self.mapping.requirements['ops.igmp.igmp.Igmp']['requirements'] = \
              [['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
               '(?P<igmp_intf>.*)', 'group', '(?P<group>.*)', '(?P<dummy>.*)']] # incase there is nothing learned

            try:
                self.pre_snap = self.mapping.learn_ops(device=uut,
                                                       abstract=abstract,
                                                       steps=steps,
                                                       timeout=timeout)
            except Exception as e:
                self.errored("Section failed due to: '{e}'".format(e=e))

            if any(not item for item in self.mapping.keys):
                self.skipped('Cannot learn the feature', goto=['next_tc'])

        with steps.start("Check if added group %s not in the "
                         "existing groups" % self.ADD_STATIC_GROUP) as step:

            # learn igmp ops to have existing igmp interfaces
            if any(self.ADD_STATIC_GROUP in \
                item.get('static_group', '') for item in self.mapping.keys):
                if add_igmp_group:
                    self.ADD_STATIC_GROUP = add_igmp_group
                else:
                    self.skipped('Could not find static_group does not '
                                 'include the added group %s' %
                                 self.ADD_STATIC_GROUP,
                                 goto=['next_tc'])

            # attach the add value to mapping keys
            [
                item.update({
                    'add_igmp_group': self.ADD_STATIC_GROUP.split()[0],
                    'add_igmp_source': self.ADD_STATIC_GROUP.split()[1],
                    'add_igmp_group_key': self.ADD_STATIC_GROUP
                }) for item in self.mapping.keys
            ]

            step.passed('Will add group %s' % self.ADD_STATIC_GROUP)

    # Mapping of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={
                          'ops.igmp.igmp.Igmp':{
                                'requirements':[\
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<igmp_intf>.*)', 'static_group', '(?P<static_group>.*)',
                                     'group', '(?P<group>.*)']],
                                'all_keys': True,
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)][interfaces][(.*)][join_group][(.*)]',
                                    'info[vrfs][(.*)][interfaces][(.*)][static_group][(.*)]',
                                    'info[vrfs][(.*)][interfaces][(.*)][group][(.*)]']},
                                'exclude': igmp_exclude}},
                      config_info={'conf.igmp.Igmp':{
                                       'requirements':[
                                         [partial(configure_add_attributes,  # callable configuration
                                            add_obj=IgmpGroup,
                                            base=[['device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                                                  'interface_attr', '(?P<igmp_intf>.*)']],
                                            add_attribute=[['static_group', '(?P<add_igmp_group>.*)'],
                                                           ['static_group_source_addr', '(?P<add_igmp_source>.*)'],],
                                            add_method='add_groups',
                                        )]],
                                       'verify_conf':False,
                                       'kwargs':{}}},
                      verify_ops={
                          'ops.igmp.igmp.Igmp':{
                                'requirements':[\
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<igmp_intf>.*)', 'static_group', '(?P<add_igmp_group_key>.*)',
                                     'group', '(?P<add_igmp_group>.*)'],
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<igmp_intf>.*)', 'static_group', '(?P<add_igmp_group_key>.*)',
                                     'source', '(?P<add_igmp_source>.*)'],
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<igmp_intf>.*)', 'group', '(?P<add_igmp_group>.*)', 'last_reporter', '([\w\.]+)']],
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)][interfaces][(.*)][join_group][(.*)]',
                                    'info[vrfs][(.*)][interfaces][(.*)][static_group][(.*)]',
                                    'info[vrfs][(.*)][interfaces][(.*)][group][(.*)]']},
                                'exclude': igmp_exclude}},
                      num_values={'vrf': 1, 'igmp_intf': 1, 'static_group': 1, 'group': 1, 'source': 1})
Example #19
0
class TriggerDisableEnablePim(TriggerDisableEnable):
    """Disable and enable feature Pim."""

    __description__ = """Disable and enable feature Pim.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn Mcast Ops object and store the Mcast vrf(s) with ipv4 feature enabled
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Disable pim feature with command "no feature pim"
           via Mcast Conf object
        4. Verify the state of feature pim is "disabled"
        5. Recover the device configurations to the one in step 2
        6. Verify the state of feature pim is "enabled" and 
           learn Mcast Ops again and verify it is the same as the Ops in step 1

    """

    mapping = Mapping(requirements={'ops.mcast.mcast.Mcast':{
                                        'requirements':[\
                                            ['info', 'vrf', '(?P<vrf>.*)', 'address_family', 'ipv4', 'enable', True]],
                                        'kwargs':{'attributes':['info']},
                                        'exclude': mcast_exclude}},
                      config_info={'conf.mcast.Mcast':{
                                    'requirements':[['device_attr', '{uut}', 'vrf_attr', None, 'address_family_attr', 'ipv4', 'enabled', True]],
                                    'verify_conf':False}},
                      verify_ops={'ops.mcast.mcsat.Mcast':{
                                    'requirements':[\
                                        ['info', 'vrf', '(?P<vrf>.*)', 'address_family', 'ipv4', 'enable', False]],
                                    'kwargs':{'attributes':['info']},
                                    'exclude': mcast_exclude}})
    # feature name
    # used for creating checkpoint name and log information
    feature_name = 'pim'
Example #20
0
class TriggerModifyLldpTimer(TriggerModify):
    """Modify and revert the LLDP timer"""

    __description__ = """Modify and revert the LLDP timer.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn LLDP Ops object to check if LLDP enabled on peer routers,
           otherwise SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Modify the LLDP timer to user defined value with LLDP Conf object on peer routers
        4. Verify the LLDP timer from step 3
           changes to the modified value in step 3,
           verify LLDP neighbors are not changed
        5. Recover the device configurations to the one in step 2
        6. Learn LLDP Ops again and verify it is the same as the Ops in step 1

    """

    mapping = Mapping(requirements={'ops.lldp.lldp.Lldp': {
                                       'requirements':[\
                                            ['info', 'enabled', True],
                                            ['info', 'interfaces', '(?P<intf>.*)',
                                             'neighbors', '(?P<peer>.*)', 'neighbor_id', '(?P<neighbor>.*)']
                                        ],
                                       'all_keys': True,
                                       'kwargs':{'attributes':['info[enabled]',
                                                               'info[interfaces][(.*)][neighbors][(.*)]']},
                                       'exclude': lldp_exclude}},
                      config_info={'conf.lldp.Lldp':{
                                     'requirements':[['device_attr', '{uut}', 'hello_timer', 5]],
                                     'verify_conf':False,
                                     'kwargs':{}}},
                      verify_ops={'ops.lldp.lldp.Lldp':{
                                    'requirements':[['info', 'hello_timer', 5],],
                                    'kwargs':{'attributes':['info[hello_timer]',
                                                            'info[enabled]',
                                                            'info[interfaces][(.*)][neighbors][(.*)]']},
                                    'exclude': lldp_exclude}},
                      num_values={'intf': 'all', 'neighbor': 1, 'peer': 'all'})
Example #21
0
class TriggerSwitchover(CommonSwitchover):
    """Do switchover on device."""

    __description__ = """Do switchover on device.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            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 "active" RP and "standby" RP
           if has any, otherwise, SKIP the trigger
        2. Do switchover by command "redundancy force-switchover"
        3. Learn Platform Ops again and verify the roles of 
           "active" RP and "standby" RP are swapped,
           and verify left 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

    """

    @aetest.setup
    def verify_prerequisite(self, uut, abstract, steps, timeout):
        '''Learn Ops object and verify the requirements.

           If the requirements are not satisfied, then skip to the next
           testcase.

           Args:
               uut (`obj`): Device object.
               abstract (`obj`): Abstract object.
               steps (`step obj`): aetest step object
               timeout (`timeout obj`): Timeout Object

           Returns:
               None

           Raises:
               pyATS Results
        '''
        self.timeout = timeout
        try:
            self.pre_snap = self.mapping.learn_ops(device=uut,
                                                   abstract=abstract,
                                                   steps=steps,
                                                   timeout=self.timeout)
        except Exception as e:
            self.skipped('Cannot learn the feature',
                         from_exception=e,
                         goto=['next_tc'])

        for stp in steps.details:
            if stp.result.name == 'skipped':
                self.skipped('Cannot learn the feature', goto=['next_tc'])

        self.print_local_verifications()

        # get and store the member priority list
        try:
            out = ShowPlatform(device=uut).parse()
            # inital priority storage
            priority_dict = {}
            priority_list = []
            if 'slot' in out:
                for slot in out['slot']:
                    for rp in out['slot'][slot]['rp']:
                        if out['slot'][slot]['rp'][rp]['role'] == 'Member':
                            priority_dict[slot] = \
                                out['slot'][slot]['rp'][rp]['priority']
                            priority_list.append(
                                out['slot'][slot]['rp'][rp]['priority'])

                if len(list(set(priority_list))) != 1:
                    # sorted the slot priority
                    priority_list = sorted(priority_dict.items(),
                                           key=lambda x: x[1])

                    # update the verify_ops requirements
                    for ops, requirements in self.mapping._verify_ops_dict.items(
                    ):
                        if 'platform' in ops:
                            self.mapping._verify_ops_dict[ops][
                                'requirements'].append([
                                    'slot', 'rp',
                                    '{}'.format(priority_list[-1][0]),
                                    'swstack_role', 'Standby'
                                ])
                else:
                    # update the verify_ops requirements
                    for ops, requirements in self.mapping._verify_ops_dict.items(
                    ):
                        if 'platform' in ops:
                            self.mapping._verify_ops_dict[ops][
                                'requirements'].append([
                                    'slot', 'rp', '(?P<members>.*)',
                                    'swstack_role', '(Standby|Member)'
                                ])
        except Exception as e:
            log.warn('Cannot get the member priority. \n{}'.format(str(e)))

    # 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<active_rp>.*)',
                                              'swstack_role', 'Active'],
                                            ['slot', 'rp', '(?P<active_rp>.*)',
                                              'state', 'Ready']],
                                            [['slot', 'rp', '(?P<standby_rp>.*)',
                                              'swstack_role', 'Standby'],
                                            ['slot', 'rp', '(?P<standby_rp>.*)',
                                              'state', 'Ready']],
                                            [['slot', 'rp', '(?P<members>.*)',
                                              'swstack_role', 'Member'],
                                            ['slot', 'rp', '(?P<members>.*)',
                                              'state', 'Ready']],
                                            [['redundancy_communication', True]],
                                          ],
                                        'all_keys': True,
                                        'exclude': platform_exclude}},
                      verify_ops={'ops.platform.platform.Platform':{
                                      'requirements': [\
                                          ['slot', 'rp', '(?P<active_rp>.*)',
                                           'swstack_role', 'Member'],
                                          ['slot', 'rp', '(?P<standby_rp>.*)',
                                           'swstack_role', 'Active']],
                                    'exclude': platform_exclude}},
                      num_values={'active_rp':1, 'standby_rp':1, 'members': 'all'})
Example #22
0
class TriggerAddRemovePimNeighborFilter(TriggerAddRemove):
    """Apply the Pim interface(s)'s neighbor-filter, add remove added Pim interface(s)'s neighbor-filter"""

    __description__ = """Apply the Pim interface(s)'s neighbor-filter,
    add remove added Pim interface(s)'s neighbor-filter.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn Pim Ops/Conf object and store the Pim interface(s)'s neighbor-filter.
        2. Save the current device configurations through "method" which user uses
        3. Add the configuration of Pim interface(s)'s neighbor-filter with Pim Conf object
        4. Verify the Pim interface(s)'s neighbor-filter from step 3 has configured
        5. Remove the Pim interface(s)'s neighbor-filter configurations.
        6. Recover the device configurations to the one in step 2
        7. Learn Pim Ops again and verify it is the same as the Ops in step 1

    """
    ADD_NAME = 'added_pim_neighbor_policy'

    # Mapping of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={
                          'ops.pim.pim.Pim':{
                                'requirements':[\
                                    ['info', 'vrf', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<pim_intf>.*)', 'address_family', '(?P<af>.*)',
                                     NotExists('neighbor_filter')],
                                    ['info', 'vrf', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<pim_intf>.*)', 'address_family', '(?P<af>.*)',
                                     'oper_status', 'up']],
                                'kwargs':{'attributes': [
                                    'info[vrf][(.*)][interfaces][(.*)][address_family][(.*)][oper_status]',
                                    'info[vrf][(.*)][interfaces][(.*)][address_family][(.*)][neighbor_filter]']},
                                'exclude': pim_exclude}},
                      config_info={'conf.pim.Pim':{
                                       'requirements':[
                                         ['device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                                          'address_family_attr', '(?P<af>.*)', 'interface_attr',
                                          '(?P<pim_intf>.*)', 'neighbor_filter', ADD_NAME]],
                                       'verify_conf':False,
                                       'kwargs':{}}},
                      verify_ops={
                          'ops.pim.pim.Pim':{
                                'requirements':[\
                                    ['info', 'vrf', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<pim_intf>.*)', 'address_family', '(?P<af>.*)',
                                     'neighbor_filter', ADD_NAME],
                                    ['info', 'vrf', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<pim_intf>.*)', 'address_family', '(?P<af>.*)',
                                     'oper_status', 'up']],
                                'kwargs':{'attributes': [
                                    'info[vrf][(.*)][interfaces][(.*)][address_family][(.*)][oper_status]',
                                    'info[vrf][(.*)][interfaces][(.*)][address_family][(.*)][neighbor_filter]']},
                                'exclude': pim_exclude}},
                      num_values={'vrf': 1, 'af': 1, 'pim_intf': 1})
Example #23
0
class TriggerReloadStandbyRP(TriggerReloadWithPriority):
    """Reload standby switch on device."""

    __description__ = """Reload standby switch on device.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            lcRole (`str`): The role of LC which is 'standby'
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                standby_rp: `str`
                members: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                   OR
                   interface: 'Ethernet1/1/1' (Specific value)
    steps:
        1. Learn Platform Ops object and store the "standby" switch and "member" switch(es)
           if has any, otherwise, SKIP the trigger
        2. Do reload by command "reload slot <lc>"
        3. Learn Platform Ops again and verify role of "standby" switch changes to "member",
           verify the role of "member" switch with highest priority changes to "standby",
           and verify left 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<standby_rp>.*)',
                                              'swstack_role', 'Standby'],
                                            ['slot', 'rp', '(?P<standby_rp>.*)',
                                              'state', 'Ready']],
                                            [['slot', 'rp', '(?P<members>.*)',
                                              'swstack_role', 'Member'],
                                            ['slot', 'rp', '(?P<members>.*)',
                                              'state', 'Ready']],
                                            [['redundancy_communication', True]],
                                          ],
                                        'all_keys': True,
                                        'exclude': platform_exclude}},
                      verify_ops={'ops.platform.platform.Platform':{
                                      'requirements': [\
                                          ['slot', 'rp', '(?P<standby_rp>.*)',
                                           'swstack_role', 'Member']],
                                    'exclude': platform_exclude}},
                      num_values={'standby_rp':1, 'members': 'all'})
Example #24
0
class TriggerModifyIgmpVersion(TriggerModify):
    """Modify dynamically learned enabled Igmp interface(s) version then restore the
      configuration by reapplying the whole running configuration."""

    __description__ = """Modify dynamically learned enabled Igmp interface(s) version
    then restore the configuration by reapplying the whole running configuration.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                interface: `str`
                vrf: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                    OR
                    interface: 'Ethernet1/1/1' (Specific value)

    steps:
        1. Learn Igmp Ops object and store the Igmp interface version
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Modify the learned Igmp interface version from step 1 
           with Igmp Conf object
        4. Verify the Igmp interface version  from step 3 is reflected in device configuration
        5. Recover the device configurations to the one in step 2
        6. Learn Igmp 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.igmp.igmp.Igmp':{
                                'requirements':[\
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<interface>.*)', 'enable', True],
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<interface>.*)', 'version', '(?P<version>2)']],
                                'all_keys': True,
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)]']},
                                'exclude': igmp_exclude}},
                      config_info={'conf.igmp.Igmp':{
                                       'requirements':[
                                         ['device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                                          'interface_attr', '(?P<interface>.*)', 'version',
                                          3]],
                                       'verify_conf':False,
                                       'kwargs':{}}},
                      verify_ops={
                          'ops.igmp.igmp.Igmp':{
                                'requirements':[\
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<interface>.*)', 'version', 3]],
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)]']},
                                'exclude': igmp_exclude}},
                      num_values={'vrf': 1, 'interface': 1})
Example #25
0
class TriggerUnconfigConfigMldVersion(TriggerUnconfigConfig):
    """Unconfigure and reapply the whole configurations of dynamically
    learned enabled Mld interface(s)'s version."""

    __description__ = """Unconfigure and reapply the whole configurations
    of dynamically learned enabled Mld interface(s)'s version.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn Mld Ops object and store the enabled Mld interface(s)'s version
           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 version from step 1 
           with Mld Conf object
        4. Verify the Mld interface(s)'s version 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<vrf>.*)', 'interfaces',
                                     '(?P<mld_intf>.*)', 'enable', True],
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<mld_intf>.*)', 'version', '(?P<version>^(?!2).*)']],
                                'all_keys': True,
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)]']},
                                'exclude': mld_exclude}},
                      config_info={'conf.mld.Mld':{
                                       'requirements':[
                                         ['device_attr', '{uut}', 'vrf_attr', '(?P<vrf>.*)',
                                          'interface_attr', '(?P<mld_intf>.*)', 'version',
                                          '(?P<version>.*)']],
                                       'verify_conf':False,
                                       'kwargs':{}}},
                      verify_ops={
                          'ops.mld.mld.Mld':{
                                'requirements':[\
                                    ['info', 'vrfs', '(?P<vrf>.*)', 'interfaces',
                                     '(?P<mld_intf>.*)', 'version', 2]],
                                'missing': False,
                                'kwargs':{'attributes': [
                                    'info[vrfs][(.*)]']},
                                'exclude': mld_exclude}},
                      num_values={'vrf': 1, 'mld_intf': 1})
Example #26
0
class TriggerShutNoShutEthernetInterface(TriggerShutNoShut):
    """Shut and unshut the dynamically learned Ethernet interface(s)."""

    __description__ = """Shut and unshut the dynamically learned Ethernet interface(s).

               trigger_datafile:
                   Mandatory:
                       timeout:
                           max_time (`int`): Maximum wait time for the trigger,
                                           in second. Default: 180
                           interval (`int`): Wait time between iteration when looping is needed,
                                           in second. Default: 15
                   Optional:
                       tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                            restored to the reference rate,
                                            in second. Default: 60
                       tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                                          in second. Default: 10
                       timeout_recovery:
                           Buffer recovery timeout make sure devices are recovered at the end
                           of the trigger execution. Used when previous timeouts have been exhausted.

                           max_time (`int`): Maximum wait time for the last step of the trigger,
                                           in second. Default: 180
                           interval (`int`): Wait time between iteration when looping is needed,
                                           in second. Default: 15
                       static:
                           The keys below are dynamically learnt by default.
                           However, they can also be set to a custom value when provided in the trigger datafile.

                           interface: `str`

                          (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                                OR
                                interface: 'Ethernet1/1/1' (Specific value)
               steps:
                   1. Learn Interface Ops object and store the "up" Ethernet interface(s) and "False" port channel member,
                      if has any, otherwise, SKIP the trigger.
                   2. Shut the learned Ethernet interface(s) from step 1 with Interface Conf object
                   3. Verify the state of learned Ethernet interface(s) from step 2 is "down"
                   4. Unshut the Ethernet interface(s) with Interface Conf object
                   5. Learn Interface Ops again and verify it is the same as the Ops in step 1

               """

    def remove_related_subinterface(item, interface, **kwargs):
        """Check if interface (item) needs to remove sub-interfaces
        by checking with the given main interface (name).

           Args:
               item (`str`): Interface name to be checked if need to remove the sub-interfaces.
               interface (`str`): Interface name that needs to remove the sub-interfaces.
               **kwargs: Arbitrary keyword arguments.

           Returns:
               True: The item interface which needs sub-interfaces removal
               False: The item interface which doesn't need sub-interfaces removal
        """
        # Easiest way is to split at the dot, and see if it exists in name
        modified_item = item.split('.')[0]

        # If it remained the same, dont waste time
        if item == modified_item:
            return False

        # See if the modified_item exists in the list of name
        if modified_item in interface:
            return True
        return False

    # Mapping of Information between Ops and Conf
    # Also permit to dictate which key to verify
    mapping = Mapping(requirements={'ops.interface.interface.Interface':{
                                        'requirements':[\
                                            ['info', '(?P<interface>(\w+(e|E)thernet[\d\/]|\w+(g|G)ig[\w\/])+$)', 'oper_status', 'up'],
                                            ['info', '(?P<interface>.*)', 'port_channel', 'port_channel_member', False]],
                                        'exclude': interface_exclude,
                                        'kwargs': {'attributes': ['info[(.*)][switchport_enable]',
                                                                  'info[(.*)][enabled]',
                                                                  'info[(.*)][oper_status]',
                                                                  'info[(.*)][port_channel]']},
                                        'include_management_interface': False}},
                      config_info={'conf.interface.Interface':{
                                        'requirements':[['enabled', False]],
                                        'verify_conf':False,
                                        'kwargs':{'mandatory':{'name': '(?P<interface>.*)',
                                                               'attach': False}}}},
                      verify_ops={'ops.interface.interface.Interface':{
                                        'requirements':[\
                                            ['info', '(?P<interface>.*)', 'enabled', False],
                                            ['info', '(?P<interface>.*)', 'oper_status', 'down'],
                                            ['info', '(?P<interface>.*)', 'switchport_enable', False]],
                                        'kwargs': {'attributes': ['info[(.*)][switchport_enable]',
                                                                  'info[(.*)][enabled]',
                                                                  'info[(.*)][oper_status]',
                                                                  'info[(.*)][port_channel]']},
                                        'exclude': interface_exclude +\
                                                   [remove_related_subinterface]}},
                      num_values={'interface': 1})
Example #27
0
def get_ops_diff(new, original, exclude=None, modified_path=None, keys=None):
    '''Diff two ops object with ignoring the keys from the exclude list

       Args:
          Mandatory:
            new (`obj`) : Ops object.
            original (`obj`) : Ops object.
          Optional:
            exclude (`list`) : Keys/attributs to ignore in the diff.
            modified_path (`list`) : List of items that needs to be checked.
                                     The item is following the ops attributes path
                                     in a list.
            keys (`list`) : List of items that contains the key values for the
                            'modified_path' regexp items.

       Returns:
           None

       Raises:
           AssertionError: When diff is found
           ValueError: When required attributes are not in the ops

       Example:
           >>> ops_diff(new = <bgp_ops_obj>,
                        original = <bgp_ops_obj>,
                        exclude = ['up_time', 'keepalive', 'maker'],
                        modified_path = [['info', 'instance', '(?P<instance>.*)',
                                          'vrf', '(?P<vrf>.*)', 'neighbor', '(?P<neighbor>.*)',
                                          'remote_as', '900']],
                        keys = [{'instance': '1', 'vrf': 'default', 'neighbor': '10.4.1.1'},
                                {'instance': '1', 'vrf': 'VRF1', 'neighbor': '10.16.2.2'},])
    '''
    def _modify_ops_snapshot(original, current, path):
        # First does path exists in original, except the value
        r = R(path[:-1] + ['(.*)'])
        ret = find([original], r, filter_=False)
        if not ret:
            raise ValueError(
                "'{p}' does not exist on original snapshot "
                "as per the original trigger requirement".format(p=path))
        _modify_value(current, path[:-1], ret[0][0])

    def _modify_value(snapshot, path, value):
        for p in path[:-1]:
            try:
                snapshot = snapshot[p]
            except (TypeError):
                snapshot = getattr(snapshot, p)
        if isinstance(snapshot, dict):
            snapshot[path[-1]] = value
        else:
            setattr(snapshot, path[-1], value)

    if modified_path and keys:
        mapping = Mapping()
        for req in modified_path:

            # use mapping internal function to populate the path with learned values
            req = mapping._populate_path([req], new.device, keys=keys)
            rs = [R(requirement) for requirement in req]

            # want to print one by one
            for rs_item in rs:
                ret = find([new], rs_item, filter_=False, all_keys=True)
                if not ret:
                    # return rs_item.args
                    raise ValueError("'{req}' does not exists in "
                                     "'{o}'".format(req=rs_item.args, o=new))

            # Let's modify the ops value to be equal to the original
            # snapshot. This will allow for comparing the other keys
            for require in req:
                try:
                    _modify_ops_snapshot(original=original,
                                         current=new,
                                         path=require)
                except Exception as e:
                    return

    diff = Diff(original,
                new,
                exclude=(exclude or []) +
                ['maker', 'callables', 'device', 'diff_ignore'])
    diff.findDiff()
    if diff.diffs:
        log.error("Current ops is not equal to the initial Snapshot "
                  "taken on device {d}.\n{e}".format(e=str(diff),
                                                     d=getattr(
                                                         new, 'device',
                                                         'name')))
        raise AssertionError(
            "Current ops is not equal to the initial Snapshot "
            "taken on device {d}.\n{e}".format(e=str(diff),
                                               d=getattr(
                                                   new, 'device', 'name')))
Example #28
0
class TriggerShutNoShutIpv4SviInterface(TriggerShutNoShut):
    """Shut and unshut Learned Vlan interface(s) with ipv4 configured."""

    __description__ = """Shut and unshut Learned Vlan interface(s) with ipv4 configured.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
            static:
                The keys below are dynamically learnt by default.
                However, they can also be set to a custom value when provided in the trigger datafile.

                interface: `str`

                (e.g) interface: '(?P<interface>Ethernet1*)' (Regex supported)
                      OR
                      interface: 'Ethernet1/1/1' (Specific value)

    steps:
        1. Learn Interface Ops object and store the "up" Vlan interface(s) with ipv4 configured
           if has any, otherwise, SKIP the trigger
        2. Shut the learned Vlan interface(s) from step 1 with Interface Conf object
        3. Verify the state of learned Vlan interface(s) from step 2 is "down"
        4. Unshut the Vlan interface(s) with Interface Conf object
        5. Learn Interface 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.interface.interface.Interface': {
                'requirements':
                [['info', '(?P<interface>Vlan[0-9]+)', 'enabled', True],
                 [
                     'info', '(?P<interface>.*)', 'ipv4', '(?P<ip>.*)', 'ip',
                     '(?P<ipaddr>.*)'
                 ],
                 [
                     'info', '(?P<interface>.*)', 'port_channel',
                     'port_channel_member', False
                 ], ['info', '(?P<interface>.*)', 'oper_status', 'up']],
                'all_keys':
                True,
                'kwargs': {
                    'attributes': [
                        'info[(.*)][port_channel]', 'info[(.*)][enabled]',
                        'info[(.*)][oper_status]', 'info[(.*)][ipv4][(.*)]'
                    ]
                },
                'exclude':
                interface_exclude
            }
        },
        config_info={
            'conf.interface.Interface': {
                'requirements': [['enabled', False]],
                'verify_conf': False,
                'kwargs': {
                    'mandatory': {
                        'name': '(?P<interface>.*)',
                        'attach': False
                    }
                }
            }
        },
        verify_ops={
            'ops.interface.interface.Interface': {
                'requirements':
                [['info', '(?P<interface>.*)', 'enabled', False],
                 ['info', '(?P<interface>.*)', 'oper_status', 'down'],
                 ['info', '(?P<interface>.*)', 'switchport_enable', False]],
                'kwargs': {
                    'attributes': [
                        'info[(.*)][port_channel]', 'info[(.*)][enabled]',
                        'info[(.*)][oper_status]', 'info[(.*)][ipv4][(.*)]'
                    ]
                },
                'exclude':
                interface_exclude
            }
        },
        num_values={'interface': 1})
Example #29
0
class TriggerModifyLoopbackInterfaceIp(TriggerModify):
    """Modify and revert the ipv4 address for dynamically learned Loopback interface(s)."""

    __description__ = """Modify and revert the ipv4 address for dynamically learned Loopback interface(s).

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iteration when looping is needed,
                                in second. Default: 15
    steps:
        1. Learn Interface Ops object and store the "up" "ipv4" Loopback interface(s)
           if has any, otherwise, SKIP the trigger
        2. Save the current device configurations through "method" which user uses
        3. Modify the ipv4 address of the learned Loopback interface(s) from step 1
           with Interface Conf object
        4. Verify the ipv4 address of the learned Loopback interface(s) from step 3
           changes to the modified value in step 3
        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

    """

    # configuration steps callable
    def configure_intf_ip(self, conf_obj, ip, mask, **kwargs):
        ipv4 = IPv4Addr(device=kwargs['device'])
        ipv4.ipv4 = IPv4Address(ip)
        ipv4.prefix_length = mask
        conf_obj.add_ipv4addr(ipv4)
        conf_obj.build_config()

    # Mapping of Information between Ops and Conf
    # Also permit to dictates which key to verify
    mapping = Mapping(requirements={'ops.interface.interface.Interface':{
                                        'requirements': [['info', '(?P<name>[l|L]oopback\d+)',
                                                          'ipv4', '(?P<ip_mask>.*)', 'ip', '(?P<ip>.*)'],
                                                         ['info', '(?P<name>[l|L]oopback\d+)',
                                                          'ipv4', '(?P<ip_mask>.*)', 'prefix_length', '(?P<mask>.*)']],
                                        'all_keys':True,
                                        'exclude': interface_exclude,
                                        'all_keys': True}},
                      config_info={'conf.interface.Interface':{
                                      'requirements':[[partial(configure_intf_ip, ip='10.254.254.254',
                                                                                  mask='32')]],
                                      'verify_conf':False,
                                      'kwargs':{'mandatory':{'name': '(?P<name>.*)',
                                                             'attach': False}}}},
                      verify_ops={'ops.interface.interface.Interface':{
                                      'requirements': [['info', '(?P<name>.*)',  'ipv4', '10.254.254.254/32',
                                                        'prefix_length', '32'],
                                                       ['info', '(?P<name>.*)',  'ipv4', '10.254.254.254/32',
                                                        'ip', '10.254.254.254']],
                                      'exclude': interface_exclude}},
                      num_values={'name': 1, 'ip_mask': 1, 'ip' : 'all', 'mask': 'all'})
Example #30
0
class TriggerAddRemoveL3EtherchannelPagp(TriggerAddRemove):
    """Apply the configuration for L3 Etherchannel in PAGP mode, and remove the
    added Etherchannel in PAGP mode
    """

    __description__ = """Apply the configuration for L3 Etherchannel in PAGP mode, and remove the
    added Etherchannel in PAGP mode.

    trigger_datafile:
        Mandatory:
            timeout: 
                max_time (`int`): Maximum wait time for the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iterations when looping is needed,
                                in second. Default: 15
                method (`str`): Method to recover the device configuration,
                              Support methods:
                                'checkpoint': Rollback the configuration by
                                              checkpoint (nxos),
                                              archive file (iosxe),
                                              load the saved running-config file on disk (iosxr)
        Optional:
            tgn_timeout (`int`): Maximum wait time for all traffic threads to be
                                 restored to the reference rate,
                                 in second. Default: 60
            tgn_delay (`int`): Wait time between each poll to verify if traffic is resumed,
                               in second. Default: 10
            timeout_recovery: 
                Buffer recovery timeout make sure devices are recovered at the end
                of the trigger execution. Used when previous timeouts have been exhausted.

                max_time (`int`): Maximum wait time for the last step of the trigger,
                                in second. Default: 180
                interval (`int`): Wait time between iterations when looping is needed,
                                in second. Default: 15

    steps:
        1. Learn Interface Ops object to select up interfaces.
           Learn LAG ops object to find port-channle interfaces which does not exists.
        2. Save the current device configurations through "method" which user uses
        3. Add the configuration of Etherchannel in PAGP mode with interface Conf object,
           Add ip address configuration to the learned port-channel interfaces
        4. Verify the interfaces are in the por-channle interfaces from step 3 has configured
        5. Remove the Etherchannel and port-channel configurations.
        6. Recover the device configurations to the one in step 2
        7. Learn LAG Ops again and verify it is the same as the Ops in step 1

    """
    counters_port = []
    counters_keys = [[
        'interface', '(?P<bundle_intf>.*)', 'out', 'ucast_pkts', '(.*)'
    ]]

    # ping info
    pre_ping_info = [{
        'src': 'uut',
        'dest': 'helper',
        'ping': {
            'proto': 'ip',
            'count': 20,
            'size': 64,
            'extd_ping': 'n',
            'ping_packet_timeout': 2
        },
        'timeout_interval': 5,
        'timeout_max_time': 60,
        'exp_succ_perc': 100,
        'peer_num': 1
    }, {
        'src': 'helper',
        'dest': 'uut',
        'ping': {
            'proto': 'ip',
            'count': 100,
            'size': 64,
            'extd_ping': 'n',
            'ping_packet_timeout': 2
        },
        'timeout_interval': 5,
        'timeout_max_time': 60,
        'exp_succ_perc': 100,
        'peer_num': 1
    }]

    @aetest.processors(
        pre=[partial(ping_devices, ping_parameters=pre_ping_info)],
        post=[
            partial(check_interface_counters,
                    ports=counters_port,
                    keys=counters_keys,
                    threshold='islargerthan(100)')
        ])
    @aetest.test
    def verify_configuration(self, uut, abstract, steps):
        super().verify_configuration(uut, abstract, steps)


    mapping = Mapping(requirements={'ops.lag.lag.Lag':{
                                            'requirements':[\
                                                ['info', 'interfaces', '(?P<bundle_intf>.*)', NotExists('members')],
                                                ['info', 'interfaces', '(?P<bundle_intf>.*)', 'bundle_id', '(?P<bundle_id>.*)']],
                                            'all_keys': True,
                                            'kwargs':{'attributes':['info[interfaces][(.*)]']},
                                            'exclude': lag_exclude},
                                    'ops.interface.interface.Interface':{
                                            'requirements':[['info', '(?P<intf>\w+Ethernet[\d\/]+$)',
                                                             'switchport_enable', False],
                                                            ['info', '(?P<intf>\w+Ethernet[\d\/]+$)',
                                                             'oper_status', 'up']],
                                            'kwargs': {'attributes': ['info[(.*)][switchport_enable]',
                                                                      'info[(.*)][operational_mode]',
                                                                      'info[(.*)][oper_status]',
                                                                      'info[(.*)][enabled]',
                                                                      'info[(.*)][port_channel]']},
                                            'exclude': interface_exclude}},
                       config_info={'conf.interface.Interface':{
                                        'requirements':[['lag_bundle_id', '(?P<bundle_id>.*)'],
                                                        ['lag_activity', 'desirable']],
                                        'verify_conf':False,
                                        'kwargs':{'mandatory':{'name': '(?P<intf>.*)',
                                                               'attach': False}}}},
                      verify_ops={'ops.lag.lag.Lag':{
                                      'requirements': [\
                                                ['info', 'interfaces', '(?P<bundle_intf>.*)',
                                                 'bundle_id', '(?P<bundle_id>.*)'],
                                                ['info', 'interfaces', '(?P<bundle_intf>.*)',
                                                 'protocol', 'pagp'],
                                                ['info', 'interfaces', '(?P<bundle_intf>.*)',
                                                 'oper_status', 'up'],
                                                ['info', 'interfaces', '(?P<bundle_intf>.*)',
                                                 'name', '(?P<bundle_intf>.*)'],
                                                ['info', 'interfaces', '(?P<bundle_intf>.*)',
                                                 'members', '(?P<intf>.*)', 'bundled', True]],
                                      'kwargs':{'attributes':['info[interfaces][(.*)]']},
                                      'exclude': lag_exclude + ['attribute']},
                                  'ops.interface.interface.Interface':{
                                          'requirements':[['info', '(?P<intf>\w+Ethernet[\d\/]+$)',
                                                           'switchport_enable', False],
                                                          ['info', '(?P<intf>\w+Ethernet[\d\/]+$)',
                                                           'oper_status', 'up'],
                                                          ['info', '(?P<bundle_intf>.*)',
                                                           'oper_status', 'up'],
                                                          ['info', '(?P<bundle_intf>.*)',
                                                           'enabled', True],
                                                          ['info', '(?P<bundle_intf>.*)',
                                                           'oper_status', 'up'],
                                                          ['info', '(?P<bundle_intf>.*)',
                                                           'port_channel', 'port_channel_member', True],
                                                          ['info', '(?P<bundle_intf>.*)',
                                                           'port_channel', 'port_channel_member_intfs', '(.*)']],
                                            'kwargs': {'attributes': ['info[(.*)][switchport_enable]',
                                                                      'info[(.*)][operational_mode]',
                                                                      'info[(.*)][oper_status]',
                                                                      'info[(.*)][enabled]',
                                                                      'info[(.*)][port_channel]']},
                                          'exclude': interface_exclude}},
                      num_values={'intf':'all', 'bundle_id': 1})