How to use the genie.utils.timeout.Timeout function in genie

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

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

github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / iosxe / hardware / verify.py View on Github external
None
    """
    slots = spa.split("/")
    reqs = R(
        [
            "slot",
            slots[0],
            "(?P.*)",
            "(?P.*)",
            "subslot",
            slots[1],
            "(?P.*)",
        ]
    )

    timeout = Timeout(max_time, check_interval)
    while timeout.iterate():
        try:
            out = device.parse("show platform")
        except SchemaEmptyParserError:
            timeout.sleep()
            continue

        found = find([out], reqs, filter_=False, all_keys=True)
        if not found:
            return True
        timeout.sleep()

    return False
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / iosxr / platform / verify.py View on Github external
''' Verify module serial number is matched with expected number

        Args:
            device (`obj`): Device object
            installed_packages (`list`): List of packages to verify that exist
            max_time (`int`): Maximum time to wait while checking for pies installed
                              Default 300 seconds (Optional)
          check_interval (`int`): Time interval while checking for pies installed
                                  Default 30 seconds (Optional)

        Returns:
            result (`bool`): Verified result
    '''

    timeout = Timeout(max_time, check_interval)

    while timeout.iterate():

        active_packages = device.api.get_current_active_pies()

        # Trim out active_packages
        if active_packages:
            active_packages = [item.split(":")[1] for item in active_packages]

        if set(installed_packages).intersection(active_packages):
            log.info("Installed packages {} present under 'Active Packages'".\
                    format(installed_packages))
            return True

        log.warning("Installed packages {} *not* present in 'Active Packages'"
                    "\nRe-checking after {} seconds...".\
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / iosxe / routing / verify.py View on Github external
"""
    route = route.split('/')
    if len(route) > 1:
        route = '{} {}'.format(route[0], device.api.int_to_mask(int(route[1])))
    else:
        route = route[0]

    patterns = ['No Label', 'implicit-null', 'Pop Label', 'none', '']
    if none_pattern:
        patterns.extend(none_pattern)

    cmd1 = "show ip route {}".format(route)
    cmd2 = "show ip cef {}".format(route)
    cmd3 = "show mpls forwarding-table {}".format(route)

    timeout = Timeout(max_time, check_interval)
    while timeout.iterate():
        result = True
        table = PrettyTable()
        table.field_names = ['RIB (INTF)', 'RIB (NH)', 'RIB (LABEL)', 
                             'FIB (INTF)', 'FIB(NH) ', 'FIB (LABEL)', 
                             'FIB (LOCAL LABEL)', 'LFIB (INTF)', 'LFIB(NH)', 
                             'LFIB (LABEL)', 'LFIB (LOCAL LABEL)', 'PASS/FAIL']

        try:
            out1 = device.parse(cmd1)
        except Exception as e:
            log.error("Failed to parse '{}':\n{}".format(cmd1, e))
            result = False
            timeout.sleep()
            continue
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / iosxe / ospf / verify.py View on Github external
def is_ospf_neighbor_established_on_interface(device, interface, max_time=30, check_interval=10):
    """ Verify OSPF is established on the interface

        Args:
            device (`obj`): Device object
            interface (`str`): Interface name
            max_time (`int`): Maximum wait time
            check_interval (`int`): Check interval

        Returns:
            result (`bool`): Verified result
    """
    cmd = "show ip ospf neighbor"
    timeout = Timeout(max_time, check_interval)

    while timeout.iterate():
        try:
            out = device.parse(cmd)
        except Exception as e:
            log.error("Failed to parse '{cmd}': {e}".format(cmd=cmd, e=e))
            timeout.sleep()
            continue

        if interface in out.get('interfaces', {}):
            log.info("OSPF interface {intf} is established".format(intf=interface))
            return True

        timeout.sleep()

    return False
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / iosxe / cef / verify.py View on Github external
[
            "vrf",
            "(?P{vrf})".format(vrf=vrf),
            "address_family",
            "(?P.*)",
            "prefix",
            "(?P.*)",
            "output_chain",
            "tag_midchain",
            "(?P.*)",
            "label",
            "(?P<label>.*)"
        ]
    )

    timeout = Timeout(max_time, check_interval)
    while timeout.iterate():
        try:
            out = device.parse('show ip cef vrf {vrf} {prefix} internal'.format(vrf=vrf, prefix=prefix))
        except SchemaEmptyParserError:
            log.info("Parser output is empty")
            timeout.sleep()
            continue

        stack_copy = list(stack)
        found = find([out], reqs, filter_=False, all_keys=True)
        if found:
            for label in found[0][0]:
                for stack_item in stack_copy:
                    if str(stack_item) in label:
                        # If item found, break to prevent else block from running
                        stack_copy.remove(stack_item)
</label>
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / junos / ospf / verify.py View on Github external
"""Verify 'show ospf database network lsa-id {ipaddress} detail' attached-router contains expected_id

    Args:
        device ('obj'): device to use
        expected_id ('str'): expected router id
        ipaddress ('str'): address to use in show command
        max_time ('int'): Maximum time to keep checking
        check_interval ('int'): How often to check

    Raise: None

    Returns: Boolean

    """

    timeout = Timeout(max_time, check_interval)

    while timeout.iterate():
        out = None
        try:        
            out = device.parse(f'show ospf database network lsa-id {ipaddress} detail')   
        except SchemaEmptyParserError:
            timeout.sleep()
            continue

        if expected_id in out.q.get_values("attached-router"):           
            return True
        else:
            timeout.sleep()
            continue

    return False
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / junos / ospf / verify.py View on Github external
device ('obj'): device to use
            expected_interface ('str'): Interface to use
            expected_interface_type ('str'): Interface type
            expected_state ('str'): Interface state
            extensive ('boolean'): Flag for extensive command
            max_time ('int'): Maximum time to keep checking
            check_interval ('int'): How often to check
            expected_hello_interval ('str'): Expected hello interval

        Returns:
            True/False

        Raises:
            N/A
    """
    timeout = Timeout(max_time, check_interval)

    while timeout.iterate():
        out = None
        try:
            if extensive:
                out = device.parse('show ospf interface extensive')
            else:
                out = device.parse('show ospf interface')
        except SchemaEmptyParserError:
            timeout.sleep()
            continue

        # {
        # "ospf-interface-information": {
        #     "ospf-interface": [
        #         {
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / junos / ospf3 / verify.py View on Github external
"""Verify 'show ospf route network extensive'

    Args:
        device ('obj'): device to use
        expected_interface ('str'): address to verify
        expected_path_type ('str'): path to verify
        max_time ('int'): Maximum time to keep checking
        check_interval ('int'): How often to check

    Raise: None

    Returns: Boolean

    """

    timeout = Timeout(max_time, check_interval)

    while timeout.iterate():
        out = None
        try:

            out = device.parse('show ospf3 route network extensive')
        except SchemaEmptyParserError:
            timeout.sleep()
            continue

        #{'ospf-route-entry': 
        #   {'address-prefix': '1.1.1.1/32', 
        #                      'route-path-type': 'Intra', 'route-type': 'Network', 
        #                      'next-hop-type': 'IP', 'interface-cost': '0', 
        #                      'ospf-next-hop': {'next-hop-name': {'interface-name': 'lo0.0'}}, 
        #                      'ospf-area': '0.0.0.0', 
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / junos / ospf / verify.py View on Github external
check_interval=10):
    """Verify 'show ospf database' lsa-types contains expected_types

    Args:
        device ('obj'): device to use
        expected_types ('str'): types to verify
        max_time ('int'): Maximum time to keep checking. Defaults to 60
        check_interval ('int'): How often to check. Defaults to 10

    Raise: None

    Returns: Boolean

    """

    timeout = Timeout(max_time, check_interval)

    while timeout.iterate():
        out = None
        try:
            
            out = device.parse('show ospf database')
        except SchemaEmptyParserError:
            timeout.sleep()
            continue


        found_types = out.q.get_values("lsa-type")

        if set(found_types).issuperset(set(expected_types)):
            return True
        else:
github CiscoTestAutomation / genielibs / pkgs / sdk-pkg / src / genie / libs / sdk / apis / iosxe / segment_routing / verify.py View on Github external
device (`obj`): Device object
            policy (`str`): Policy name
            expected_bsid (`int`): Expected Binding SID
            expected_mode (`str`): Expected allocation mode
            expected_state (`str`): Expected binding state
            policy_dict (`dict`): Policy dict from parser output 
                IOSXE Parser - ShowSegmentRoutingTrafficEngPolicy
                cmd - show segment-routing traffic-eng policy all
            max_time (`int`): Max time, default: 30
            check_interval (`int`): Check interval, default: 10
        Returns
            result (`bool`): Verified result
            sid (`int`): Binding sid
    """
    cmd = 'show segment-routing traffic-eng policy name {policy}'.format(policy=policy)
    timeout = Timeout(max_time, check_interval)

    while timeout.iterate():

        if policy_dict is None:
            try:
                out = device.parse(cmd)
            except Exception as e:
                log.error("Failed to parse '{cmd}': {e}".format(cmd=cmd, e=e))
                timeout.sleep()
                continue
        else:
            out = policy_dict

        bsid_dict = out.get(policy, {}).get('attributes', {}).get('binding_sid', {})

        if bsid_dict: