def __perform_model_file_validation(model_file_name, model_context):
    """

    :param model_file_name:
    :param model_context:
    :return:
    :raises ValidationException:
    """

    _method_name = '__perform_model_file_validation'

    __logger.entering(model_file_name,
                      class_name=_class_name, method_name=_method_name)

    try:
        model_validator = Validator(model_context, logger=__logger)
        variable_map = model_validator.load_variables(model_context.get_variable_file())
        model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map)

        if cla_helper.check_persist_model():
            persist_model_dict = copy.deepcopy(model_dictionary)
            variables.substitute(persist_model_dict, variable_map, model_context)
            cla_helper.persist_model(model_context, persist_model_dict)

        model_validator.validate_in_standalone_mode(model_dictionary, variable_map,
                                                    model_context.get_archive_file_name())
    except (TranslateException, VariableException), te:
        __logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(),
                        error=te, class_name=_class_name, method_name=_method_name)
        ex = exception_helper.create_validate_exception(te.getLocalizedMessage(), error=te)
        __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
 def testSecretTokenNotFound(self):
     try:
         model = {'domainInfo': {'AdminUserName': '******'}}
         variables.substitute(model, {}, self.model_context)
     except VariableException:
         pass
     else:
         self.fail('Test must raise VariableException when secret token is not found')
 def testEnvironmentVariableNotFound(self):
     try:
         model = {'domainInfo': {'AdminUserName': '******'}}
         variables.substitute(model, {}, self.model_context)
     except VariableException:
         pass
     else:
         self.fail('Test must raise VariableException when variable file is not found')
 def testSubstituteJson(self):
     model = FileToPython(self._resources_dir + '/variables-test.json', self._use_ordering).parse()
     variable_map = variables.load_variables(self._variables_file)
     variables.substitute(model, variable_map, self.model_context)
     self.assertEqual(model['topology']['Name'], 'xyz123')
     self.assertEqual(model['topology']['Server']['s1']['ListenPort'], '1009')
     self.assertEqual(model['topology']['Server']['s2']['Cluster'], 'myCluster')
     self.assertEqual(True, 'myCluster' in model['topology']['Cluster'])
     self.assertEqual(True, 's3' in model['topology']['Server'])
 def _test_token_syntax_error(self, value):
     """
     Test that an exception is thrown for a token syntax error in the specified value.
     :param value: the text value to be checked
     """
     try:
         model = {'domainInfo': {'AdminUserName': value}}
         variables.substitute(model, {}, self.model_context)
     except VariableException, e:
         pass
 def testFileVariableWithConstant(self):
     model = {
         'domainInfo': {
             'AdminUserName':
             '******' + self._file_variable_name + '@@'
         }
     }
     variables.substitute(model, {}, self.model_context)
     self.assertEqual(model['domainInfo']['AdminUserName'],
                      'file-variable-value')
 def testFileVariableNotFound(self):
     try:
         path = self._resources_dir + '/no-file.txt'
         model = {'domainInfo': {'AdminUserName': '******' + path + '@@'}}
         variables.substitute(model, {}, self.model_context)
         self.assertEqual(model['domainInfo']['AdminUserName'], 'file-variable-value')
     except VariableException:
         pass
     else:
         self.fail('Test must raise VariableException when variable file is not found')
Exemple #8
0
 def testVariableNotFound(self):
     """
     For ${key} substitution, no replacement is done, and no error is reported, if variable not found.
     ${key} substitution is deprecated.
     """
     model = FileToPython(self._resources_dir + '/variables-test.json', self._use_ordering).parse()
     model['topology']['Name'] = '${bad.variable}'
     variable_map = variables.load_variables(self._variables_file)
     variables.substitute(model, variable_map)
     self.assertEqual(model['topology']['Name'], '${bad.variable}')
 def testFileVariableWithVariable(self):
     model = {
         'domainInfo': {
             'AdminUserName':
             '******' + self._file_variable_name + '@@'
         }
     }
     variables.substitute(model, {'variable_dir': self._resources_dir},
                          self.model_context)
     self.assertEqual(model['domainInfo']['AdminUserName'],
                      'file-variable-value')
 def testFileVariableWithEnvironmentVariable(self):
     os.environ['variableDir'] = self._resources_dir
     model = {
         'domainInfo': {
             'AdminUserName':
             '******' + self._file_variable_name + '@@'
         }
     }
     variables.substitute(model, {}, self.model_context)
     self.assertEqual(model['domainInfo']['AdminUserName'],
                      'file-variable-value')
 def testSecretToken(self):
     """
     Verify that the WDT_MODEL_SECRETS_DIRS variable can be used to find a secret.
     Put two paths in the variable, the second is .../resources/secrets.
     It should find the file .../resources/secrets/my-secrets/secret2, containing "mySecret2".
     """
     os.environ['WDT_MODEL_SECRETS_DIRS'] = "/noDir/noSubdir," + self._resources_dir + "/secrets"
     model = {'domainInfo': {'AdminUserName': '******'}}
     variables._clear_secret_token_map()
     variables.substitute(model, {}, self.model_context)
     self.assertEqual(model['domainInfo']['AdminUserName'], 'mySecret2')
 def testSecretTokenPairs(self):
     """
     Verify that the WDT_MODEL_SECRETS_NAME_DIR_PAIRS variable can be used to find a secret.
     Put two path assignments in the variable, the second is dirY=.../resources/secrets.
     It should find the file .../resources/secrets/secret1, containing "mySecret1".
     """
     os.environ['WDT_MODEL_SECRETS_NAME_DIR_PAIRS'] = "dirX=/noDir,dirY=" + self._resources_dir + "/secrets"
     model = {'domainInfo': {'AdminUserName': '******'}}
     variables._clear_secret_token_map()
     variables.substitute(model, {}, self.model_context)
     self.assertEqual(model['domainInfo']['AdminUserName'], 'mySecret1')
Exemple #13
0
def _apply_overrides_file(overrides_file_name, test_def_dict, logger):
    _method_name = '_apply_overrides_file'

    try:
        variable_map = variables.load_variables(overrides_file_name)
        variables.substitute(test_def_dict, variable_map)
    except VariableException, ve:
        ex = exception_helper.create_testing_exception('WLSDPLY-09814',
                                                       overrides_file_name,
                                                       ve.getLocalizedMessage(), error=ve)
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
 def testPropertyNotFound(self):
     """
     For @@PROP:key@@ substitution, an exception is thrown if variable not found.
     """
     try:
         model = FileToPython(self._resources_dir + '/variables-test.json', self._use_ordering).parse()
         model['topology']['Name'] = '@@PROP:bad.variable@@'
         variable_map = variables.load_variables(self._variables_file)
         variables.substitute(model, variable_map, self.model_context)
     except VariableException:
         pass
     else:
         self.fail('Test must raise VariableException when variable is not found')
Exemple #15
0
def apply_substitution_variables_file(variable_file, model_dict, logger):
    _method_name = 'apply_substitution_variables_file'

    if variable_file is None:
        return

    try:
        variable_map = variables.load_variables(variable_file)
        variables.substitute(model_dict, variable_map)
    except VariableException, ve:
        ex = exception_helper.create_testing_exception('WLSDPLY-09814',
                                                       variable_file,
                                                       ve.getLocalizedMessage(), error=ve)
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
Exemple #16
0
        __logger.severe('WLSDPLY-20009',
                        _program_name,
                        model_file,
                        te.getLocalizedMessage(),
                        error=te,
                        class_name=_class_name,
                        method_name=_method_name)
        __clean_up_temp_files()
        tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)

    try:
        variable_map = {}
        if model_context.get_variable_file():
            variable_map = variables.load_variables(
                model_context.get_variable_file())
        variables.substitute(model, variable_map, model_context)
    except VariableException, ex:
        __logger.severe('WLSDPLY-20004',
                        _program_name,
                        ex.getLocalizedMessage(),
                        error=ex,
                        class_name=_class_name,
                        method_name=_method_name)
        __clean_up_temp_files()
        tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)

    aliases = Aliases(model_context, wlst_mode=__wlst_mode)
    alias_helper = AliasHelper(aliases, __logger, ExceptionType.CREATE)
    validate_model(model, model_context, aliases)

    if filter_helper.apply_filters(model, "create"):
Exemple #17
0
    def compare(self):
        """
        Do the actual compare of the models.
        :return:  whether the difference is safe for online dynamic update
        """

        _method_name = "compare"
        # arguments have been verified and same extensions

        model_file_name = None

        # validate models first

        try:
            if os.path.splitext(self.current_dict_file)[1].lower() == ".yaml":
                model_file_name = self.current_dict_file
                FileToPython(model_file_name, True).parse()
                model_file_name = self.past_dict_file
                FileToPython(model_file_name, True).parse()

            aliases = Aliases(model_context=self.model_context,
                              wlst_mode=WlstModes.OFFLINE)

            validator = Validator(self.model_context,
                                  aliases,
                                  wlst_mode=WlstModes.OFFLINE)

            variable_map = validator.load_variables(
                self.model_context.get_variable_file())
            model_file_name = self.current_dict_file

            model_dictionary = cla_helper.merge_model_files(
                model_file_name, variable_map)

            variables.substitute(model_dictionary, variable_map,
                                 self.model_context)

            return_code = validator.validate_in_tool_mode(
                model_dictionary,
                variables_file_name=None,
                archive_file_name=None)

            if return_code == Validator.ReturnCode.STOP:
                __logger.severe('WLSDPLY-05705', model_file_name)
                return VALIDATION_FAIL

            current_dict = model_dictionary
            model_file_name = self.past_dict_file

            model_dictionary = cla_helper.merge_model_files(
                model_file_name, variable_map)
            variables.substitute(model_dictionary, variable_map,
                                 self.model_context)

            return_code = validator.validate_in_tool_mode(
                model_dictionary,
                variables_file_name=None,
                archive_file_name=None)

            if return_code == Validator.ReturnCode.STOP:
                __logger.severe('WLSDPLY-05705', model_file_name)
                return VALIDATION_FAIL
            past_dict = model_dictionary
        except ValidateException, te:
            __logger.severe('WLSDPLY-20009',
                            _program_name,
                            model_file_name,
                            te.getLocalizedMessage(),
                            error=te,
                            class_name=_class_name,
                            method_name=_method_name)
            ex = exception_helper.create_compare_exception(
                te.getLocalizedMessage(), error=te)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            return VALIDATION_FAIL
 def testEnvironmentVariable(self):
     os.environ['envVariable'] = 'the-admin-user'
     model = {'domainInfo': {'AdminUserName': '******'}}
     variables.substitute(model, {}, self.model_context)
     self.assertEqual(model['domainInfo']['AdminUserName'], 'the-admin-user')
Exemple #19
0
        __logger.severe('WLSDPLY-09014',
                        _program_name,
                        model_file,
                        te.getLocalizedMessage(),
                        error=te,
                        class_name=_class_name,
                        method_name=_method_name)
        __clean_up_temp_files()
        tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)

    try:
        variable_map = {}
        if model_context.get_variable_file():
            variable_map = variables.load_variables(
                model_context.get_variable_file())
        variables.substitute(model_dictionary, variable_map)
    except VariableException, ex:
        __logger.severe('WLSDPLY-20004',
                        _program_name,
                        ex.getLocalizedMessage(),
                        error=ex,
                        class_name=_class_name,
                        method_name=_method_name)
        __clean_up_temp_files()
        tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)

    aliases = Aliases(model_context, wlst_mode=__wlst_mode)
    validate_model(model_dictionary, model_context, aliases)

    if filter_helper.apply_filters(model_dictionary, "update"):
        # if any filters were applied, re-validate the model
 def testFileVariable(self):
     path = self._resources_dir + '/' + self._file_variable_name
     model = {'domainInfo': {'AdminUserName': '******' + path + '@@'}}
     variables.substitute(model, {}, self.model_context)
     self.assertEqual(model['domainInfo']['AdminUserName'], 'file-variable-value')
Exemple #21
0
    def compare(self):
        """
        Do the actual compare of the models.
        :return:  whether the difference is safe for online dynamic update
        """

        _method_name = "compare"
        # arguments have been verified and same extensions

        model_file_name = None

        # validate models first

        try:
            if FileUtils.isYamlFile(JFile(os.path.splitext(self.current_dict_file)[1].lower())):
                model_file_name = self.current_dict_file
                FileToPython(model_file_name, True).parse()
                model_file_name = self.past_dict_file
                FileToPython(model_file_name, True).parse()

            self.model_context.set_validation_method('lax')

            aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE,
                              exception_type=ExceptionType.COMPARE)

            validator = Validator(self.model_context, aliases, wlst_mode=WlstModes.OFFLINE)

            variable_map = validator.load_variables(self.model_context.get_variable_file())
            model_file_name = self.current_dict_file

            model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map)

            variables.substitute(model_dictionary, variable_map, self.model_context)

            # Run this utility in stand-alone mode instead of tool mode,
            # which has stricter checks for the tools.
            # An archive is not used with the compare models and if the model
            # references a file in an archive, the compareModel will fail if
            # running in the stricter tool mode (even with lax).
            #
            arg_map = dict()
            arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = model_file_name
            model_context_copy = self.model_context.copy(arg_map)
            val_copy = Validator(model_context_copy, aliases, wlst_mode=WlstModes.OFFLINE)

            # any variables should have been substituted at this point
            validate_variables = {}
            return_code = val_copy.validate_in_standalone_mode(model_dictionary, validate_variables,
                                                               archive_file_name=None)

            if return_code == Validator.ReturnCode.STOP:
                _logger.severe('WLSDPLY-05705', model_file_name)
                return VALIDATION_FAIL

            current_dict = model_dictionary
            model_file_name = self.past_dict_file

            model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map)
            variables.substitute(model_dictionary, variable_map, self.model_context)

            arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = model_file_name
            model_context_copy = self.model_context.copy(arg_map)
            val_copy = Validator(model_context_copy, aliases, wlst_mode=WlstModes.OFFLINE)
            return_code = val_copy.validate_in_standalone_mode(model_dictionary, validate_variables,
                                                               archive_file_name=None)

            if return_code == Validator.ReturnCode.STOP:
                _logger.severe('WLSDPLY-05705', model_file_name)
                return VALIDATION_FAIL
            past_dict = model_dictionary
        except ValidateException, te:
            _logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(),
                           error=te, class_name=_class_name, method_name=_method_name)
            ex = exception_helper.create_compare_exception(te.getLocalizedMessage(), error=te)
            _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
            return VALIDATION_FAIL
Exemple #22
0
    try:
        model_dictionary = cla_helper.merge_model_files(
            model_file_value, variable_map)
    except TranslateException, te:
        __logger.severe('WLSDPLY-09014',
                        _program_name,
                        model_file_value,
                        te.getLocalizedMessage(),
                        error=te,
                        class_name=_class_name,
                        method_name=_method_name)
        cla_helper.clean_up_temp_files()
        tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)

    try:
        variables.substitute(model_dictionary, variable_map, model_context)
    except VariableException, ex:
        __logger.severe('WLSDPLY-20004',
                        _program_name,
                        ex.getLocalizedMessage(),
                        error=ex,
                        class_name=_class_name,
                        method_name=_method_name)
        cla_helper.clean_up_temp_files()
        tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)

    aliases = Aliases(model_context, wlst_mode=__wlst_mode)
    validate_model(model_dictionary, model_context, aliases)

    if filter_helper.apply_filters(model_dictionary, "deploy"):
        # if any filters were applied, re-validate the model
Exemple #23
0
        __logger.severe('WLSDPLY-20009',
                        _program_name,
                        model_file,
                        te.getLocalizedMessage(),
                        error=te,
                        class_name=_class_name,
                        method_name=_method_name)
        __clean_up_temp_files()
        tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)

    try:
        variable_map = {}
        if model_context.get_variable_file():
            variable_map = variables.load_variables(
                model_context.get_variable_file())
        variables.substitute(model, variable_map)
    except VariableException, ex:
        __logger.severe('WLSDPLY-20004',
                        _program_name,
                        ex.getLocalizedMessage(),
                        error=ex,
                        class_name=_class_name,
                        method_name=_method_name)
        __clean_up_temp_files()
        tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)

    aliases = Aliases(model_context, wlst_mode=__wlst_mode)
    validate_model(model, model_context, aliases)

    if filter_helper.apply_filters(model, "create"):
        # if any filters were applied, re-validate the model