class UsagePrinter(object): """ Class for printing the recognized metadata for a model file, to STDOUT. This output is referred to as the usage. """ ControlOptions = Enum(['RECURSIVE', 'FOLDERS_ONLY', 'ATTRIBUTES_ONLY']) def __init__(self, aliases, logger): """ :param aliases: A reference to an Aliases class instance :param logger: A reference to the platform logger to write to, if a log entry needs to be made """ self._logger = logger self._aliases = aliases self._alias_helper = AliasHelper(self._aliases, self._logger, ExceptionType.VALIDATE) def print_model_path_usage(self, model_path, control_option): """ Prints out the usage information for a given '''model_path'''. '''model_path''' needs to be specified using the following pattern: <model_section>[:/<section_folder>[/<section_subfolder>|...]] Examples: 'domainInfo', 'domainInfo:' or 'domainInfo:/' (all 3 are rquivalent) 'topology:/Server' 'resources:/JDBCSystemResource/JdbcResource/JDBCDriverParams' 'appDeployments:/Application' :param model_path: A forward-slash delimited string contain the model path to print usage for :param control_option: A command-line switch that controls what is output to STDOUT :return: :raises ValidationException: if an AliasException is raised during an invocation of an aliases API call. """ model_path_tokens = self.__create_model_path_tokens(model_path) top_level_key = model_path_tokens[0] if control_option == self.ControlOptions.RECURSIVE: print validation_utils.format_message('WLSDPLY-05100') elif control_option == self.ControlOptions.FOLDERS_ONLY: print validation_utils.format_message('WLSDPLY-05101') elif control_option == self.ControlOptions.ATTRIBUTES_ONLY: print validation_utils.format_message('WLSDPLY-05102') validation_utils.print_blank_lines() valid_section_folder_keys = [] if model_path_tokens[0] == model_constants.TOPOLOGY: valid_section_folder_keys = self._aliases.get_model_topology_top_level_folder_names( ) if model_path_tokens[0] == model_constants.RESOURCES: valid_section_folder_keys = self._aliases.get_model_resources_top_level_folder_names( ) if model_path_tokens[0] == model_constants.APP_DEPLOYMENTS: valid_section_folder_keys = self._aliases.get_model_app_deployments_top_level_folder_names( ) if len(model_path_tokens) == 1: if model_path_tokens[0] == model_constants.DOMAIN_INFO: self.__print_domain_info_usage(model_path_tokens) else: self.__print_top_level_usage(top_level_key, valid_section_folder_keys, control_option) else: self.__print_model_section_usage(model_path_tokens, valid_section_folder_keys, control_option) return def __print_domain_info_usage(self, model_path_tokens): """ Prints out the usage for the domainInfo section of a model :param model_path_tokens: A Python list of path elements built from model path :return: """ _method_name = '__print_domain_info_usage' self._logger.finest('1 model_path_tokens={0}', str(model_path_tokens), class_name=_class_name, method_name=_method_name) model_path = validation_utils.format_message( 'WLSDPLY-05103', '%s:' % model_path_tokens[0]) # Print 'Path: <model_section>' label and field validation_utils.print_indent(model_path, 0) validation_utils.print_blank_lines() attr_infos = self._alias_helper.get_model_domain_info_attribute_names_and_types( ) _print_attr_infos(attr_infos, 1) return def __print_top_level_usage(self, top_level_key, valid_section_folder_keys, control_option): """ Prints out the usage for a section of a model, when just the section_name[:[/}} is provided :param top_level_key: The name of one of the model sections :param valid_section_folder_keys: Python list of the valid model section names :param control_option: A command-line switch that controls what is output to STDOUT :return: """ _method_name = '__print_top_level_usage' self._logger.finest('1 top_level_key={0}', top_level_key, class_name=_class_name, method_name=_method_name) location_path = '%s:' % top_level_key self._logger.finest('1 location_path={0}', location_path, class_name=_class_name, method_name=_method_name) model_section = validation_utils.format_message( 'WLSDPLY-05104', location_path) # Print 'Section: <model_section>' label and field validation_utils.print_indent(model_section, 0) if control_option == self.ControlOptions.ATTRIBUTES_ONLY: # Doing an ATTRIBUTES_ONLY on a top level key is a no-op return validation_location = LocationContext() if control_option == self.ControlOptions.FOLDERS_ONLY: validation_utils.print_blank_lines() validation_utils.print_indent( validation_utils.format_message('WLSDPLY-05105'), 1) valid_section_folder_keys.sort() for section_folder_key in valid_section_folder_keys: if control_option == self.ControlOptions.FOLDERS_ONLY: validation_utils.print_indent(section_folder_key, 2) elif control_option == self.ControlOptions.RECURSIVE: validation_location.append_location(section_folder_key) name_token = self._alias_helper.get_name_token( validation_location) if name_token is not None: validation_location.add_name_token( name_token, '%s-0' % section_folder_key) self._logger.finest('1 validation_location={0}', validation_location, class_name=_class_name, method_name=_method_name) location_path = '%s:%s' % ( top_level_key, validation_location.get_folder_path()) model_path = validation_utils.format_message( 'WLSDPLY-05103', location_path) validation_utils.print_blank_lines() validation_utils.print_indent(model_path, 0) validation_utils.print_blank_lines() self.__print_folders_usage(validation_location, control_option, 1) validation_location.pop_location() return def __print_model_section_usage(self, model_path_tokens, valid_section_folder_keys, control_option): """ Prints out the usage for a section of a model, when more than just the section_name[:[/}} is provided :param model_path_tokens: A Python list of path elements built from model path :param valid_section_folder_keys: A list of valid folder names for the model section the usage is being printed for :param control_option: A command-line switch that controls what is output to STDOUT :return: """ _method_name = '__print_model_section_usage' self._logger.finest('1 model_path_tokens={0}, control_option={1}', str(model_path_tokens), self.ControlOptions.from_value(control_option), class_name=_class_name, method_name=_method_name) self._logger.finest('1 valid_section_folder_keys={0}', str(valid_section_folder_keys), class_name=_class_name, method_name=_method_name) self.__validate_section_folder_path(model_path_tokens, valid_section_folder_keys) validation_location = LocationContext() model_path = validation_utils.format_message( 'WLSDPLY-05103', '%s:/%s' % (model_path_tokens[0], '/'.join(model_path_tokens[1:]))) # Print 'Path: <model_section>' header validation_utils.print_indent(model_path, 0) validation_utils.print_blank_lines() # Populate the location context using model_path_tokens[1:] for folder_key in model_path_tokens[1:]: validation_location.append_location(folder_key) name_token = self._alias_helper.get_name_token(validation_location) if name_token is not None: validation_location.add_name_token(name_token, '%s-0' % folder_key) self._logger.finest('2 validation_location={0}', validation_location, class_name=_class_name, method_name=_method_name) # Print the attributes associated with location context self.__print_attributes_usage(validation_location, 1) if control_option != self.ControlOptions.ATTRIBUTES_ONLY: # Print the folders associated with location context self.__print_folders_usage(validation_location, control_option, 1) self._logger.exiting(class_name=_class_name, method_name=_method_name) return def __print_folders_usage(self, validation_location, control_option, indent_level): """ Prints out the usage for the folders in a model location :param validation_location: An object containing data about the model location being worked on :param control_option: A command-line switch that controls what is output to STDOUT :param indent_level: The level to indent by, before printing output :return: """ _method_name = '__print_folders_usage' valid_subfolder_keys = self._alias_helper.get_model_subfolder_names( validation_location) self._logger.finest( '3 aliases.get_model_subfolder_names(validation_location) returned: {0}', str(valid_subfolder_keys), class_name=_class_name, method_name=_method_name) if not valid_subfolder_keys: return validation_utils.print_indent( validation_utils.format_message('WLSDPLY-05105'), indent_level) valid_subfolder_keys.sort() for key in valid_subfolder_keys: validation_location.append_location(key) name_token = self._alias_helper.get_name_token(validation_location) if name_token is not None: validation_location.add_name_token(name_token, '%s-0' % key) self._logger.finest('3 validation_location={0}', validation_location, class_name=_class_name, method_name=_method_name) validation_utils.print_indent(key, indent_level + 1) if control_option != self.ControlOptions.FOLDERS_ONLY: self.__print_attributes_usage(validation_location, indent_level + 2) if control_option == self.ControlOptions.RECURSIVE: # Call this __print_folders_usage() function recursively self.__print_folders_usage(validation_location, control_option, indent_level + 2) validation_location.pop_location() return def __print_attributes_usage(self, validation_location, indent_level): """ Prints out the usage for the attributes in a model location :param validation_location: An object containing data about the model location being worked on :param indent_level: The level to indent by, before printing output :return: """ _method_name = '__print_attributes_usage' attr_infos = self._alias_helper.get_model_attribute_names_and_types( validation_location) self._logger.finer('WLSDPLY-05012', str(validation_location), str(attr_infos), class_name=_class_name, method_name=_method_name) _print_attr_infos(attr_infos, indent_level) return def __create_model_path_tokens(self, model_path=''): """ Creates a Python list from the elements in the specified model_path. :param model_path: A forward-slash delimited string contain the model path to print usage for :return: """ _method_name = '__create_model_path_tokens' self._logger.entering(model_path, class_name=_class_name, method_name=_method_name) if model_path[-1:] != ':': m = MODEL_PATH_PATTERN.match(model_path) if m is None: ex = exception_helper.create_validate_exception( 'WLSDPLY-05106', model_path) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex self._logger.finest('m.group(1)={0}, m.group(3)={1}', str(m.group(1)), str(m.group(3)), class_name=_class_name, method_name=_method_name) # Replace any ':' in model_path with '', then split it on '/' into a list model_path_tokens = model_path.replace(':', '').split('/') # Remove any blank list items caused by the user entering # extraneous '/' characters. while '' in model_path_tokens: del model_path_tokens[model_path_tokens.index('')] recognized_top_level_keys = model.get_model_top_level_keys() self._logger.finest('recognized_top_level_keys={0}', str(recognized_top_level_keys), class_name=_class_name, method_name=_method_name) top_level_key = model_path_tokens[0] if top_level_key not in recognized_top_level_keys: ex = exception_helper.create_validate_exception( 'WLSDPLY-05107', top_level_key, '%s' % ', '.join(recognized_top_level_keys)) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex return model_path_tokens def __validate_section_folder_path(self, model_path_tokens, valid_section_folder_keys): """ Verifies that a model path element is in the specified valid_section_folder_keys list. :param model_path_tokens: A Python list of path elements built from model path :param valid_section_folder_keys: A Python list of folder names :return: """ _method_name = '__validate_section_folder_path' if model_path_tokens[1] not in valid_section_folder_keys: ex = exception_helper.create_validate_exception( 'WLSDPLY-05108', '%s:/' % model_path_tokens[0], '%s' % '/'.join(model_path_tokens[1:]), '%s' % ', '.join(valid_section_folder_keys)) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex return
""" Copyright (c) 2020, Oracle Corporation and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ from wlsdeploy.util.enum import Enum ControlOptions = Enum( ['NORMAL', 'RECURSIVE', 'FOLDERS_ONLY', 'ATTRIBUTES_ONLY']) def show_attributes(control_option): """ Determine if attributes should be displayed, based on the control option. :param control_option: the control option to be checked :return: True if attributes should be displayed, False otherwise """ return control_option in [ ControlOptions.NORMAL, ControlOptions.ATTRIBUTES_ONLY ] def show_folders(control_option): """ Determine if folders should be displayed, based on the control option. :param control_option: the control option to be checked :return: True if folders should be displayed, False otherwise """ return control_option != ControlOptions.ATTRIBUTES_ONLY
WLST_PATH = 'wlst_path' WLST_PATHS = 'wlst_paths' WLST_READ_TYPE = 'wlst_read_type' WLST_SKIP_NAMES = '__wlst_skip_names__' WLST_SUBFOLDERS_PATH = 'wlst_subfolders_path' WLST_TYPE = 'wlst_type' # CHILD_FOLDER_TYPES MULTIPLE = 'multiple' MULTIPLE_WITH_TYPE_SUBFOLDER = 'multiple_with_type_subfolder' NONE_CHILD_FOLDERS_TYPE = 'none' SINGLE = 'single' SINGLE_UNPREDICTABLE = 'single_unpredictable' ChildFoldersTypes = Enum([ 'MULTIPLE', 'MULTIPLE_WITH_TYPE_SUBFOLDER', 'NONE', 'SINGLE', 'SINGLE_UNPREDICTABLE' ]) # get_method values GET = 'GET' LSA = 'LSA' NONE = 'NONE' # set_method values MBEAN = 'MBEAN' # attribute wlst_type values BOOLEAN = 'boolean' COMMA_DELIMITED_STRING = 'delimited_string[comma]' CREDENTIAL = 'credential' DELIMITED_STRING = 'delimited_string'
""" Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ from wlsdeploy.util.enum import Enum ExceptionType = Enum([ 'ALIAS', 'CLA', 'CREATE', 'DEPLOY', 'DISCOVER', 'ENCRYPTION', 'JSON', 'PY_WLST', 'TRANSLATE', 'VALIDATE', 'VARIABLE', 'COMPARE', 'WLS_DEPLOY_ARCHIVE_IO', 'YAML' ])
""" Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ from wlsdeploy.util.enum import Enum TargetingType = Enum([ 'APPLY_JRF' ])
""" Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. The WlstModes enum module. """ from wlsdeploy.util.enum import Enum WlstModes = Enum(['OFFLINE', 'ONLINE'])
""" Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. The Universal Permissive License (UPL), Version 1.0 The ValidationCodes enum module """ from wlsdeploy.util.enum import Enum ValidationCodes = Enum(['INVALID', 'VERSION_INVALID', 'VALID'])
class ModelHelpPrinter(object): """ Class for printing the recognized model metadata to STDOUT. """ ControlOptions = Enum( ['NORMAL', 'RECURSIVE', 'FOLDERS_ONLY', 'ATTRIBUTES_ONLY']) def __init__(self, aliases, logger): """ :param aliases: A reference to an Aliases class instance :param logger: A reference to the platform logger to write to, if a log entry needs to be made """ self._logger = logger self._alias_helper = AliasHelper(aliases, self._logger, ExceptionType.CLA) def print_model_help(self, model_path, control_option): """ Prints out the help information for a given '''model_path'''. '''model_path''' needs to be specified using the following pattern: <model_section>[:/<section_folder>[/<section_subfolder>|...]] Examples: 'domainInfo', 'domainInfo:' or 'domainInfo:/' (all 3 are equivalent) 'topology:/Server' 'resources:/JDBCSystemResource/JdbcResource/JDBCDriverParams' 'appDeployments:/Application' :param model_path: a formatted string containing the model path :param control_option: a command-line switch that controls what is output :raises CLAException: if a problem is encountered """ # print filter information, if not NORMAL if control_option == self.ControlOptions.RECURSIVE: print print _format_message('WLSDPLY-10102') elif control_option == self.ControlOptions.FOLDERS_ONLY: print print _format_message('WLSDPLY-10103') elif control_option == self.ControlOptions.ATTRIBUTES_ONLY: print print _format_message('WLSDPLY-10104') model_path_tokens = self._parse_model_path(model_path) section_name = model_path_tokens[0] valid_section_folder_keys = self._alias_helper.get_model_section_top_level_folder_names( section_name) if model_path_tokens[0] == 'top': self._print_model_top_level_help() elif len(model_path_tokens) == 1: self._print_model_section_help(section_name, valid_section_folder_keys, control_option) else: self._print_model_folder_help(model_path_tokens, valid_section_folder_keys, control_option) def _parse_model_path(self, model_path): """ Parse the specified model_path into a Python list of elements. The first element will be the section name. If not specified, the section name will be derived from the first path element. :param model_path: a string contain the model path to parse :return: a python list containing the section name, then each folder element :raises: CLAException if the path cannot be parsed, or the section name is invalid """ _method_name = '_parse_model_path' self._logger.entering(model_path, class_name=_class_name, method_name=_method_name) match = MODEL_PATH_PATTERN.match(model_path) if match is None: ex = exception_helper.create_cla_exception('WLSDPLY-10108', model_path) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex self._logger.finest('match.group(1)={0}, match.group(2)={1}', str(match.group(1)), str(match.group(2)), class_name=_class_name, method_name=_method_name) section = match.group(1) path = match.group(2) folders = [] if path is not None: for folder in path.split('/'): # trailing or duplicate slashes may cause empty folder name if len(folder) > 0: folders.append(folder) if section is None: section = self._get_section_for_folder_list(folders) section = section.replace(':', '') top_level_keys = model.get_model_top_level_keys() # 'top' is a special case for listing the sections all_section_keys = ['top'] all_section_keys.extend(top_level_keys) if section not in all_section_keys: ex = exception_helper.create_cla_exception( 'WLSDPLY-10109', section, str(', '.join(top_level_keys))) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex model_path_tokens = [section] model_path_tokens.extend(folders) return model_path_tokens def _get_section_for_folder_list(self, folder_list): """ Derive the section name from the first folder in the specified list. :param folder_list: the list of folders in the model path :return: the section name :raises: CLAException if the section name cannot be determined """ _method_name = '_get_section_for_folder_list' top_folder = folder_list[0] for section in KNOWN_TOPLEVEL_MODEL_SECTIONS: folder_keys = self._alias_helper.get_model_section_top_level_folder_names( section) if top_folder in folder_keys: return section ex = exception_helper.create_cla_exception('WLSDPLY-10101', top_folder) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex def _print_model_top_level_help(self): """ Prints out all the valid section names for a model. The -recursive flag is disregarded for this case. """ _method_name = '_print_model_top_level_help' self._logger.finest('sections={0}', KNOWN_TOPLEVEL_MODEL_SECTIONS, class_name=_class_name, method_name=_method_name) title = _format_message('WLSDPLY-10113') # Print 'All Sections:' header print _print_indent(title, 0) print for section in KNOWN_TOPLEVEL_MODEL_SECTIONS: _print_indent(section, 1) def _print_model_section_help(self, section_name, valid_section_folder_keys, control_option): """ Prints the help for a section of a model, when just the section_name[:] is provided :param section_name: the name of the model section :param valid_section_folder_keys: list of the valid top folders in the specified section :param control_option: A command-line switch that controls what is output to STDOUT """ _method_name = '_print_model_section_help' self._logger.finest('1 section_name={0}', section_name, class_name=_class_name, method_name=_method_name) location_path = '%s:' % section_name self._logger.finest('1 location_path={0}', location_path, class_name=_class_name, method_name=_method_name) model_section = _format_message('WLSDPLY-10106', location_path) # Print 'Section: <model_section>' label and field print _print_indent(model_section, 0) if self._show_attributes(control_option): attributes_location = self._alias_helper.get_model_section_attribute_location( section_name) if attributes_location is not None: self._print_attributes_help(attributes_location, 1) if self._show_folders(control_option): print _print_indent(_format_message('WLSDPLY-10107'), 1) valid_section_folder_keys.sort() for section_folder_key in valid_section_folder_keys: _print_indent(section_folder_key, 2) if control_option == self.ControlOptions.RECURSIVE: model_location = LocationContext().append_location( section_folder_key) self._print_subfolders_help(model_location, control_option, 2) def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys, control_option): """ Prints the help for a folder in a model, when more than just the section_name[:] is provided. The section name in the first token was already validated. :param model_path_tokens: a Python list of path elements built from model path :param valid_section_folder_keys: A list of valid folder names for the model section in the path :param control_option: A command-line switch that controls what is output to STDOUT """ _method_name = '_print_model_folder_help' self._logger.finest( '1 model_path_tokens={0}, control_option={1}, valid_section_folder_keys={0}', str(model_path_tokens), self.ControlOptions.from_value(control_option), str(valid_section_folder_keys), class_name=_class_name, method_name=_method_name) section_name = model_path_tokens[0] top_folder = model_path_tokens[1] if top_folder not in valid_section_folder_keys: ex = exception_helper.create_cla_exception( 'WLSDPLY-10110', section_name + ':', top_folder, ', '.join(valid_section_folder_keys)) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex folder_path = '/'.join(model_path_tokens[1:]) model_path = _format_message('WLSDPLY-10105', '%s:/%s' % (section_name, folder_path)) # Print 'Path: <model_section>' header print _print_indent(model_path, 0) # Populate the location context using model_path_tokens[1:] model_location = LocationContext() for folder_key in model_path_tokens[1:]: model_location.append_location(folder_key) name_token = self._alias_helper.get_name_token(model_location) if name_token is not None: model_location.add_name_token(name_token, '%s-0' % folder_key) self._logger.finest('2 model_location={0}', model_location, class_name=_class_name, method_name=_method_name) if self._show_attributes(control_option): # Print the attributes associated with location context self._print_attributes_help(model_location, 1) if self._show_folders(control_option): # Print the folders associated with location context print _print_indent(_format_message('WLSDPLY-10107'), 1) self._print_subfolders_help(model_location, control_option, 1) self._logger.exiting(class_name=_class_name, method_name=_method_name) return def _print_subfolders_help(self, model_location, control_option, indent_level): """ Prints the help for the folders in a model location, without header or leading space. :param model_location: the model location being worked on :param control_option: a command-line switch that controls what is output to STDOUT :param indent_level: the level to indent by, before printing output """ _method_name = '_print_subfolders_help' valid_subfolder_keys = self._alias_helper.get_model_subfolder_names( model_location) self._logger.finest( '3 aliases.get_model_subfolder_names(model_location) returned: {0}', str(valid_subfolder_keys), class_name=_class_name, method_name=_method_name) if not valid_subfolder_keys: return valid_subfolder_keys.sort() for key in valid_subfolder_keys: model_location.append_location(key) name_token = self._alias_helper.get_name_token(model_location) if name_token is not None: model_location.add_name_token(name_token, '%s-0' % key) self._logger.finest('3 model_location={0}', model_location, class_name=_class_name, method_name=_method_name) _print_indent(key, indent_level + 1) if control_option == self.ControlOptions.RECURSIVE: # Call this method recursively self._print_subfolders_help(model_location, control_option, indent_level + 1) model_location.pop_location() def _print_attributes_help(self, model_location, indent_level): """ Prints out the help for the attributes in a model location :param model_location: An object containing data about the model location being worked on :param indent_level: The level to indent by, before printing output """ _method_name = '_print_attributes_help' attr_infos = self._alias_helper.get_model_attribute_names_and_types( model_location) self._logger.finer('WLSDPLY-05012', str(model_location), str(attr_infos), class_name=_class_name, method_name=_method_name) if attr_infos: # Print 'Valid Attributes are :-' area label print _print_indent(_format_message('WLSDPLY-10111'), indent_level) maxlen = 0 for key in attr_infos: if len(key) > maxlen: maxlen = len(key) formatted_string = '%-' + str(maxlen) + 's\t%s' attr_list = attr_infos.keys() attr_list.sort() for attr_name in attr_list: msg = formatted_string % (attr_name, attr_infos[attr_name]) _print_indent(msg, indent_level + 1) def _show_attributes(self, control_option): """ Determine if attributes should be displayed, based on the control option. :param control_option: the control option to be checked :return: True if attributes should be displayed, False otherwise """ return control_option in [ self.ControlOptions.NORMAL, self.ControlOptions.ATTRIBUTES_ONLY ] def _show_folders(self, control_option): """ Determine if folders should be displayed, based on the control option. :param control_option: the control option to be checked :return: True if folders should be displayed, False otherwise """ return control_option != self.ControlOptions.ATTRIBUTES_ONLY
class ModelSectionDifferencer(object): """ """ _class_name = 'ModelSectionDifferencer' ItemValueTypes = Enum(['EXPECTED', 'ACTUAL', 'DEFAULT']) def __init__(self, name, logger=None): self.name = name if logger is None: self._logger = _logger else: self._logger = logger self._excludes_dict = PyOrderedDict() ############################################ # # Protected methods exposed to subclasses # ########################################### def _compare_sections(self, section_name, expected_section_dict, actual_section_dict, item_paths, comparison_result): _method_name = '__compare_sections' self._logger.info('WLSDPLY-09917', ModelFileType.EXPECTED, section_name, class_name=self._class_name, method_name=_method_name) function_name = '_handle_expected_item_path' function = getattr(self, function_name) path_tokens, iterators_count = [], 0 iterators = [expected_section_dict.iteritems()] while iterators: current_iterator = iterators.pop() for node_name, node_value in current_iterator: if not isinstance(node_value, dict): item_path = '%s:/%s%s%s' % (section_name, '/'.join(path_tokens), (path_tokens and ['/'] or [''])[0], '@%s' % node_name) self._logger.finer('item_path = {0}: [{1}, None, None]', item_path, node_value, class_name=self._class_name, method_name=_method_name) function(item_path, node_value, item_paths) else: self._logger.finer('node_name={0}', node_name, class_name=self._class_name, method_name=_method_name) diff = cmp(iterators_count, len(iterators)) iterators_count = len(iterators) self._logger.finer('iterators_count={0}', iterators_count, class_name=self._class_name, method_name=_method_name) if diff == -1: # increased path_tokens.append(node_name) elif diff == 1: # deceased path_tokens = path_tokens[0:iterators_count]+[node_name] else: # remained the same if path_tokens: path_tokens.pop() path_tokens.append(node_name) self._logger.finer('path_tokens={0}', str(path_tokens), class_name=self._class_name, method_name=_method_name) iterators.append(current_iterator) iterators.append(node_value.iteritems()) break self._logger.info('WLSDPLY-09917', ModelFileType.ACTUAL, section_name, class_name=self._class_name, method_name=_method_name) function_name = '_handle_actual_item_path' function = getattr(self, function_name) path_tokens, iterators_count = [], 0 iterators = [actual_section_dict.iteritems()] while iterators: current_iterator = iterators.pop() for node_name, node_value in current_iterator: if not isinstance(node_value, dict): item_path = '%s:/%s%s%s' % (section_name, '/'.join(path_tokens), (path_tokens and ['/'] or [''])[0], '@%s' % node_name) function(item_path, node_value, item_paths) else: self._logger.finer('node_name={0}', node_name, class_name=self._class_name, method_name=_method_name) diff = cmp(iterators_count, len(iterators)) iterators_count = len(iterators) self._logger.finer('iterators_count={0}', iterators_count, class_name=self._class_name, method_name=_method_name) if diff == -1: # increased path_tokens.append(node_name) elif diff == 1: # deceased path_tokens = path_tokens[0:iterators_count]+[node_name] else: # remained the same if path_tokens: path_tokens.pop() path_tokens.append(node_name) self._logger.finer('path_tokens={0}', str(path_tokens), class_name=self._class_name, method_name=_method_name) iterators.append(current_iterator) iterators.append(node_value.iteritems()) break return comparison_result def _load_model_section_excludes(self, section_name): """ Reads a JSON file containing information regarding which item paths should be excluded, when comparing a given model section. The JSON representation of the information looks like the following: ... "expected": { "domainInfo:/@AdminUserName": { "node_name": "AdminUserName", "reason": "This is a pseudo model section, so model generated by discover will not contain attributes from it" }, "domainInfo:/@AdminPassword": { "node_name": "AdminPassword", "reason": "This is a pseudo model section, so model generated by discover will not contain attributes from it" }, ... The lookup keys are the item path fields, which are siblings of the item value type node (e.g. "expected", "actual"). If the specified item path is present, then it will be excluded from the item paths for the model, of the item value type node it appears under. For example, if the "domainInfo:/@AdminUserName" item path is in the expected model, then "domainInfo:/@AdminUserName" will be excluded from the item paths collection. The item paths collection is used during the compare and match process. :param section_name: The name of the model section that the excludes applies to :return: A Python dictionary contain excludes information :raises TestingException, if file cannot be translated into a python dictionary """ _method_name = '_load_model_section_excludes' file_path = '%s/%s-excludes.json' % (testing_constants.EXCLUDES_DIR, section_name) j_file = testing_helper.extract_file(file_path, self._logger) self._logger.finer('WLSDPLY-09912', j_file.getAbsolutePath(), section_name, class_name=self._class_name, method_name=_method_name) excludes_dict = testing_helper.translate_file(j_file, self._logger) return excludes_dict
""" Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. The Universal Permissive License (UPL), Version 1.0 """ from wlsdeploy.util.enum import Enum ExceptionType = Enum([ 'INTEGRATION_TEST', 'SYSTEM_TEST', 'TESTING', 'TEST_DEF', 'VERIFICATION', 'COMPARE_MODELS' ])