Ejemplo n.º 1
0
def learn_system(device, steps, platform_pts=None):
    """Learn and store the system properties

       Args:
           testbed (`obj`): Testbed object

       Returns:
           None

       Raises:
           pyATS Results
    """

    # learn show version
    if not platform_pts:
        with steps.start(
                "Store image type/router type from 'show version' on {}".
                format(device.name)) as step:
            try:
                output = ShowVersion(device=device).parse()
                device.image_type = output['version']['image_type']
                device.router_type = output['version']['rtr_type']
            except Exception as e:
                log.warning(e)
                step.passx('Cannot get required router info on {}'.format(
                    device.name))

            log.info('Image type: {}\nRouter type: {}'.format(
                device.image_type, device.router_type))

        # learn show version
        with steps.start(
                "Store switches info from 'show platform' on {}".format(
                    device.name)) as step:

            req = {
                'active':
                [['slot', '(?P<switch>.*)', 'rp', '(.*)', 'role', 'Active']],
                'standby':
                [['slot', '(?P<switch>.*)', 'rp', '(.*)', 'role', 'Standby']],
                'members':
                [['slot', '(?P<switch>.*)', 'rp', '(.*)', 'role', 'Member']]
            }

            try:
                output = ShowPlatform(device=device).parse()
                ret = get_requirements(requirements=req, output=output)
                device.active = ret['active'][0]['switch']
                device.standby = ret['standby'][0]['switch']
                device.members = [i['switch'] for i in ret['members']]
            except Exception as e:
                log.warning(e)
                step.passx('Cannot get required router info on {}'.format(
                    device.name))

            log.info(
                'Active Switch: {}\nStandby Switch: {}\nMember Switch: {}'.
                format(device.active, device.standby, device.members))
    else:
        with steps.start("Store image type/router type from PTS on {}".format(
                device.name)) as step:
            try:
                # device.image_type = platform_pts.image_type
                device.image_type = 'developer image'
                device.router_type = platform_pts.rtr_type
            except Exception as e:
                log.warning(e)
                step.passx('Cannot get required router info on {}'.format(
                    device.name))

            log.info('Image type: {}\nRouter type: {}'.format(
                device.image_type, device.router_type))

        with steps.start("Store switches info from PTS on {}".format(
                device.name)) as step:

            req = {
                'active':
                [['slot', 'rp', '(?P<switch>.*)', 'swstack_role', 'Active'],
                 ['slot', 'rp', '(?P<switch>.*)', 'state', 'Ready']],
                'standby':
                [['slot', 'rp', '(?P<switch>.*)', 'swstack_role', 'Standby'],
                 ['slot', 'rp', '(?P<switch>.*)', 'state', 'Ready']],
                'members':
                [['slot', 'rp', '(?P<switch>.*)', 'swstack_role', 'Member'],
                 ['slot', 'rp', '(?P<switch>.*)', 'state', 'Ready']]
            }

            try:
                ret = get_requirements(requirements=req, output=platform_pts)
                device.active = ret['active'][0]['switch']
                device.standby = ret['standby'][0]['switch']
                device.members = [i['switch'] for i in ret['members']]
            except Exception as e:
                log.warning(e)
                step.passx('Cannot get required switches info on {}'.format(
                    device.name))

            log.info(
                'Active Switch: {}\nStandby Switch: {}\nMember Switch: {}'.
                format(device.active, device.standby, device.members))
Ejemplo n.º 2
0
    def verify_show_version(self, uut, steps, timeout):
        '''Platform Manager: Log Check for show version
           Args:
               uut (`obj`): Device object.
               steps (`step obj`): aetest step object
               timeout (`timeout obj`): Timeout Object

           Returns:
               None

           Raises:
               pyATS Results
        '''

        try:
            if hasattr(uut, 'workers'):
                with uut.allocate() as worker:
                    output = ShowVersion(device=worker).parse()
            else:
                output = ShowVersion(device=uut).parse()
        except Exception as e:
            self.skipped('Cannot get info from show version',
                         from_exception=e,
                         goto=['next_tc'])

        # Check for Intermittent Issue
        with steps.start('Attempting to check message from show version',
                         continue_=True) as step:
            expect_string = \
                'This product contains cryptographic features and is subject to United\n'\
                'States and local country laws governing import, export, transfer and\n'\
                'use. Delivery of Cisco cryptographic products does not imply\n'\
                'third-party authority to import, export, distribute or use encryption.\n'\
                'Importers, exporters, distributors and users are responsible for\n'\
                'compliance with U.S. and local country laws. By using this product you\n'\
                'agree to comply with applicable laws and regulations. If you are unable\n'\
                'to comply with U.S. and local laws, return this product immediately.\n'\
                '\n'\
                'A summary of U.S. laws governing Cisco cryptographic products may be found at:\n'\
                'http://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n'\
                '\n'\
                'If you require further assistance please contact us by sending email to\n'\
                '[email protected].\n'\
                '\n\n'\
                'Technology Package License Information:'

            log.info('Expected string is {}'.format(expect_string))

            for item in expect_string.splitlines():
                if item in uut.execute.result:
                    log.info(
                        'There is no corruption/missing data observed after Reload Reason. '
                        'Continuing Show Version testing...')
                else:
                    self.failed('Found missing string: {}'.format(item))

        # get version info
        with steps.start('Get version information', continue_=True) as step:
            req = {
                'copyright_or_technical_support': [[
                    'version', 'image_type',
                    '(?P<copyright_or_technical_support>.*)'
                ]],
                'rom': [['version', 'rom', '(?P<rom>.*)']],
                'boot_loader': [['version', 'bootldr', '(?P<boot_loader>.*)']],
                'host': [['version', 'hostname', '(?P<host>.*)']],
                'device_uptime':
                [['version', 'uptime', '(?P<device_uptime>.*)']],
                'control_processor_uptime': [[
                    'version', 'uptime_this_cp',
                    '(?P<control_processor_uptime>.*)'
                ]],
                'reload_reason':
                [['version', 'last_reload_reason', '(?P<reload_reason>.*)']],
                'chassis': [['version', 'chassis', '(?P<chassis>.*)']],
                'memory': [['version', 'main_mem', '(?P<memory>.*)']],
                'processor_type':
                [['version', 'processor_type', '(?P<processor_type>.*)']],
                'processor_board_id':
                [['version', 'chassis_sn', '(?P<processor_board_id>.*)']],
            }
            req_full_stack = {
                'base_ethernet_mac_address': [[
                    'version', 'switch_num', '(?P<stack>.*)', 'mac_address',
                    '(?P<base_ethernet_mac_address>.*)'
                ]],
                'motherboard_assembly_number': [[
                    'version', 'switch_num', '(?P<stack>.*)',
                    'mb_assembly_num', '(?P<motherboard_assembly_number>.*)'
                ]],
                'motherboard_serial_number': [[
                    'version', 'switch_num', '(?P<stack>.*)', 'mb_sn',
                    '(?P<motherboard_serial_number>.*)'
                ]],
                'model_revision_number': [[
                    'version', 'switch_num', '(?P<stack>.*)', 'model_rev_num',
                    '(?P<model_revision_number>.*)'
                ]],
                'motherboard_revision_number': [[
                    'version', 'switch_num', '(?P<stack>.*)', 'mb_rev_num',
                    '(?P<motherboard_revision_number>.*)'
                ]],
                'model_number': [[
                    'version', 'switch_num', '(?P<stack>.*)', 'model_num',
                    '(?P<model_number>.*)'
                ]],
                'system_serial_number': [[
                    'version', 'switch_num', '(?P<stack>.*)', 'system_sn',
                    '(?P<system_serial_number>.*)'
                ]],
            }
            try:
                requirements = deepcopy(req)
                requirements.update(req_full_stack)
                ret = get_requirements(requirements=requirements,
                                       output=output)
            except Exception as e:
                step.failed(
                    "Cannot get version required info from show version"
                    "\nrequirements: {}".format(requirements),
                    from_exception=e)

        # Print the information
        with steps.start('Check and print the version info',
                         continue_=True) as step:
            try:
                verify_requirements(reqs=req,
                                    keys_dict=ret,
                                    raise_exception=False)
                verify_requirements(reqs=req_full_stack,
                                    keys_dict=ret,
                                    raise_exception=False,
                                    full_stack=self.full_stack)
            except Exception as e:
                step.failed("Could not reach SSO state".format(requirements),
                            from_exception=e,
                            goto=['next_tc'])
Ejemplo n.º 3
0
def save_device_information(device, **kwargs):
    """Check boot variable from show version and show reedundancy
    to see if they are consistent. Configure boot var if not same,
    and save running-configuration to startup-config.
    This is for asr1k devices.

    Args:
      Mandatory:
        device (`obj`) : Device object.

    Raises:
        Exception: show command is failed to execute or
                   failed to get image information

    Example:
        >>> save_device_information(device=Device())
    """
    # get bootvar from show version
    try:
        out = ShowVersion(device).parse()
        ver_sys_img = out['version']['system_image']
    except Exception as e:
        raise Exception('Cannot get the image information '
                        'from "show version"') from e

    # get bootvar from show redundancy
    try:
        out = ShowRedundancy(device).parse()
        redundancy_image = []
        if 'slot' in out:
            for slot in out['slot']:
                redundancy_image.append(out['slot'][slot]['boot'])
            redundancy_image = list(set(redundancy_image))

            # active and standby image mismatch
            if len(redundancy_image) != 1:
                response = OrderedDict()
                response[
                    r"Destination +filename +\[.*\].*"] = "econ_send \\\r;exp_continue"
                response[
                    r"Do +you +want +to +over +write? +\[confirm\]"] = "econ_send no\\\r;exp_continue"
                # copy image to standby bootflash:
                # Destination filename [asr1000rpx.bin]?
                device.execute('copy {} stby-bootflash:'.format(ver_sys_img),
                               reply=response)
            redundancy_image = str(redundancy_image[0]).split(',')[0]
        else:
            redundancy_image = None
    except Exception as e:
        log.warning('Cannot get the boot image '
                    'information from "show redundancy"')
        redundancy_image = None

    # check if need to configure the boot vars
    if ver_sys_img:
        if ver_sys_img == redundancy_image:
            log.info('Device will reload with image {}'.format(ver_sys_img))
            device.system = ver_sys_img
        else:
            device.system = ver_sys_img
            # configure boot var
            cfg_str = 'no boot system\nboot system {sys_img}'.format(
                sys_img=ver_sys_img)
            device.configure(cfg_str)

    # configure config-register
    device.configure('config-register 0x2102')

    # save all configuration to startup for all slots
    dialog = Dialog([
        Statement(pattern=r'Destination +filename +\[.*\].*',
                  action='sendline()',
                  loop_continue=True,
                  continue_timer=False)
    ])
    device.execute('copy running-config nvram:startup-config', reply=dialog)
    device.execute('write memory')
Ejemplo n.º 4
0
def save_device_information(device, **kwargs):
    """Check boot variable from show boot and show reedundancy
    to see if they are consistent. Configure boot var if not same,
    and save running-configuration to startup-config.
    This is for c3850 devices.

    Args:
      Mandatory:
        device (`obj`) : Device object.

    Raises:
        Exception: show command is failed to execute or
                   failed to get image information

    Example:
        >>> save_device_information(device=Device())
    """
    # get bootvar from show version
    ver_sys_img = getattr(kwargs.get('platform_pts', {}), 'image', None)

    if not ver_sys_img:
        log.info(
            'Cannot get image from PTS, get image from show version instead')
        log.info("Get device current image from 'show version' on {}".format(
            device.name))
        try:
            out = ShowVersion(device).parse()
            ver_sys_img = out['version']['system_image']
        except Exception as e:
            raise Exception('Cannot get the image information '
                            'from "show version"') from e
    else:
        log.info('Device {d} version image is {i} from PTS'.format(
            i=ver_sys_img, d=device.name))

    # get bootvar from show boot
    try:
        out = ShowBoot(device).parse()
        current_boot_variable = out['current_boot_variable']
        next_reload_boot_variable = out['next_reload_boot_variable']
        if next_reload_boot_variable in current_boot_variable:
            next_reload_image = next_reload_boot_variable
        else:
            next_reload_image = current_boot_variable
    except Exception as e:
        log.warning('Cannot get the boot image '
                    'information from "show boot"')
        next_reload_image = None

    # check if need to configure the boot vars
    if ver_sys_img:
        if ver_sys_img == next_reload_image:
            log.info('Device will reload with image {}'.format(ver_sys_img))
            device.system = ver_sys_img
        else:
            device.system = ver_sys_img
            # configure boot var
            cfg_str = 'no boot system\nboot system {sys_img}'.format(
                sys_img=ver_sys_img)
            device.configure(cfg_str)

    # avoid manual boot
    device.configure('no boot manual')

    # configure config-register
    device.configure('config-register 0x2102')

    # save all configuration to startup for all slots
    dialog = Dialog([
        Statement(pattern=r'Destination +filename +\[.*\].*',
                  action='sendline()',
                  loop_continue=True,
                  continue_timer=False)
    ])
    device.execute('copy running-config nvram:startup-config', reply=dialog)
    device.execute('write memory')