Exemple #1
0
def save_bootvar(self, testbed):
    """Check boot information and save bootvar to startup-config

       Args:
           testbed (`obj`): Testbed object

       Returns:
           None

       Raises:
           pyATS Results
    """

    # Create Summary
    summary = Summary(title='Summary', width=90)

    devices = []
    for dev in self.parent.mapping_data['devices']:
        device = testbed.devices[dev]
        if device.type in EXCLUDED_DEVICE_TYPES:
            msg = "    - This subsection is not supported for 'TGN' devices"
            summarize(summary, message=msg, device=dev)
            continue
        devices.append(device)

    device_dict = {}
    failed = False

    # We don't catch exceptions since failures will lead to passx in that
    # CommonSetup subsection
    asynchronous_boot_var_output = pcall(asynchronous_save_boot_variable,
                                         ckwargs={
                                             'self': self,
                                             'device_dict': device_dict
                                         },
                                         device=tuple(devices))

    for item in asynchronous_boot_var_output:
        for dev, res in item.items():
            if res == 'Failed':
                failed = True
                msg = "    - Failed to save boot variable or copy "\
                    "running-config to startup-config"
                summarize(summary, message=msg, device=dev)
            elif res == 'Skipped':
                msg = "    - Skipped saving boot variable or copy "\
                    "running-config to startup-config"
                summarize(summary, message=msg, device=dev)
            else:
                msg = "    - Successfully saved boot variable"
                summarize(summary, message=msg, device=dev)

    summary.print()

    if failed:
        self.passx("Issue while saving boot variable on one of the devices, "
                   "Check section summary for more details")
Exemple #2
0
    def is_global_ver_enabled(self):
        '''To check if global verifications need to be udpated.'''

        # create summary instnace for Global verification
        self.global_summary = Summary(title='Global Verifications', width=150)

        if not self.obj.parent.verifications:
            self.global_summary.add_message('* No verifications imported')
            self.global_summary.add_subtitle_line()
            log.info('No verifications imported')
            return False

        if hasattr('self.obj.parent', 'verf'):
            if not self.obj.parent.verf:
                self.global_summary.add_message(
                    '* No global verifications executed')
                self.global_summary.add_subtitle_line()
                log.info('No global verifications executed')
                return False

        if not self.update_ver_list:
            self.global_summary.add_message(
                '* No verifications defined to be updated')
            self.global_summary.add_subtitle_line()
            log.info('No verifications require to be updated')
            return False

        for ver in self.update_ver_list:
            if hasattr('self.obj.parent', 'verf'):
                if self.device.name in self.obj.parent.verf and \
                self.obj.parent.verf[self.device.name] and \
                ver in self.obj.parent.verf[self.device.name]:
                    return True

        # add seperate line
        self.global_summary.add_sep_line()

        # compose the summary message
        self.global_summary.add_message('* Skipped Update\n')
        msgs = ''
        for ver in self.update_ver_list:
            msgs += '%s: Not learned before on device %s\n' % \
                (self.global_summary.add_indent(ver), self.device.name)
        self.global_summary.add_message(msgs)
        self.global_summary.add_subtitle_line()

        log.info(
            'Required Global verification "{v}" is '
            'not learned before on device {d}, Skip updating global'.format(
                v=self.update_ver_list, d=self.device.name))
        return False
Exemple #3
0
    def is_pts_enabled(self):
        '''To check if PTS need to be udpated.'''
        # create summary instnace for PTS
        self.pts_summary = Summary(title='PTS', width=150)

        if 'pts' not in self.obj.parent.parameters:
            self.pts_summary.add_message('* No PTS executed')
            log.info('No PTS executed')
            self.pts_summary.add_subtitle_line()
            return False

        if not self.update_feature_list:
            self.pts_summary.add_message(
                '* No PTS features require to be updated')
            self.pts_summary.add_subtitle_line()
            log.info('No PTS features require to be updated')
            return False

        for feature in self.update_feature_list:
            if feature in self.obj.parent.parameters['pts']:
                return True

        # add seperate line
        self.pts_summary.add_sep_line()

        # compose the summary message
        self.pts_summary.add_message('* Skipped Update')
        msgs = ''
        for fe in self.update_feature_list:
            msgs += '%s: Not learned before on device %s\n' % \
                (self.pts_summary.add_indent(fe), self.device.name)
        self.pts_summary.add_message(msgs)
        self.pts_summary.add_subtitle_line()

        log.info('Required features "{v}" is '
                 'not learned before on device {d}, Skip updating PTS'.format(
                     v=self.update_feature_list, d=self.device.name))
        return False
Exemple #4
0
def learn_system_defaults(self, testbed):
    """Execute commands to learn default system information
       Args:
           testbed (`obj`): Testbed object

       Returns:
           None

       Raises:
           pyATS Results
    """

    # Get default memory location
    self.parent.default_file_system = {}

    # Create Summary
    summary = Summary(title='Summary', width=150)

    for device in self.parent.mapping_data['devices']:
        dev = testbed.devices[device]
        lookup = Lookup.from_device(dev)

        # Skip in case of TGN device
        if dev.type in EXCLUDED_DEVICE_TYPES:
            log.info("This subsection is not supported for "
                     "TGN device '{}'".format(dev.name))
            msg = "    - This subsection is not supported for 'TGN' devices"
            summarize(summary, message=msg, device=dev.name)
            continue

        try:
            self.parent.default_file_system[dev.name] = lookup.sdk.libs.\
                            abstracted_libs.subsection.get_default_dir(
                                device=dev)
            msg = "    - Successfully learnt system default directroy"
            summarize(summary, message=msg, device=device)
        except LookupError as e:
            log.info('Cannot find device {d} correspoding get_default_dir'.\
                format(d=dev.name))
            msg = "    - Didn't find device OS corresponding "\
                "'get_default_dir' implementation, Please contact Genie support"
            summarize(summary, message=msg, device=device)
        except Exception as e:
            msg = "    - Failed to learn system default directory"
            summarize(summary, message=msg, device=device)
            summary.print()
            self.failed('Unable to learn system default directory',
                from_exception=e)

    summary.print()

    if not self.parent.default_file_system:
        # Create Summary
        summary = Summary(title='Summary', width=90)
        summary.add_message("* Summary for device(s): "
            "{}".format(', '.join(self.parent.mapping_data['devices'])))
        summary.add_sep_line()
        msg = "    - Couldn't set system default directory"
        summarize(summary, message=msg)
        summary.print()
        self.failed('Unable to set system default directory')