def testDeleteModelAppDeployments(self):
        _method_name = 'testCompareModelFull'

        _variables_file = self._resources_dir + '/compare_model_model1.10.properties'
        _new_model_file = self._resources_dir + '/compare_model_model5.yaml'
        _old_model_file = self._resources_dir + '/compare_model_model1.yaml'
        _temp_dir = os.path.join(tempfile.gettempdir(), _method_name)

        if os.path.exists(_temp_dir):
            shutil.rmtree(_temp_dir)

        os.mkdir(_temp_dir)

        mw_home = os.environ['MW_HOME']
        args_map = {
            '-oracle_home': mw_home,
            '-variable_file': _variables_file,
            '-output_dir': _temp_dir,
            '-domain_type': 'WLS',
            '-trailing_arguments': [_new_model_file, _old_model_file]
        }

        try:
            model_context = ModelContext('CompareModelTestCase', args_map)
            obj = ModelFileDiffer(_new_model_file, _old_model_file,
                                  model_context, _temp_dir)
            return_code = obj.compare()
            self.assertEqual(return_code, 0)

            yaml_result = _temp_dir + os.sep + 'diffed_model.yaml'
            stdout_result = obj.get_compare_msgs()
            model_dictionary = FileToPython(yaml_result).parse()
            yaml_exists = os.path.exists(yaml_result)

            self.assertEqual(yaml_exists, True)
            self.assertEqual(len(stdout_result), 0)

            self.assertEqual(model_dictionary.has_key('appDeployments'), True)
            self.assertEqual(
                model_dictionary['appDeployments'].has_key('Library'), True)
            self.assertEqual(
                model_dictionary['appDeployments'].has_key('Application'),
                True)
            self.assertEqual(
                model_dictionary['appDeployments']['Application'].has_key(
                    '!myear'), True)
            self.assertEqual(
                model_dictionary['appDeployments']['Library'].has_key(
                    '!jax-rs#[email protected]'), True)
            self.assertEqual(
                model_dictionary['appDeployments']['Library'].has_key(
                    '!jsf#[email protected]'), True)

        except (CompareException, PyWLSTException), te:
            return_code = 2
            self._logger.severe('WLSDPLY-05709',
                                te.getLocalizedMessage(),
                                error=te,
                                class_name=self._program_name,
                                method_name=_method_name)
    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
示例#3
0
    def testJsonToPython(self):
        translator = FileToPython(self._src_json_file, use_ordering=True)
        pythonDict = translator.parse()

        self.assertNotEqual(pythonDict, None)
        self.assertEqual(len(pythonDict), 2)

        quotedValue = pythonDict['foo']
        self.assertEqual(quotedValue, 'this is a "legal" JSON value')

        self.assertEqual('keys "can" have quotes too' in pythonDict, True)
        quotedKeyValue = pythonDict['keys "can" have quotes too']
        self.assertEqual(quotedKeyValue, 123)
示例#4
0
    def testYamlToPython(self):
        translator = FileToPython(self._src_yaml_file, use_ordering=True)
        pythonDict = translator.parse()

        self.assertNotEqual(pythonDict, None)
        self.assertEqual(len(pythonDict), 3)

        quotedValue = pythonDict['foo']
        self.assertEqual(quotedValue, 'test \'legal\' yaml')

        quotedValue = pythonDict['bar']
        self.assertEqual(quotedValue, 'test "legal" yaml')

        quotedValue = pythonDict['baz']
        self.assertEqual(quotedValue, 'test \'legal\' yaml')
示例#5
0
def apply_filters(model, tool_type):
    """
    Apply any filters configured for the specified tool type to the specified model.
    :param model: the model to be filtered
    :param tool_type: the name of the filter tool type
    :return: True if any filter was applied, False otherwise
    :raises: BundleAwareException of the specified type: if an error occurs
    """
    _method_name = 'apply_filters'

    filter_applied = False

    try:
        if os.path.isfile(__filter_file_location):
            filters_dictionary = FileToPython(__filter_file_location).parse()

            if tool_type in filters_dictionary:
                filter_list = filters_dictionary[tool_type]
                for filter in filter_list:
                    filter_applied = _apply_filter(model, filter) or filter_applied
            else:
                __logger.info('WLSDPLY-20016', tool_type, __filter_file_location, class_name=__class_name,
                              method_name=_method_name)
        else:
            __logger.info('WLSDPLY-20017', __filter_file_location, class_name=__class_name, method_name=_method_name)
    except Exception, ex:
        __logger.severe('WLSDPLY-20018', str(ex), error=ex, class_name=__class_name, method_name=_method_name)
示例#6
0
def translate_file(from_file, logger):
    """
    Returns a Python dictionary representation of the from_file argument.

    If from_file is a string, the assumption taken is that it's the name
    of a JSON file. In that case, the verify_file_exists(file_name) method
    will be called on it, first. That method returns a Jython File object,
    which is what this translate_file(from_file) method works with.

    :param from_file: A File
    :param logger: A PlatformLogger instance that will be used for logging
                   any exceptions that are thrown
    :return: A Python dictionary representation of the from_file argument
    :raises: TestingException: if a TranslateException is caught during the translation
    """
    _method_name = 'translate_file'

    try:
        if isinstance(from_file, str):
            from_file = verify_file_exists(from_file, logger)

        from_file_dict = FileToPython(from_file.getAbsolutePath(),
                                      True).parse()
    except TranslateException, te:
        ex = exception_helper.create_testing_exception(
            'WLSDPLY-09807',
            from_file.getAbsolutePath(),
            te.getLocalizedMessage(),
            error=te)
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
示例#7
0
def __compare_models(compare_models_args_map):
    """

    :param compare_models_args_map:
    :return:
    :raises CompareModelsException:
    :raises VerificationException:
    """
    _method_name = '__compare_models'

    expected_model_file = None

    try:
        expected_model_file = compare_models_args_map[
            _EXPECTED_MODEL_FILE_SWITCH]
        expected_model_dict = FileToPython(
            expected_model_file.getAbsolutePath(), True).parse()
    except TranslateException, te:
        __logger.severe('WLSDPLY-20009',
                        _program_name,
                        expected_model_file.getAbsolutePath(),
                        te.getLocalizedMessage(),
                        error=te,
                        class_name=_class_name,
                        method_name=_method_name)
        ex = exception_helper.create_verification_exception(
            te.getLocalizedMessage(), error=te)
        __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
示例#8
0
    def testPythonToYaml(self):
        pythonDict = dict()
        pythonDict['foo'] = 'test \'legal\' yaml'
        pythonDict['bar'] = 'test "legal" yaml'
        pythonDict['baz'] = 'test \'legal\' yaml'
        pythonDict['newline'] = 'test embedded\nnewline yaml'

        translator = PythonToFile(pythonDict)
        translator.write_to_file(self._target_yaml_file)

        translator = FileToPython(self._target_yaml_file, use_ordering=True)
        newPythonDict = translator.parse()

        self.assertEqual('foo' in newPythonDict, True)
        self.assertEqual('bar' in newPythonDict, True)
        self.assertEqual('baz' in newPythonDict, True)
        self.assertEquals('newline' in newPythonDict, True)

        quotedValue = newPythonDict['foo']
        self.assertEqual(quotedValue, 'test \'legal\' yaml')
        quotedValue = newPythonDict['bar']
        self.assertEqual(quotedValue, 'test "legal" yaml')
        quotedValue = newPythonDict['baz']
        self.assertEqual(quotedValue, 'test \'legal\' yaml')
        quotedValue = newPythonDict['newline']
        self.assertEqual(quotedValue, 'test embedded\nnewline yaml')
示例#9
0
    def testFilterInvokedOnModelValidation(self):
        """
        Verify filter was run and changes are persisted to model file
        """

        # Setup model context arguments
        _model_file = self._resources_dir + '/simple-model.yaml'
        _archive_file = self._resources_dir + "/SingleAppDomain.zip"
        _method_name = 'testFilterInvokedOnModelValidation'

        mw_home = os.environ['MW_HOME']

        args_map = {
            '-oracle_home': mw_home,
            '-model_file': _model_file,
            '-archive_file': _archive_file
        }

        model_context = ModelContext('validate', args_map)

        try:
            # Invoke model validation
            __perform_model_file_validation(_model_file, model_context)

            # read persisted model file and convert to python dictionary
            model_dictionary = FileToPython(self._wlsdeply_store_model,
                                            True)._parse_json()
        except ValidateException, ve:
            self._logger.severe('WLSDPLY-20000',
                                self._program_name,
                                ve.getLocalizedMessage(),
                                error=ve,
                                class_name=self._class_name,
                                method_name=_method_name)
    def testModelValidation(self):
        _method_name = 'testModelValidation'

        _model_file = self._resources_dir + '/variablestest.yaml'
        _variable_file = self._resources_dir + '/variablestest.properties'
        _archive_file = self._resources_dir + '/variablestest.zip'

        mw_home = os.environ['MW_HOME']
        args_map = {
            '-oracle_home': mw_home,
            '-model_file': _model_file,
            '-variable_file': _variable_file,
            '-archive_file': _archive_file
        }

        model_context = ModelContext('ValidationTestCase', args_map)

        try:
            model_dictionary = FileToPython(model_context.get_model_file()).parse()
            model_validator = Validator(model_context,
                                        wlst_mode=WlstModes.ONLINE)
            return_code = model_validator.validate_in_tool_mode(model_dictionary,
                                                                model_context.get_variable_file(),
                                                                model_context.get_archive_file_name())
            self._logger.info('The Validator.validate_in_tool_mode() call returned {0}',
                              Validator.ReturnCode.from_value(return_code),
                              class_name=self._class_name, method_name=_method_name)
        except TranslateException, te:
            return_code = Validator.ReturnCode.STOP
            self._logger.severe('WLSDPLY-20009',
                                self._program_name,
                                model_context.get_model_file(),
                                te.getLocalizedMessage(), error=te,
                                class_name=self._class_name, method_name=_method_name)
    def testYamlModelValidation(self):
        """
            Parse and validate a YAML model with '-' list type and attributes with negative values.
        """

        _model_file = self._resources_dir + '/simple-model.yaml'
        _archive_file = self._resources_dir + "/SingleAppDomain.zip"
        _method_name = 'testYamlModelValidation'

        mw_home = os.environ['MW_HOME']
        args_map = {
            '-oracle_home': mw_home,
            '-model_file': _model_file,
            '-archive_file': _archive_file
        }

        model_context = ModelContext('ValidationTestCase', args_map)

        try:
            model_dictionary = FileToPython(model_context.get_model_file()).parse()
            model_validator = Validator(model_context,
                                        wlst_mode=WlstModes.ONLINE)
            return_code = model_validator.validate_in_tool_mode(model_dictionary,
                                                                model_context.get_variable_file(),
                                                                model_context.get_archive_file_name())
            self._logger.info('The Validator.validate_in_tool_mode() call returned {0}',
                              Validator.ReturnCode.from_value(return_code),
                              class_name=self._class_name, method_name=_method_name)
        except TranslateException, te:
            return_code = Validator.ReturnCode.STOP
            self._logger.severe('WLSDPLY-20009',
                                self._program_name,
                                model_context.get_model_file(),
                                te.getLocalizedMessage(), error=te,
                                class_name=self._class_name, method_name=_method_name)
示例#12
0
    def testDirectEncryption(self):
        copy2(self._src_model_file_wo_variables, self._target_model_test1)

        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)
        args.append(CommandLineArgUtil.PASSPHRASE_SWITCH)
        args.append(self._passphrase)
        exit_code = encrypt._process_request(args)
        self.assertEquals(exit_code, 0)

        model = FileToPython(self._target_model_test1).parse()
        passphrase_array = String(self._passphrase).toCharArray()

        admin_pass = model['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)

        nm_pass = model['topology']['SecurityConfiguration'][
            'NodeManagerPasswordEncrypted']
        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 = model['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)

        ons_pass = \
            model['resources']['JDBCSystemResource']['Generic1']['JdbcResource']['JDBCOracleParams']['OnsWalletPasswordEncrypted']
        self.assertEquals(ons_pass.startswith('{AES}'), True)
        _decrypted_ons_pass = EncryptionUtils.decryptString(
            ons_pass, passphrase_array)
        self.assertEquals(str(String(_decrypted_ons_pass)),
                          self._unencrypted_password)

        ds2_pass = model['resources']['JDBCSystemResource']['Generic2'][
            'JdbcResource']['JDBCDriverParams']['PasswordEncrypted']
        self.assertEquals(ds2_pass.startswith('{AES}'), True)
        _decrypted_ds2_pass = EncryptionUtils.decryptString(
            ds2_pass, passphrase_array)
        self.assertEquals(str(String(_decrypted_ds2_pass)),
                          self._unencrypted_password)
        return
 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'])
示例#14
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 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
 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')
def apply_filters(model, tool_type, model_context=None):
    """
    Apply any filters configured for the specified tool type to the specified model.
    :param model: the model to be filtered
    :param tool_type: the name of the filter tool type
    :param model_context: optional, used to find target filters
    :return: True if any filter was applied, False otherwise
    :raises: BundleAwareException of the specified type: if an error occurs
    """
    _method_name = 'apply_filters'
    global __filter_file_location

    __filter_file_location = path_utils.find_config_path('model_filters.json')
    filter_applied = False
    target_configuration = None

    try:
        filters_dictionary = {}

        # if target specified in model context, use the filters from target config
        if model_context:
            target_configuration = model_context.get_target_configuration()

        if target_configuration and 'model_filters' in target_configuration:
            filters_dictionary = target_configuration['model_filters']
            target_path = os.path.join('targets', model_context.get_target())

            # Fix the tokenized path in the filter path
            for filter_list in filters_dictionary:
                for current_filter in filters_dictionary[filter_list]:
                    filter_path = dictionary_utils.get_element(current_filter, 'path')
                    if (filter_path is not None) and filter_path.startswith(TARGET_CONFIG_TOKEN):
                        filter_path = target_path + filter_path.replace(TARGET_CONFIG_TOKEN, '')
                        current_filter['path'] = path_utils.find_config_path(filter_path)

        elif os.path.isfile(__filter_file_location):
            filters_dictionary = FileToPython(__filter_file_location).parse()
        else:
            __logger.info('WLSDPLY-20017', __filter_file_location, class_name=__class_name, method_name=_method_name)

        if tool_type in filters_dictionary:
            filter_list = filters_dictionary[tool_type]
            for filter in filter_list:
                filter_applied = _apply_filter(model, filter) or filter_applied
        else:
            __logger.info('WLSDPLY-20016', tool_type, __filter_file_location, class_name=__class_name,
                          method_name=_method_name)

    except Exception, ex:
        __logger.severe('WLSDPLY-20018', str(ex), error=ex, class_name=__class_name, method_name=_method_name)
示例#18
0
    def testPythonToJson(self):
        pythonDict = dict()
        pythonDict['foo'] = 'this is a "legal" JSON value'
        pythonDict['keys "can" have quotes too'] = 123

        translator = PythonToFile(pythonDict)
        translator.write_to_file(self._target_json_file)

        translator = FileToPython(self._target_json_file)
        newPythonDict = translator.parse()

        self.assertEqual('foo' in newPythonDict, True)
        self.assertEqual('keys "can" have quotes too' in newPythonDict, True)
        self.assertEqual(newPythonDict['foo'], 'this is a "legal" JSON value')
        self.assertEqual(newPythonDict['keys "can" have quotes too'], 123)
def merge_model_files(model_file_value):
    """
    Merge the model files specified by the model file value.
    It may be a single file, or a comma-separated list of files.
    :param model_file_value: the value specified as a command argument
    :return: the merge model dictionary
    """
    merged_model = OrderedDict()
    model_files = cla_utils.get_model_files(model_file_value)

    for model_file in model_files:
        model = FileToPython(model_file, True).parse()
        _merge_dictionaries(merged_model, model)

    return merged_model
def __encrypt_model_and_variables(model_context):
    """
    Encrypt the model and variables file, if provided.
    :param model_context: the model context object containing the processed command-line arguments
    :return: the exit code that should be used to exit the program
    """
    _method_name = '__encrypt_model_and_variables'

    model_files = cla_utils.get_model_files(model_context.get_model_file())
    models = dict()
    for model_file in model_files:
        try:
            models[model_file] = 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
示例#21
0
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'

    print_usage = model_context.get_print_usage()

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

    try:
        model_dictionary = FileToPython(model_file_name.getAbsolutePath(),
                                        True).parse()
        model_validator = Validator(model_context, logger=__logger)
        validation_results = model_validator.validate_in_standalone_mode(
            model_dictionary, model_context.get_variable_file(),
            model_context.get_archive_file_name())
    except TranslateException, te:
        __logger.severe('WLSDPLY-20009',
                        _program_name,
                        model_file_name.getAbsolutePath(),
                        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 testCompareModelFull3(self):
        _method_name = 'testCompareModelFull3'
        # This test for
        # 1. Changing MailSessionProperty
        # 2. Changing ODL HandlerDefaults
        # 3. Changing ODL Handler property
        # 4. Changing ODL Logger attributes

        _variables_file = self._resources_dir + '/compare_model_model1.10.properties'
        _new_model_file = self._resources_dir + '/compare_model_model8.yaml'
        _old_model_file = self._resources_dir + '/compare_model_model7.yaml'
        _temp_dir = os.path.join(tempfile.gettempdir(), _method_name)

        if os.path.exists(_temp_dir):
            shutil.rmtree(_temp_dir)

        os.mkdir(_temp_dir)

        mw_home = os.environ['MW_HOME']
        args_map = {
            '-oracle_home': mw_home,
            '-variable_file': _variables_file,
            '-output_dir': _temp_dir,
            '-domain_type': 'WLS',
            '-trailing_arguments': [_new_model_file, _old_model_file]
        }

        try:
            model_context = ModelContext('CompareModelTestCase', args_map)
            obj = ModelFileDiffer(_new_model_file, _old_model_file,
                                  model_context, _temp_dir)
            return_code = obj.compare()
            self.assertEqual(return_code, 0)

            yaml_result = _temp_dir + os.sep + 'diffed_model.yaml'
            json_result = _temp_dir + os.sep + 'diffed_model.json'
            stdout_result = obj.get_compare_msgs()
            model_dictionary = FileToPython(yaml_result).parse()
            yaml_exists = os.path.exists(yaml_result)
            json_exists = os.path.exists(json_result)

            self.assertEqual(yaml_exists, True)
            self.assertEqual(json_exists, True)
            self.assertEqual(len(stdout_result), 0)

            self.assertEqual(model_dictionary.has_key('resources'), True)
            self.assertEqual(
                model_dictionary['resources'].has_key('MailSession'), True)
            self.assertEqual(
                model_dictionary['resources']['MailSession'].has_key(
                    'MyMailSession'), True)

            mail_session = model_dictionary['resources']['MailSession'][
                'MyMailSession']
            self.assertEqual(mail_session.has_key('Properties'), True)
            self.assertEqual(
                mail_session['Properties'].has_key('mail.imap.port'), True)
            self.assertEqual(mail_session['Properties']['mail.imap.port'], 993)

            self.assertEqual(
                model_dictionary['resources'].has_key('ODLConfiguration'),
                True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration'].has_key(
                    'config'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']
                ['config'].has_key('HandlerDefaults'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['HandlerDefaults'].has_key('maxFileSize'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['HandlerDefaults']['maxFileSize'], 14857620)

            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']
                ['config'].has_key('Handler'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['Handler'].has_key('odl-handler'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['Handler']['odl-handler'].has_key('Properties'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['Handler']['odl-handler']['Properties'].has_key(
                    'maxFileSize'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['Handler']['odl-handler']['Properties']['maxFileSize'],
                14857620)

            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']
                ['config'].has_key('Logger'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['Logger'].has_key(
                    'oracle.communications.ordermanagement.automation.plugin.AutomationPluginManager'
                ), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['Logger']
                ['oracle.communications.ordermanagement.automation.plugin.AutomationPluginManager']
                .has_key('Level'), True)
            self.assertEqual(
                model_dictionary['resources']['ODLConfiguration']['config']
                ['Logger']
                ['oracle.communications.ordermanagement.automation.plugin.AutomationPluginManager']
                ['Level'], 'TRACE:16')
            self.assertEqual(
                len(model_dictionary['resources']['ODLConfiguration']
                    ['config']), 3)

            self.assertEqual(
                len(model_dictionary['resources']['ODLConfiguration']['config']
                    ['Logger']), 1)

            self.assertEqual(
                len(model_dictionary['resources']['ODLConfiguration']['config']
                    ['HandlerDefaults']), 1)

        except (CompareException, PyWLSTException), te:
            return_code = 2
            self._logger.severe('WLSDPLY-05709',
                                te.getLocalizedMessage(),
                                error=te,
                                class_name=self._program_name,
                                method_name=_method_name)
示例#23
0
 def setUp(self):
     self.name = VariableFileHelperTest
     self._model = FileToPython(self._model_file).parse()
     self._helper = VariableInjector(self.name, self._model, None,
                                     '12.2.1.3')
示例#24
0
    def walk(self):
        """
        Replace password attributes in each model file with secret tokens, and write each model.
        Generate a script to create the required secrets.
        Create any additional output specified for the target environment.
        """
        _method_name = "walk"

        model_file_name = None

        try:
            model_file_list = self.model_files.split(',')
            for model_file in model_file_list:
                self.cache.clear()
                if os.path.splitext(model_file)[1].lower() == ".yaml":
                    model_file_name = model_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)

                # Just merge and validate but without substitution
                model_dictionary = cla_helper.merge_model_files(
                    model_file_name, None)

                variable_file = self.model_context.get_variable_file()
                if not os.path.exists(variable_file):
                    variable_file = None

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

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

                self.current_dict = model_dictionary

                self.__walk_model_section(
                    model.get_model_domain_info_key(), self.current_dict,
                    aliases.get_model_section_top_level_folder_names(
                        DOMAIN_INFO))

                self.__walk_model_section(
                    model.get_model_topology_key(), self.current_dict,
                    aliases.get_model_topology_top_level_folder_names())

                self.__walk_model_section(
                    model.get_model_resources_key(), self.current_dict,
                    aliases.get_model_resources_top_level_folder_names())

                self.current_dict = self._apply_filter_and_inject_variable(
                    self.current_dict, self.model_context, validator)

                file_name = os.path.join(self.output_dir,
                                         os.path.basename(model_file_name))
                fos = JFileOutputStream(file_name, False)
                writer = JPrintWriter(fos, True)
                pty = PythonToYaml(self.current_dict)
                pty._write_dictionary_to_yaml_file(self.current_dict, writer)
                writer.close()

            self.cache.clear()
            for key in self.secrets_to_generate:
                self.cache[key] = ''

            # use a merged, substituted, filtered model to get domain name and create additional target output.
            full_model_dictionary = cla_helper.load_model(
                _program_name, self.model_context, self._aliases, "discover",
                WlstModes.OFFLINE)

            target_configuration_helper.generate_k8s_script(
                self.model_context, self.cache, full_model_dictionary)

            # create any additional outputs from full model dictionary
            target_configuration_helper.create_additional_output(
                Model(full_model_dictionary), self.model_context,
                self._aliases, ExceptionType.VALIDATE)

        except ValidateException, te:
            self._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)
            self._logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
            return VALIDATION_FAIL
示例#25
0
        if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
            __logger.severe('WLSDPLY-20008',
                            _program_name,
                            ex.getLocalizedMessage(),
                            error=ex,
                            class_name=_class_name,
                            method_name=_method_name)
        __clean_up_temp_files()

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

    model_file = model_context.get_model_file()
    try:
        model_dictionary = FileToPython(model_file, True).parse()
    except TranslateException, te:
        __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(
示例#26
0
        model_context = __process_args(args)
    except CLAException, ex:
        exit_code = ex.getExitCode()
        if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
            __logger.severe('WLSDPLY-20008',
                            _program_name,
                            ex.getLocalizedMessage(),
                            error=ex,
                            class_name=_class_name,
                            method_name=_method_name)
        __clean_up_temp_files()
        tool_exit.end(None, exit_code)

    model_file = model_context.get_model_file()
    try:
        model = FileToPython(model_file, True).parse()
    except TranslateException, te:
        __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(
示例#27
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 testCompareModel4(self):
        _method_name = 'testCompareModel4'

        _models_dir = self._resources_dir + '/compare'
        _new_model_file = _models_dir + '/model-4-new.yaml'
        _old_model_file = _models_dir + '/model-4-old.yaml'

        _output_dir = os.path.join(self._results_dir, 'model-4')
        if not os.path.isdir(_output_dir):
            os.mkdir(_output_dir)

        args_map = {
            '-oracle_home': '/oracle',
            '-output_dir': _output_dir,
            '-trailing_arguments': [_new_model_file, _old_model_file]
        }

        try:
            model_context = ModelContext('CompareModelTestCase', args_map)
            differ = ModelFileDiffer(_new_model_file, _old_model_file,
                                     model_context, _output_dir)
            return_code = differ.compare()
            self.assertEqual(return_code, 0)

            yaml_result = _output_dir + os.sep + 'diffed_model.yaml'
            self.assertEqual(os.path.exists(yaml_result), True,
                             "YAML result should exist: " + yaml_result)

            json_result = _output_dir + os.sep + 'diffed_model.json'
            self.assertEqual(os.path.exists(json_result), True,
                             "JSON result should exist: " + json_result)

            # see comments in the model for erased attributes
            messages = differ.get_compare_msgs()
            self.assertEqual(len(messages), 2)

            model_root = FileToPython(yaml_result).parse()

            # topology section not present, since no Server differences
            topology = dictionary_utils.get_element(model_root, TOPOLOGY)
            self.assertEqual(topology, None, "topology should not be present")

            resources = dictionary_utils.get_dictionary_element(
                model_root, RESOURCES)

            # the SelfTuning should contain delete keys for nested, named folders
            self_tuning = dictionary_utils.get_dictionary_element(
                resources, SELF_TUNING)

            work_manager = dictionary_utils.get_dictionary_element(
                self_tuning, WORK_MANAGER)
            delete_name = model_helper.get_delete_name('newWM')
            self.assertEqual(delete_name in work_manager, True,
                             WORK_MANAGER + ' should contain ' + delete_name)

            min_constraint = dictionary_utils.get_dictionary_element(
                self_tuning, MIN_THREADS_CONSTRAINT)
            delete_name = model_helper.get_delete_name('SampleMinThreads')
            self.assertEqual(
                delete_name in min_constraint, True,
                MIN_THREADS_CONSTRAINT + ' should contain ' + delete_name)

            max_constraint = dictionary_utils.get_dictionary_element(
                self_tuning, MAX_THREADS_CONSTRAINT)
            delete_name = model_helper.get_delete_name('SampleMaxThreads')
            self.assertEqual(
                delete_name in max_constraint, True,
                MAX_THREADS_CONSTRAINT + ' should contain ' + delete_name)

            deployments = dictionary_utils.get_dictionary_element(
                model_root, APP_DEPLOYMENTS)

            libraries = dictionary_utils.get_dictionary_element(
                deployments, LIBRARY)
            # mylib should not appear in change model, it had no changes
            self.assertEqual(len(libraries), 1,
                             "only one entry should be present in " + LIBRARY)
            # retarget should have a source path in change model, even though only targeting changed
            retarget = dictionary_utils.get_dictionary_element(
                libraries, 'retarget')
            self.assertEqual(
                SOURCE_PATH in retarget, True,
                LIBRARY + ' retarget should  contain ' + SOURCE_PATH)

            applications = dictionary_utils.get_dictionary_element(
                deployments, APPLICATION)
            # myapp should not appear in change model, it had no changes
            self.assertEqual(
                len(applications), 1,
                "only one entry should be present in " + APPLICATION)
            # retarget should have a source path in change model, even though only targeting changed
            retarget = dictionary_utils.get_dictionary_element(
                applications, 'retarget')
            self.assertEqual(
                SOURCE_PATH in retarget, True,
                APPLICATION + ' retarget should  contain ' + SOURCE_PATH)

        except (CompareException, PyWLSTException), te:
            return_code = 2
            self._logger.severe('WLSDPLY-05709',
                                te.getLocalizedMessage(),
                                error=te,
                                class_name=self._program_name,
                                method_name=_method_name)
示例#29
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
    def testCompareModelFull2(self):
        _method_name = 'testCompareModelFull2'
        # This test for
        # 1. Changing weblogic password
        # 2. Changing RCU password
        # 3. Deleting an application

        _variables_file = self._resources_dir + '/compare_model_model1.10.properties'
        _new_model_file = self._resources_dir + '/compare_model_model7.yaml'
        _old_model_file = self._resources_dir + '/compare_model_model6.yaml'
        _temp_dir = os.path.join(tempfile.gettempdir(), _method_name)

        if os.path.exists(_temp_dir):
            shutil.rmtree(_temp_dir)

        os.mkdir(_temp_dir)

        mw_home = os.environ['MW_HOME']
        args_map = {
            '-oracle_home': mw_home,
            '-variable_file': _variables_file,
            '-output_dir': _temp_dir,
            '-domain_type': 'WLS',
            '-trailing_arguments': [_new_model_file, _old_model_file]
        }

        try:
            model_context = ModelContext('CompareModelTestCase', args_map)
            obj = ModelFileDiffer(_new_model_file, _old_model_file,
                                  model_context, _temp_dir)
            return_code = obj.compare()
            self.assertEqual(return_code, 0)

            yaml_result = _temp_dir + os.sep + 'diffed_model.yaml'
            json_result = _temp_dir + os.sep + 'diffed_model.json'
            stdout_result = obj.get_compare_msgs()
            model_dictionary = FileToPython(yaml_result).parse()
            yaml_exists = os.path.exists(yaml_result)
            json_exists = os.path.exists(json_result)

            self.assertEqual(yaml_exists, True)
            self.assertEqual(json_exists, True)
            self.assertEqual(len(stdout_result), 0)

            self.assertEqual(model_dictionary.has_key('domainInfo'), True)
            self.assertEqual(
                model_dictionary['domainInfo'].has_key('AdminPassword'), True)
            self.assertEqual(model_dictionary['domainInfo']['AdminPassword'],
                             'welcome2')
            self.assertEqual(
                model_dictionary['domainInfo'].has_key('AdminUser'), False)
            self.assertEqual(
                model_dictionary['domainInfo'].has_key('RCUDbInfo'), True)
            self.assertEqual(
                model_dictionary['domainInfo']['RCUDbInfo'].has_key(
                    'rcu_admin_password'), True)
            self.assertEqual(len(model_dictionary['domainInfo']['RCUDbInfo']),
                             1)
            self.assertEqual(len(model_dictionary['domainInfo']), 2)
            self.assertEqual(model_dictionary.has_key('appDeployments'), True)
            self.assertEqual(
                model_dictionary['appDeployments'].has_key('Application'),
                True)
            self.assertEqual(
                model_dictionary['appDeployments']['Application'].has_key(
                    '!yourear'), True)
            self.assertEqual(
                len(model_dictionary['appDeployments']['Application']), 1)

        except (CompareException, PyWLSTException), te:
            return_code = 2
            self._logger.severe('WLSDPLY-05709',
                                te.getLocalizedMessage(),
                                error=te,
                                class_name=self._program_name,
                                method_name=_method_name)