Пример #1
0
def _load_variable_file(variable_file_location, **kwargs):
    _method_name = '_load_variable_file'
    append = False
    variable_dictionary = dict()
    if VARIABLE_FILE_APPEND_ARG in kwargs and kwargs[
            VARIABLE_FILE_APPEND_ARG] in VARIABLE_FILE_APPEND_VALS:
        if kwargs[VARIABLE_FILE_APPEND_ARG] == VARIABLE_FILE_APPEND:
            _logger.fine('WLSDPLY-19536',
                         variable_file_location,
                         class_name=_class_name,
                         method_name=_method_name)
            append = True
        elif kwargs[
                VARIABLE_FILE_APPEND_ARG] == VARIABLE_FILE_UPDATE and os.path.isfile(
                    variable_file_location):
            _logger.fine('WLSDPLY-19534',
                         variable_file_location,
                         class_name=_class_name,
                         method_name=_method_name)
            try:
                variable_dictionary = variables.load_variables(
                    variable_file_location)
            except VariableException, ve:
                _logger.warning('WLSDPLY-19537',
                                variable_file_location,
                                ve.getLocalizedMessage(),
                                class_name=_class_name,
                                method_name=_method_name)
        else:
            _logger.fine('WLSDPLY-19535',
                         variable_file_location,
                         class_name=_class_name,
                         method_name=_method_name)
def load_model(program_name, model_context, aliases, filter_type, wlst_mode):
    """
    Load the model based on the arguments in the model context.
    Apply the variable substitution, if specified, and validate the model.
    Apply any model filters of the specified type that are configured, and re-validate if necessary
    The tool will exit if exceptions are encountered.
    :param program_name: the program name, for logging
    :param model_context: the model context
    :param aliases: the alias configuration
    :param filter_type: the type of any filters to be applied
    :param wlst_mode: offline or online
    :return: the resulting model dictionary
    """
    _method_name = 'load_model'

    variable_map = {}
    try:
        if model_context.get_variable_file():
            # callers of this method allow multiple variable files
            variable_map = variables.load_variables(
                model_context.get_variable_file(), allow_multiple_files=True)
    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)
 def testWithVariableHelperKeywords(self):
     expected = dict()
     short_name = self._helper.get_folder_short_name(
         LocationContext().append_location('JMSSystemResource'))
     expected[short_name + '.MyJmsModule.MyForeignServer.ConnectionURL'] \
         = 't3://my.other.cluster:7001'
     short_name = self._helper.get_folder_short_name(
         LocationContext().append_location('Server'))
     expected[short_name + '.AdminServer.ListenPort'] = '9001'
     expected[short_name + '.m2.ListenPort'] = '9005'
     expected[short_name + '.m1.ListenPort'] = '9003'
     short_name = self._helper.get_folder_short_name(
         LocationContext().append_location('Machine'))
     expected[short_name + '.machine1.ListenPort'] = '5557'
     expected[short_name + '.machine1.PasswordEncrypted'] = '--FIX ME--'
     expected[short_name + '.machine1.UserName'] = '******'
     inserted, model, variable_file_name = self._helper.inject_variables_keyword_file(
         variable_file_name=self._variable_file,
         variable_injector_path_name=self._resources_dir,
         variable_injector_file_name=self._variable_injector_keyword,
         variable_keywords_path_name=self._resources_dir,
         variable_keywords_file_name=self._keywords_file)
     self.assertEqual(self._variable_file, variable_file_name)
     self.assertEqual(True, inserted)
     actual = variables.load_variables(self._variable_file)
     self._compare_to_expected_dictionary(expected, actual)
 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'])
Пример #5
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 testMultipleModelsIndirectEncryptionVariables(self):
        copy2(self._src_model_file_w_variables, self._target_model_test2)
        copy2(self._src_model_file_w_variables_multi, self._target_model_test3)
        copy2(self._src_variable_file, self._target_variables_test3)

        args = list()
        args.append(
            'encrypt')  # dummy arg for args[0] to get arg padding right
        args.append(CommandLineArgUtil.ORACLE_HOME_SWITCH)
        args.append(self._oracle_home)
        args.append(CommandLineArgUtil.MODEL_FILE_SWITCH)
        args.append(self._target_model_test2 + ',' + self._target_model_test3)
        args.append(CommandLineArgUtil.VARIABLE_FILE_SWITCH)
        args.append(self._target_variables_test3)
        args.append(CommandLineArgUtil.PASSPHRASE_SWITCH)
        args.append(self._passphrase)
        exit_code = encrypt._process_request(args)
        self.assertEquals(exit_code, 0)

        model2 = FileToPython(self._target_model_test2).parse()
        model3 = FileToPython(self._target_model_test3).parse()
        variables = variables_helper.load_variables(
            self._target_variables_test3)
        passphrase_array = String(self._passphrase).toCharArray()

        admin_pass = model2['domainInfo']['AdminPassword']
        self.assertNotEquals(admin_pass.startswith('{AES}'), True)
        admin_pass = model3['domainInfo']['AdminPassword']
        self.assertNotEquals(admin_pass.startswith('{AES}'), True)
        admin_pass = variables['admin.password']
        self.assertEquals(admin_pass.startswith('{AES}'), True)
        _decrypted_admin_pass = EncryptionUtils.decryptString(
            admin_pass, passphrase_array)
        self.assertEquals(str(String(_decrypted_admin_pass)),
                          self._unencrypted_password)

        nm_pass = model2['topology']['SecurityConfiguration'][
            'NodeManagerPasswordEncrypted']
        self.assertNotEquals(nm_pass.startswith('{AES}'), True)
        nm_pass = variables['nm.password']
        self.assertEquals(nm_pass.startswith('{AES}'), True)
        _decrypted_nm_pass = EncryptionUtils.decryptString(
            nm_pass, passphrase_array)
        self.assertEquals(str(String(_decrypted_nm_pass)),
                          self._unencrypted_password)

        ds1_pass = model2['resources']['JDBCSystemResource']['Generic1'][
            'JdbcResource']['JDBCDriverParams']['PasswordEncrypted']
        self.assertEquals(ds1_pass.startswith('{AES}'), True)
        _decrypted_ds1_pass = EncryptionUtils.decryptString(
            ds1_pass, passphrase_array)
        self.assertEquals(str(String(_decrypted_ds1_pass)),
                          self._unencrypted_password)

        return
Пример #7
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')
Пример #9
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
    def testMultipleModelsDirectAndVariables(self):
        copy2(self._src_model_file_w_variables, self._target_model_test1)
        copy2(self._src_model_file_wo_variables_for_multi,
              self._target_model_test2)
        copy2(self._src_variable_file, self._target_variables_test3)

        args = list()
        args.append(
            'encrypt')  # dummy arg for args[0] to get arg padding right
        args.append(CommandLineArgUtil.ORACLE_HOME_SWITCH)
        args.append(self._oracle_home)
        args.append(CommandLineArgUtil.MODEL_FILE_SWITCH)
        args.append(self._target_model_test1 + ',' + self._target_model_test2)
        args.append(CommandLineArgUtil.VARIABLE_FILE_SWITCH)
        args.append(self._target_variables_test3)
        args.append(CommandLineArgUtil.PASSPHRASE_SWITCH)
        args.append(self._passphrase)
        exit_code = encrypt._process_request(args)
        self.assertEquals(exit_code, 0)

        model2 = FileToPython(self._target_model_test1).parse()
        model3 = FileToPython(self._target_model_test2).parse()
        variables = variables_helper.load_variables(
            self._target_variables_test3)
        passphrase_array = String(self._passphrase).toCharArray()

        admin_pass = model2['domainInfo']['AdminPassword']
        self.assertNotEquals(admin_pass.startswith('{AES}'), True)
        admin_pass = variables['admin.password']
        self.assertEquals(admin_pass.startswith('{AES}'), True)
        _decrypted_admin_pass = EncryptionUtils.decryptString(
            admin_pass, passphrase_array)
        self.assertEquals(str(String(_decrypted_admin_pass)),
                          self._unencrypted_password)
        admin_pass = model3['domainInfo']['AdminPassword']
        self.assertEquals(admin_pass.startswith('{AES}'), True)
        _decrypted_admin_pass = EncryptionUtils.decryptString(
            admin_pass, passphrase_array)
        self.assertEquals(str(String(_decrypted_admin_pass)),
                          self._unencrypted_password_second)

        return
Пример #11
0
 def testWithVariableHelperKeywords(self):
     expected = dict()
     expected['JMSSystemResource.MyJmsModule.JmsResource.ForeignServer.MyForeignServer.ConnectionURL'] \
         = 't3://my.other.cluster:7001'
     expected['Server.AdminServer.ListenPort'] = '9001'
     expected['Server.m2.ListenPort'] = '9005'
     expected['Server.m1.ListenPort'] = '9003'
     expected['Machine.machine1.NodeManager.ListenPort'] = '5557'
     expected[
         'Machine.machine1.NodeManager.PasswordEncrypted'] = '--FIX ME--'
     expected['Machine.machine1.NodeManager.UserName'] = '******'
     inserted, model, variable_file_name = self._helper.inject_variables_keyword_file(
         variable_file_name=self._variable_file,
         variable_injector_path_name=self._resources_dir,
         variable_injector_file_name=self._variable_injector_keyword,
         variable_keywords_path_name=self._resources_dir,
         variable_keywords_file_name=self._keywords_file)
     self.assertEqual(self._variable_file, variable_file_name)
     self.assertEqual(True, inserted)
     actual = variables.load_variables(self._variable_file)
     self._compare_to_expected_dictionary(expected, actual)
Пример #12
0
def _load_variable_file(variable_file_location, append_option):
    """
    Load the variable dictionary from the file, and determine if append or update.
    :param variable_file_location: the location of the variable file
    :param append_option: 'append', 'update', or None
    :return: tuple with append True or False, and the existing variable dictionary
    """
    _method_name = '_load_variable_file'
    append = False
    variable_dictionary = OrderedDict()
    if append_option in VARIABLE_FILE_APPEND_VALS:
        if append_option == VARIABLE_FILE_APPEND:
            _logger.fine('WLSDPLY-19536',
                         variable_file_location,
                         class_name=_class_name,
                         method_name=_method_name)
            append = True
        elif append_option == VARIABLE_FILE_UPDATE and os.path.isfile(
                variable_file_location):
            _logger.fine('WLSDPLY-19534',
                         variable_file_location,
                         class_name=_class_name,
                         method_name=_method_name)
            try:
                variable_dictionary = variables.load_variables(
                    variable_file_location)
            except VariableException, ve:
                _logger.warning('WLSDPLY-19537',
                                variable_file_location,
                                ve.getLocalizedMessage(),
                                class_name=_class_name,
                                method_name=_method_name)
        else:
            _logger.fine('WLSDPLY-19535',
                         variable_file_location,
                         class_name=_class_name,
                         method_name=_method_name)
Пример #13
0
            __logger.severe('WLSDPLY-20008',
                            _program_name,
                            ex.getLocalizedMessage(),
                            error=ex,
                            class_name=_class_name,
                            method_name=_method_name)
        cla_helper.clean_up_temp_files()

        # create a minimal model for summary logging
        model_context = model_context_helper.create_exit_context(_program_name)
        tool_exit.end(model_context, exit_code)

    variable_map = {}
    try:
        if model_context.get_variable_file():
            variable_map = variables.load_variables(
                model_context.get_variable_file())
    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)

    model_file_value = model_context.get_model_file()
    try:
        model_dictionary = cla_helper.merge_model_files(
            model_file_value, variable_map)
    except TranslateException, te:
Пример #14
0
        model = FileToPython(model_file, True).parse()
    except TranslateException, te:
        __logger.severe('WLSDPLY-04206',
                        _program_name,
                        model_file,
                        te.getLocalizedMessage(),
                        error=te,
                        class_name=_class_name,
                        method_name=_method_name)
        return CommandLineArgUtil.PROG_ERROR_EXIT_CODE

    variable_file = model_context.get_variable_file()
    variables = None
    if variable_file is not None:
        try:
            variables = variable_helper.load_variables(variable_file)
        except VariableException, ve:
            __logger.severe('WLSDPLY-04207',
                            _program_name,
                            variable_file,
                            ve.getLocalizedMessage(),
                            error=ve,
                            class_name=_class_name,
                            method_name=_method_name)
            return CommandLineArgUtil.PROG_ERROR_EXIT_CODE

    try:
        passphrase = model_context.get_encryption_passphrase()
        model_change_count, variable_change_count = \
            encryption_utils.encrypt_model_dictionary(passphrase, model, variables)
    except EncryptionException, ee:
 def testReadVariables(self):
     variable_map = variables.load_variables(self._variables_file)
     self.assertEqual(variable_map['my-abc'], 'xyz')