def diff(self, steps, section, name, device, pre, post, alias=None, continue_=True, fail_different=False, command=None, exclude=None, processor='', health_uids=None, health_groups=None, health_sections=None, feature=None, mode=None, **kwargs): msg = kwargs.pop('custom_substep_message', "Perform Diff for '{device}'".format(device=device.name)) with steps.start(msg, continue_=continue_) as step: exclude_items = _get_exclude(command, device) # if feature is given, get exclude from the Ops if feature: try: exclude_items.extend(get_ops_exclude(feature, device)) except LookupError: log.warning( "No Ops for {feature} was found. Couldn't retrieve exclude list." .format(feature=feature)) # check given mode if mode and mode not in ['add', 'remove', 'modified']: log.warning( "Wrong mode '{mode}' was given. Ignored.".format(mode=mode)) if exclude and isinstance(exclude, list): exclude_items.extend(exclude) log.debug('exclude: {exclude}'.format(exclude=exclude_items)) try: diff = Diff(pre, post, exclude=exclude_items, mode=mode) except Exception as e: step.failed(str(e)) diff.findDiff() # check content of diff if str(diff): log.info(diff) if fail_different: step.failed('{pre} and {post} are not ' 'identical'.format(pre=pre, post=post)) else: step.passed('{pre} and {post} are identical'.format(pre=pre, post=post))
def _get_exclude(command, device): exclude = None if command: try: # Try parser return get_parser_exclude(command, device) except Exception: pass try: # Try ops return get_ops_exclude(command, device) except Exception: pass return []