Exemplo n.º 1
0
    def __init__(self,
                 program_name,
                 model,
                 model_context,
                 version=None,
                 variable_dictionary=None):
        """
        Construct an instance of the injector with the model and information used by the injector.
        :param program_name: name of the calling tool
        :param model: to be updated with variables
        :param model_context: context with command line information
        :param version: of model if model context is not provided
        """
        self.__program_name = program_name
        self.__original = copy.deepcopy(model)
        self.__model = model
        self.__model_context = model_context
        if self.__model_context:
            self.__wlst_mode = self.__model_context.get_target_wlst_mode()
        else:
            self.__wlst_mode = WlstModes.OFFLINE
        self.__section_keys = model_sections.get_model_top_level_keys()
        self.__section_keys.remove(model_sections.get_model_domain_info_key())

        if version:
            self.__aliases = Aliases(model_context,
                                     wlst_mode=self.__wlst_mode,
                                     wls_version=version)
        else:
            self.__aliases = Aliases(model_context)
        self.__variable_dictionary = variable_dictionary
Exemplo n.º 2
0
 def __init__(self,
              model_context,
              base_location,
              wlst_mode,
              aliases=None,
              credential_injector=None):
     """
     :param model_context: context about the model for this instance of discover domain
     :param base_location: to look for common weblogic resources. By default this is the global path or '/'
     :param wlst_mode: offline or online
     :param aliases: optional, aliases object to use
     :param credential_injector: optional, injector to collect credentials
     """
     self._model_context = model_context
     self._base_location = base_location
     self._wlst_mode = wlst_mode
     if aliases:
         self._aliases = aliases
     else:
         self._aliases = Aliases(self._model_context,
                                 wlst_mode=self._wlst_mode,
                                 exception_type=ExceptionType.DISCOVER)
     self._credential_injector = credential_injector
     self._att_handler_map = OrderedDict()
     self._custom_folder = CustomFolderHelper(self._aliases, _logger,
                                              self._model_context,
                                              ExceptionType.DISCOVER,
                                              self._credential_injector)
     self._weblogic_helper = WebLogicHelper(_logger)
     self._wlst_helper = WlstHelper(ExceptionType.DISCOVER)
     self._mbean_utils = MBeanUtils(self._model_context, self._aliases,
                                    ExceptionType.DISCOVER)
     self._wls_version = self._weblogic_helper.get_actual_weblogic_version()
Exemplo n.º 3
0
    def _is_alias_folder(self, path):
        """
        Check if the delimited path is a folder or attribute
        :param path: '|' delimited path
        :return: true if it is a folder otherwise false
        """
        debug("DEBUG: Entering is_alias_folder %s", path)
        path_tokens = path.split(PATH_TOKEN)
        model_context = ModelContext("test", {})
        aliases = Aliases(model_context=model_context,
                          wlst_mode=WlstModes.OFFLINE)
        location = LocationContext()
        last_token = path_tokens[-1]
        alias_helper = AliasHelper(aliases, __logger, ExceptionType.COMPARE)

        found = True
        name_token_next = False
        for path_token in path_tokens[1:]:
            if name_token_next:
                token_name = aliases.get_name_token(location)
                location.add_name_token(token_name, path_token)
                name_token_next = False
            else:
                location.append_location(path_token)
                if last_token == path_token:
                    break
                name_token_next = alias_helper.supports_multiple_mbean_instances(
                    location)
            attrib_names = alias_helper.get_model_attribute_names(location)
            if last_token in attrib_names:
                found = False

        debug("DEBUG: is_alias_folder %s %s", path, found)

        return found
Exemplo n.º 4
0
class AliasEncryptedModelTestCase(unittest.TestCase):
    """
    Test cases for a the -use_encryption feature.
    """

    _logger = PlatformLogger('wlsdeploy.aliases')
    _wls_version = '12.2.1.3'
    _wlst_password_name = "Password"
    _wlst_password_encrypted_name = "PasswordEncrypted"

    _passphrase = 'RE a drop of golden sun'
    _password = '******'
    _encrypted_password = '******'

    def setUp(self):
        # construct aliases as if the -use_encryption and -passphrase switches were used
        model_context = ModelContext("test", {CommandLineArgUtil.USE_ENCRYPTION_SWITCH: 'true',
                                              CommandLineArgUtil.PASSPHRASE_SWITCH: self._passphrase})
        self.aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self._wls_version)
        self.online_aliases = Aliases(model_context, wlst_mode=WlstModes.ONLINE, wls_version=self._wls_version)

        self.location = LocationContext()
        self.location.append_location(JDBC_SYSTEM_RESOURCE)
        self.location.add_name_token(self.aliases.get_name_token(self.location), "Mine")
        self.location.append_location(JDBC_RESOURCE)
        self.location.append_location(JDBC_DRIVER_PARAMS)

    def testOfflineWlstNames(self):
        # Using offline WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST
        # attribute, regardless of whether the password is encrypted. The password value should be plain text.

        # using encrypted password
        wlst_name, wlst_value = \
            self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password)
        self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
        self.assertEqual(wlst_value, self._password)

        # using unencrypted password
        wlst_name, wlst_value = \
            self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
        self.assertEquals(wlst_name, self._wlst_password_encrypted_name)
        self.assertEqual(wlst_value, self._password)

    def testOnlineWlstNames(self):
        # Using online WLST, the PasswordEncrypted model attribute should always translate to the Password WLST
        # attribute, and the value should translate to the unencrypted value.

        # using encrypted password
        wlst_name, wlst_value = \
            self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED,
                                                                  self._encrypted_password)
        self.assertEqual(wlst_name, self._wlst_password_name)
        self.assertEqual(wlst_value, self._password)

        # using unencrypted password
        wlst_name, wlst_value = \
            self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
        self.assertEquals(wlst_name, self._wlst_password_name)
        self.assertEqual(wlst_value, self._password)
    def setUp(self):
        model_context = ModelContext("test", {})
        self.aliases = Aliases(model_context,
                               wlst_mode=WlstModes.OFFLINE,
                               wls_version=self._wls_version)
        self.online_aliases = Aliases(model_context,
                                      wlst_mode=WlstModes.ONLINE,
                                      wls_version=self._wls_version)

        self.location = aliases_test.get_jdbc_driver_params_location(
            "Mine", self.aliases)
Exemplo n.º 6
0
 def __init__(self, model_files, model_context, logger, output_dir=None):
     self.model_files = model_files
     self.output_dir = output_dir
     self.model_context = model_context
     self._aliases = Aliases(model_context=model_context, wlst_mode=WlstModes.OFFLINE,
                             exception_type=ExceptionType.COMPARE)
     self._logger = logger
     self._name_tokens_location = LocationContext()
     self._name_tokens_location.add_name_token('DOMAIN', "testdomain")
     self.current_dict = None
     self.credential_injector = CredentialInjector(_program_name, None, model_context)
Exemplo n.º 7
0
    def testAttributeNames(self):
        model_context = ModelContext("test", { })
        aliases = Aliases(model_context=model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self.wls_version)

        location = LocationContext()
        self._check_folder('Domain', location, aliases)

        for folder_name in aliases.get_model_top_level_folder_names():
            location = LocationContext()
            location.append_location(folder_name)
            self._check_folder(folder_name, location, aliases)
    def setUp(self):
        model_context = ModelContext("test", {CommandLineArgUtil.USE_ENCRYPTION_SWITCH: 'true',
                                              CommandLineArgUtil.PASSPHRASE_SWITCH: self._passphrase})
        self.aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self._wls_version)
        self.online_aliases = Aliases(model_context, wlst_mode=WlstModes.ONLINE, wls_version=self._wls_version)

        self.location = LocationContext()
        self.location.append_location(JDBC_SYSTEM_RESOURCE)
        self.location.add_name_token(self.aliases.get_name_token(self.location), "Mine")
        self.location.append_location(JDBC_RESOURCE)
        self.location.append_location(JDBC_DRIVER_PARAMS)
 def __init__(self, model_files, model_context, logger, output_dir=None):
     self.model_files = model_files
     self.output_dir = output_dir
     self.model_context = model_context
     self._aliases = Aliases(model_context=model_context, wlst_mode=WlstModes.OFFLINE)
     self._alias_helper = AliasHelper(self._aliases, logger, ExceptionType.COMPARE)
     self._logger = logger
     self._name_tokens_location = LocationContext()
     self._name_tokens_location.add_name_token('DOMAIN', "testdomain")
     self.current_dict = None
     self.cache =  OrderedDict()
     self.secrets_to_generate = sets.Set()
Exemplo n.º 10
0
class VariableInjectorFunctionsTests(unittest.TestCase):
    """
    Test the variable injector functions methods.
    """
    wls_version = '12.2.1.3'
    attribute_name = 'Notes'

    def setUp(self):
        model_context = ModelContext("test", {})
        self.aliases = Aliases(model_context)
        self.location = LocationContext().append_location(MACHINE)
        self.name_token = self.aliases.get_name_token(self.location)
        self.short_name = self.aliases.get_folder_short_name(self.location)

    def testFormatVariableName(self):
        """
        Verify that names from location are converted to valid variable names.
        """
        # spaces in model name
        self._check_name('My Machine', 'My-Machine')

        # parenthesis can be in model name
        self._check_name('ohMy-(datasource)', 'ohMy--datasource-')

        # versioned library names may be model names
        self._check_name(
            'Lib.oracle.wsm.idmrest.sharedlib#[email protected]',
            'Lib.oracle.wsm.idmrest.sharedlib-1.0-12.2.1.3.Target')

    def _check_name(self, name, expected_key):
        """
        Verify that the specified name is converted to match the expected key.
        A machine location is created with the supplied name and converted to a variable name.
        An expected value is constructed using the expected key and known parameters.
        :param name: the name to be converted
        :param expected_key: the expected variable key
        """
        self.location.add_name_token(self.name_token, name)
        variable_name = variable_injector_functions.format_variable_name(
            self.location, self.attribute_name, self.aliases)

        # verify that a property built with this value will parse correctly
        property_text = '@@PROP:%s@@' % variable_name
        matches = variables._property_pattern.findall(property_text)
        self.assertEqual(1, len(matches),
                         "Property %s should parse correctly" % property_text)

        expected_name = "%s.%s.%s" % (self.short_name, expected_key,
                                      self.attribute_name)
        self.assertEqual(expected_name, variable_name)
Exemplo n.º 11
0
    def setUp(self):
        model_context = ModelContext("test", {})
        self.aliases = Aliases(model_context,
                               wlst_mode=WlstModes.OFFLINE,
                               wls_version=self._wls_version)
        self.online_aliases = Aliases(model_context,
                                      wlst_mode=WlstModes.ONLINE,
                                      wls_version=self._wls_version)

        self.location = LocationContext()
        self.location.append_location(JDBC_SYSTEM_RESOURCE)
        self.location.add_name_token(
            self.aliases.get_name_token(self.location), "Mine")
        self.location.append_location(JDBC_RESOURCE)
        self.location.append_location(JDBC_DRIVER_PARAMS)
Exemplo n.º 12
0
def print_help(model_path, model_context):
    """
    Prints the folders and/or attributes for the specified given model_path,
    using control_option to filter what is output
    :param model_path: the model path to print help for
    :param model_context: the model context, used to determine print options
    :return: an exit code
    """
    _method_name = 'print_help'

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

    # default to NORMAL
    control_option = ModelHelpPrinter.ControlOptions.NORMAL

    # determine control option using the model_context
    if model_context.get_recursive_control_option():
        control_option = ModelHelpPrinter.ControlOptions.RECURSIVE
    elif model_context.get_attributes_only_control_option():
        control_option = ModelHelpPrinter.ControlOptions.ATTRIBUTES_ONLY
    elif model_context.get_folders_only_control_option():
        control_option = ModelHelpPrinter.ControlOptions.FOLDERS_ONLY

    aliases = Aliases(model_context)
    printer = ModelHelpPrinter(aliases, __logger)
    printer.print_model_help(model_path, control_option)

    __logger.exiting(class_name=_class_name, method_name=_method_name)
    return CommandLineArgUtil.PROG_OK_EXIT_CODE
Exemplo n.º 13
0
    def testPersistModelAfterFilter(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 = 'testPersistModelAfterFilter'

        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)

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

        # Load model and invoke filter
        model_dictionary = cla_helper.load_model('validateModel', model_context, aliases, "validate", WlstModes.OFFLINE)

        # assert the validate filter made modications and was persisted
        self.assertEquals('gumby1234', model_dictionary['domainInfo']['AdminPassword'], "Expected validate filter to have changed AdminPassword to 'gumby1234'")
    def setUp(self):
        # construct aliases as if the -use_encryption and -passphrase switches were used
        model_context = ModelContext(
            "test", {
                CommandLineArgUtil.USE_ENCRYPTION_SWITCH: 'true',
                CommandLineArgUtil.PASSPHRASE_SWITCH: self._passphrase
            })
        self.aliases = Aliases(model_context,
                               wlst_mode=WlstModes.OFFLINE,
                               wls_version=self._wls_version)
        self.online_aliases = Aliases(model_context,
                                      wlst_mode=WlstModes.ONLINE,
                                      wls_version=self._wls_version)

        self.location = aliases_test.get_jdbc_driver_params_location(
            "Mine", self.aliases)
    def testDelimitedAttributes(self):
        # This test ensures that delimited attributes are always comma-delimited for the model.
        # Space-delimited attributes are allowed to bypass this rule.

        model_context = ModelContext("test", {})
        aliases = Aliases(model_context=model_context,
                          wlst_mode=WlstModes.OFFLINE,
                          wls_version=self.wls_version)

        location = LocationContext()
        self._check_folder(location, aliases)

        for folder_name in aliases.get_model_top_level_folder_names():
            location = LocationContext()
            location.append_location(folder_name)
            self._check_folder(location, aliases)
Exemplo n.º 16
0
    def __init__(self,
                 model_context,
                 base_location,
                 wlst_mode,
                 aliases=None,
                 variable_injector=None):
        """

        :param model_context: context about the model for this instance of discover domain
        :param base_location: to look for common weblogic resources. By default this is the global path or '/'
        """
        self._model_context = model_context
        self._base_location = base_location
        self._wlst_mode = wlst_mode
        if aliases:
            self._aliases = aliases
        else:
            self._aliases = Aliases(self._model_context,
                                    wlst_mode=self._wlst_mode)
        self._alias_helper = AliasHelper(self._aliases, _logger,
                                         ExceptionType.DISCOVER)
        self._variable_injector = variable_injector
        self._att_handler_map = OrderedDict()
        self._custom_folder = CustomFolderHelper(self._aliases, _logger,
                                                 self._model_context,
                                                 ExceptionType.DISCOVER,
                                                 self._variable_injector)
        self._weblogic_helper = WebLogicHelper(_logger)
        self._wlst_helper = WlstHelper(ExceptionType.DISCOVER)
        self._mbean_utils = MBeanUtils(self._model_context, self._alias_helper,
                                       ExceptionType.DISCOVER)
        self._wls_version = self._weblogic_helper.get_actual_weblogic_version()
Exemplo n.º 17
0
 def __init__(self, model_context, exception_type, location):
     self.__model_context = model_context
     self.__exception_type = exception_type
     self.__location = location
     self.__aliases = Aliases(
         self.__model_context,
         wlst_mode=self.__model_context.get_target_wlst_mode())
     self.__alias_helper = AliasHelper(self.__aliases, _logger,
                                       exception_type)
     self.__wlst_helper = WlstHelper(_logger, exception_type)
     self.__mbean_instance = None
     self.__mbean_name = ''
    def setUp(self):
        arg_map = dict()
        arg_map[CLA.ORACLE_HOME_SWITCH] = '/my/path/to/oracle'
        arg_map[CLA.TARGET_MODE_SWITCH] = 'offline'

        self._model_context = ModelContext("test", arg_map)
        self._aliases = Aliases(model_context=self._model_context,
                                wlst_mode=WlstModes.OFFLINE,
                                wls_version=self._wls_version)
        self._custom_helper = CustomFolderHelper(self._aliases, self._logger,
                                                 self._model_context,
                                                 ExceptionType.DISCOVER)
        return
Exemplo n.º 19
0
    def _get_model_help(self, path, control_option):
        try:
            old_out = sys.stdout
            sys.stdout = StringIO()

            model_context = ModelContext(self._program_name, { })
            aliases = Aliases(model_context, WlstModes.OFFLINE, self.wls_version)
            printer = ModelHelpPrinter(aliases, self._logger)
            printer.print_model_help(path, control_option)

            sys.stdout.flush()
            text = sys.stdout.getvalue()
            sys.stdout = old_out
            return text

        except CLAException, e:
            self.fail(e.getLocalizedMessage())
Exemplo n.º 20
0
        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
        validate_model(model_dictionary, model_context, aliases)

    try:
        model = Model(model_dictionary)
        exit_code = __deploy(model, model_context, aliases)
    except DeployException, ex:
        __logger.severe('WLSDPLY-09015',
                        _program_name,
                        ex.getLocalizedMessage(),
                        error=ex,
                        class_name=_class_name,
Exemplo n.º 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
Exemplo n.º 22
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
Exemplo n.º 23
0
        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)
        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)

    aliases = Aliases(model_context,
                      wlst_mode=__wlst_mode,
                      exception_type=ExceptionType.DEPLOY)

    model_dictionary = cla_helper.load_model(_program_name, model_context,
                                             aliases, "update", __wlst_mode)

    try:
        model = Model(model_dictionary)
        exit_code = __update(model, model_context, aliases)
    except DeployException, ex:
        __logger.severe('WLSDPLY-09015',
                        _program_name,
                        ex.getLocalizedMessage(),
                        error=ex,
                        class_name=_class_name,
                        method_name=_method_name)
Exemplo n.º 24
0
class Discoverer(object):
    """
    Discoverer contains the private methods used to facilitate discovery of the domain information by its subclasses.
    """
    def __init__(self, model_context, base_location, wlst_mode, aliases=None):
        """

        :param model_context: context about the model for this instance of discover domain
        :param base_location: to look for common weblogic resources. By default this is the global path or '/'
        """
        self._model_context = model_context
        self._base_location = base_location
        self._wlst_mode = wlst_mode
        if aliases:
            self._aliases = aliases
        else:
            self._aliases = Aliases(self._model_context,
                                    wlst_mode=self._wlst_mode)
        self._alias_helper = AliasHelper(self._aliases, _logger,
                                         ExceptionType.DISCOVER)
        self._att_handler_map = OrderedDict()
        self._wls_version = WebLogicHelper(
            _logger).get_actual_weblogic_version()
        self._wlst_helper = WlstHelper(_logger, ExceptionType.DISCOVER)

    # methods for use only by the subclasses

    def _populate_model_parameters(self, dictionary, location):
        """
        Populate the model dictionary with the attribute values discovered at the current location. Perform
        any special processing for a specific attribute before storing into the model dictionary.
        :param dictionary: where to store the discovered attributes
        :param location: context containing current location information
        :return: dictionary of model attribute name and wlst value
        """
        _method_name = '_populate_model_parameters'
        wlst_path = self._alias_helper.get_wlst_attributes_path(location)
        _logger.finer('WLSDPLY-06100',
                      wlst_path,
                      class_name=_class_name,
                      method_name=_method_name)

        if not self.wlst_cd(wlst_path, location):
            return

        wlst_params = self._get_attributes_for_current_location(location)
        _logger.finest('WLSDPLY-06102',
                       self._wlst_helper.get_pwd(),
                       wlst_params,
                       class_name=_class_name,
                       method_name=_method_name)
        wlst_get_params = self._get_required_attributes(location)
        _logger.finest('WLSDPLY-06103',
                       str(location),
                       wlst_get_params,
                       class_name=_class_name,
                       method_name=_method_name)
        attr_dict = OrderedDict()
        if wlst_params:
            for wlst_param in wlst_params:
                if wlst_param in wlst_get_params:
                    _logger.finest('WLSDPLY-06104',
                                   wlst_param,
                                   class_name=_class_name,
                                   method_name=_method_name)
                    try:
                        wlst_value = wlst_helper.get(wlst_param)
                    except PyWLSTException, pe:
                        _logger.warning('WLSDPLY-06127',
                                        wlst_param,
                                        wlst_path,
                                        pe.getLocalizedMessage(),
                                        class_name=_class_name,
                                        method_name=_method_name)
                        continue
                else:
                    _logger.finer('WLSDPLY-06131',
                                  wlst_param,
                                  class_name=_class_name,
                                  method_name=_method_name)
                    wlst_value = wlst_params[wlst_param]

                # if type(wlst_value) == str and len(wlst_value) == 0:
                #     wlst_value = None

                _logger.finer('WLSDPLY-06105',
                              wlst_param,
                              wlst_value,
                              wlst_path,
                              class_name=_class_name,
                              method_name=_method_name)
                try:
                    model_param, model_value = self._aliases.get_model_attribute_name_and_value(
                        location, wlst_param, wlst_value)
                except AliasException, de:
                    _logger.info('WLSDPLY-06106',
                                 wlst_param,
                                 wlst_path,
                                 de.getLocalizedMessage(),
                                 class_name=_class_name,
                                 method_name=_method_name)
                    continue

                attr_dict[model_param] = wlst_value
                model_value = self._check_attribute(model_param, model_value,
                                                    location)
                if model_value is not None:
                    _logger.finer('WLSDPLY-06107',
                                  model_param,
                                  model_value,
                                  class_name=_class_name,
                                  method_name=_method_name)
                    dictionary[model_param] = model_value
                elif model_param is None:
                    _logger.finest('WLSDPLY-06108',
                                   model_param,
                                   class_name=_class_name,
                                   method_name=_method_name)
Exemplo n.º 25
0
class AliasPasswordTestCase(unittest.TestCase):

    _logger = PlatformLogger('wlsdeploy.aliases')
    _wls_version = '12.2.1.3'
    _wlst_password_name = "Password"
    _wlst_password_encrypted_name = "PasswordEncrypted"

    _passphrase = 'RE a drop of golden sun'
    _password = '******'
    _encrypted_password = '******'
    _encrypted_password_bytes = jarray.array(_encrypted_password, 'b')

    def setUp(self):
        model_context = ModelContext(
            "test", {
                CommandLineArgUtil.USE_ENCRYPTION_SWITCH: 'true',
                CommandLineArgUtil.PASSPHRASE_SWITCH: self._passphrase
            })
        self.aliases = Aliases(model_context,
                               wlst_mode=WlstModes.OFFLINE,
                               wls_version=self._wls_version)
        self.online_aliases = Aliases(model_context,
                                      wlst_mode=WlstModes.ONLINE,
                                      wls_version=self._wls_version)

        self.location = LocationContext()
        self.location.append_location(JDBC_SYSTEM_RESOURCE)
        self.location.add_name_token(
            self.aliases.get_name_token(self.location), "Mine")
        self.location.append_location(JDBC_RESOURCE)
        self.location.append_location(JDBC_DRIVER_PARAMS)

    def testOfflineModelNames(self):
        # Using offline WLST, only PasswordEncrypted is an attribute, and its value is encrypted.
        # The model name should be PasswordEncrypted.
        model_name, model_value = \
            self.aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_encrypted_name,
                                                            self._encrypted_password)
        self.assertEquals(model_name, PASSWORD_ENCRYPTED)

    def testOnlineModelNames(self):
        # Using online WLST, both Password and PasswordEncrypted are WLST attributes.

        # The PasswordEncrypted WLST attribute should translate to the PasswordEncrypted model attribute.
        model_name, model_value = \
            self.online_aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_encrypted_name,
                                                                   self._encrypted_password)
        self.assertEqual(model_name, PASSWORD_ENCRYPTED)

        # The Password WLST attribute should be skipped, since its value cannot be retrieved.
        # This is accomplished by returning a model name of None.
        model_name, model_value = \
            self.online_aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_name,
                                                                   self._encrypted_password)
        self.assertEquals(model_name, None)

    def testOfflineWlstNames(self):
        # Using offline WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST
        # attribute, regardless of whether the password is encrypted.

        # using encrypted password
        wlst_name, wlst_value = \
            self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password)
        self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
        self.assertEqual(wlst_value, self._password)

        # using unencrypted password
        wlst_name, wlst_value = \
            self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
        self.assertEquals(wlst_name, self._wlst_password_encrypted_name)

    def testOnlineWlstNames(self):
        # Using online WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST
        # attribute if the password is encrypted, otherwise to Password.

        # using encrypted password
        wlst_name, wlst_value = \
            self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED,
                                                                  self._encrypted_password)
        self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
        self.assertEqual(wlst_value, self._password)

        # using unencrypted password
        wlst_name, wlst_value = \
            self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
        self.assertEquals(wlst_name, self._wlst_password_name)
Exemplo n.º 26
0
class VariableInjector(object):
    def __init__(self, program_name, model, model_context=None, version=None):
        """
        Construct an instance of the injector with the model and information used by the injector.
        :param program_name: name of the calling tool
        :param model: to be updated with variables
        :param model_context: context with command line information
        :param version: of model if model context is not provided
        """
        self.__program_name = program_name
        self.__original = copy.deepcopy(model)
        self.__model = model
        self.__model_context = model_context
        if self.__model_context:
            self.__wlst_mode = self.__model_context.get_target_wlst_mode()
        else:
            self.__wlst_mode = WlstModes.OFFLINE
        self.__section_keys = model_sections.get_model_top_level_keys()
        self.__section_keys.remove(model_sections.get_model_domain_info_key())

        if version:
            self.__aliases = Aliases(model_context, self.__wlst_mode, version,
                                     None)
        else:
            self.__aliases = Aliases(model_context)

    def inject_variables_keyword_file(self, **kwargs):
        """
        Replace attribute values with variables and generate a variable dictionary.
        The variable replacement is driven from the values in the model variable helper file.
        This file can either contain the name of a replacement file, or a list of pre-defined
        keywords for canned replacement files.
        Return the variable dictionary with the variable name inserted into the model, and the value
        that the inserted variable replaced.
        :param kwargs: arguments used to override default for variable processing, typically used in test situations
        :return: variable dictionary containing
        """
        _method_name = 'inject_variables_keyword_file'
        _logger.entering(class_name=_class_name, method_name=_method_name)

        variable_injector_location_file = _get_variable_injector_file_name(
            **kwargs)
        variables_injector_dictionary = _load_variable_injector_file(
            variable_injector_location_file)
        variable_keywords_location_file = _get_variable_keywords_file_name(
            **kwargs)
        keywords_dictionary = _load_keywords_file(
            variable_keywords_location_file)

        variables_inserted = False
        return_model = self.__original
        variable_file_location = None
        if variables_injector_dictionary and keywords_dictionary:
            variable_file_location = self._get_variable_file_name(**kwargs)
            if not variable_file_location:
                _logger.warning('WLSDPLY-19520',
                                variable_injector_location_file,
                                class_name=_class_name,
                                method_name=_method_name)
            else:
                _logger.info('WLSDPLY-19533',
                             variable_injector_location_file,
                             class_name=_class_name,
                             method_name=_method_name)
                append, stage_dictionary = _load_variable_file(
                    variable_file_location, **kwargs)
                injector_file_list = _create_injector_file_list(
                    variables_injector_dictionary, keywords_dictionary,
                    _get_keyword_files_location(**kwargs))
                variables_file_dictionary = self.inject_variables_keyword_dictionary(
                    injector_file_list)
                if variables_file_dictionary:
                    stage_dictionary.update(variables_file_dictionary)
                    variables_inserted = self._write_variables_file(
                        stage_dictionary, variable_file_location, append)
                if variables_inserted:
                    _logger.info('WLSDPLY-19518',
                                 variable_file_location,
                                 class_name=_class_name,
                                 method_name=_method_name)
                    return_model = self.__model
                else:
                    _logger.info('WLSDPLY-19519',
                                 class_name=_class_name,
                                 method_name=_method_name)
                    variable_file_location = None
        else:
            _logger.info('WLSDPLY-19532',
                         variable_injector_location_file,
                         class_name=_class_name,
                         method_name=_method_name)

        _logger.exiting(class_name=_class_name,
                        method_name=_method_name,
                        result=variables_inserted)
        return variables_inserted, return_model, variable_file_location

    def inject_variables_keyword_dictionary(self, injector_file_list):
        """
        Takes a variable keyword dictionary and returns a variables for file in a dictionary
        :param injector_file_list: list of injector files for processing variable injection
        :return: variables_dictionary containing the variable properties to persist to the variable file
        """
        _method_name = 'inject_variables_keyword_dictionary'
        _logger.entering(injector_file_list,
                         class_name=_class_name,
                         method_name=_method_name)
        variable_dictionary = dict()
        for filename in injector_file_list:
            injector_dictionary = _load_injector_file(
                self._replace_tokens(filename))
            entries = self.inject_variables(injector_dictionary)
            if entries:
                _logger.finer('WLSDPLY-19513',
                              filename,
                              class_name=_class_name,
                              method_name=_method_name)
                variable_dictionary.update(entries)
        _logger.exiting(class_name=_class_name,
                        method_name=_method_name,
                        result=variable_dictionary)
        return variable_dictionary

    def inject_variables(self, injector_dictionary):
        """
        Iterate through the injector dictionary that was loaded from the file for the model
        injector file keyword.
        :param injector_dictionary:
        :return: variable dictionary containing the variable string and model value entries
        """
        variable_dict = dict()
        if injector_dictionary:
            location = LocationContext()
            domain_token = self.__aliases.get_name_token(location)
            location.add_name_token(domain_token, _fake_name_marker)
            for injector, injector_values in injector_dictionary.iteritems():
                entries_dict = self.__inject_variable(location, injector,
                                                      injector_values)
                if len(entries_dict) > 0:
                    variable_dict.update(entries_dict)

        return variable_dict

    def __inject_variable(self, location, injector, injector_values):
        _method_name = '__inject_variable'
        _logger.entering(injector,
                         class_name=_class_name,
                         method_name=_method_name)
        variable_dict = dict()
        start_mbean_list, attribute = _split_injector(injector)

        def _traverse_variables(model_section, mbean_list):
            if mbean_list:
                mbean = mbean_list.pop(0)
                mbean, mbean_name_list = self._find_special_name(mbean)
                _logger.finer('WLSDPLY-19523',
                              mbean,
                              location.get_folder_path(),
                              class_name=_class_name,
                              method_name=_method_name)
                if mbean in model_section:
                    _logger.finest('WLSDPLY-19514',
                                   mbean,
                                   class_name=_class_name,
                                   method_name=_method_name)
                    next_model_section = model_section[mbean]
                    location.append_location(mbean)
                    name_token = self.__aliases.get_name_token(location)
                    if not mbean_name_list:
                        if self.__aliases.supports_multiple_mbean_instances(
                                location):
                            mbean_name_list = next_model_section
                        else:
                            self._check_name_token(location, name_token)
                    else:
                        _logger.fine('WLSDPLY-19506',
                                     mbean_name_list,
                                     attribute,
                                     location.get_folder_path(),
                                     class_name=_class_name,
                                     method_name=_method_name)
                    if mbean_name_list:
                        for mbean_name in mbean_name_list:
                            if mbean_name in next_model_section:
                                continue_mbean_list = copy.copy(mbean_list)
                                location.add_name_token(name_token, mbean_name)
                                _traverse_variables(
                                    next_model_section[mbean_name],
                                    continue_mbean_list)
                                location.remove_name_token(name_token)
                    else:
                        _traverse_variables(next_model_section, mbean_list)
                    location.pop_location()
                else:
                    self._log_mbean_not_found(mbean, injector, location)
                    return False
            else:
                self._check_insert_attribute_model(location, model_section,
                                                   attribute, injector_values)
                if attribute in model_section:
                    returned_dict = self._variable_info(
                        model_section, attribute, location, injector_values)
                    if returned_dict:
                        variable_dict.update(returned_dict)
                else:
                    _logger.finer('WLSDPLY-19517',
                                  attribute,
                                  injector,
                                  location.get_folder_path(),
                                  class_name=_class_name,
                                  method_name=_method_name)
            return True

        section = self.__model
        if start_mbean_list:
            # Find out in what section is the mbean top folder so can move to that section in the model
            top_mbean, __ = self._find_special_name(start_mbean_list[0])
            for entry in self.__section_keys:
                if entry in self.__model and top_mbean in self.__model[entry]:
                    section = self.__model[entry]
                    break
        else:
            # This is a domain attribute
            section = self.__model[model_sections.get_model_topology_key()]
        # if it wasn't found, will log appropriately in the called method
        # This also will allow someone to put the section in the injector string
        _traverse_variables(section, start_mbean_list)

        _logger.exiting(class_name=_class_name,
                        method_name=_method_name,
                        result=variable_dict)

        return variable_dict

    def __format_variable_name(self, location, attribute):
        _method_name = '__format_variable_name'
        variable_name = attribute
        make_path = None
        try:
            make_path = self.__aliases.get_model_folder_path(location)
        except AliasException, ae:
            _logger.warning('WLSDPLY-19531',
                            str(location),
                            attribute,
                            ae.getLocalizedMessage(),
                            class_name=_class_name,
                            method_name=_method_name)
        if make_path:
            make_path = make_path.split(':')
            if len(make_path) > 1 and len(make_path[1]) > 1:
                variable_name = make_path[1]
                variable_name = variable_name[1:] + VARIABLE_SEP + attribute
        return _massage_name(variable_name)
Exemplo n.º 27
0
    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

    aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE)
    alias_helper = AliasHelper(aliases, __logger, ExceptionType.ENCRYPTION)

    try:
        passphrase = model_context.get_encryption_passphrase()
        model_change_count, variable_change_count = \
            encryption_utils.encrypt_model_dictionary(passphrase, model, alias_helper, variables)
    except EncryptionException, ee:
        __logger.severe('WLSDPLY-04208',
                        _program_name,
                        ee.getLocalizedMessage(),
                        error=ee,
                        class_name=_class_name,
                        method_name=_method_name)
        return CommandLineArgUtil.PROG_ERROR_EXIT_CODE
Exemplo n.º 28
0
class AliasPasswordTestCase(unittest.TestCase):

    _logger = PlatformLogger('wlsdeploy.aliases')
    _wls_version = '12.2.1.3'
    _wlst_password_name = "Password"
    _wlst_password_encrypted_name = "PasswordEncrypted"

    _password = '******'
    _encrypted_password = '******'
    _encrypted_password_bytes = jarray.array(_encrypted_password, 'b')

    def setUp(self):
        model_context = ModelContext("test", {})
        self.aliases = Aliases(model_context,
                               wlst_mode=WlstModes.OFFLINE,
                               wls_version=self._wls_version)
        self.online_aliases = Aliases(model_context,
                                      wlst_mode=WlstModes.ONLINE,
                                      wls_version=self._wls_version)

        self.location = LocationContext()
        self.location.append_location(JDBC_SYSTEM_RESOURCE)
        self.location.add_name_token(
            self.aliases.get_name_token(self.location), "Mine")
        self.location.append_location(JDBC_RESOURCE)
        self.location.append_location(JDBC_DRIVER_PARAMS)

    def testOfflineModelNames(self):
        # Using offline WLST, only PasswordEncrypted is an attribute, and its value is encrypted.
        # The model name should be PasswordEncrypted.
        model_name, model_value = \
            self.aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_encrypted_name,
                                                            self._encrypted_password)
        self.assertEquals(model_name, PASSWORD_ENCRYPTED)

    def testOnlineModelNames(self):
        # Using online WLST, both Password and PasswordEncrypted are WLST attributes.

        # The PasswordEncrypted WLST attribute should translate to the PasswordEncrypted model attribute.
        model_name, model_value = \
            self.online_aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_encrypted_name,
                                                                   self._encrypted_password)
        self.assertEqual(model_name, PASSWORD_ENCRYPTED)

        # The Password WLST attribute should be skipped, since its value cannot be retrieved.
        # This is accomplished by returning a model name of None.
        model_name, model_value = \
            self.online_aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_name,
                                                                   self._encrypted_password)
        self.assertEquals(model_name, None)

    def testOfflineWlstNames(self):
        # Using offline WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST
        # attribute, regardless of whether the password is encrypted.

        # using encrypted password
        wlst_name, wlst_value = \
            self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password)
        self.assertEqual(wlst_name, self._wlst_password_encrypted_name)

        # using unencrypted password
        wlst_name, wlst_value = \
            self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
        self.assertEquals(wlst_name, self._wlst_password_encrypted_name)

    def testOnlineWlstNames(self):
        # Using online WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST
        # attribute if the password is encrypted, otherwise to Password.

        # using encrypted password
        wlst_name, wlst_value = \
            self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED,
                                                                  self._encrypted_password)
        self.assertEqual(wlst_name, self._wlst_password_encrypted_name)

        # using unencrypted password
        wlst_name, wlst_value = \
            self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
        self.assertEquals(wlst_name, self._wlst_password_name)
Exemplo n.º 29
0
class Discoverer(object):
    """
    Discoverer contains the private methods used to facilitate discovery of the domain information by its subclasses.
    """
    def __init__(self,
                 model_context,
                 base_location,
                 wlst_mode,
                 aliases=None,
                 credential_injector=None):
        """
        :param model_context: context about the model for this instance of discover domain
        :param base_location: to look for common weblogic resources. By default this is the global path or '/'
        :param wlst_mode: offline or online
        :param aliases: optional, aliases object to use
        :param credential_injector: optional, injector to collect credentials
        """
        self._model_context = model_context
        self._base_location = base_location
        self._wlst_mode = wlst_mode
        if aliases:
            self._aliases = aliases
        else:
            self._aliases = Aliases(self._model_context,
                                    wlst_mode=self._wlst_mode,
                                    exception_type=ExceptionType.DISCOVER)
        self._credential_injector = credential_injector
        self._att_handler_map = OrderedDict()
        self._custom_folder = CustomFolderHelper(self._aliases, _logger,
                                                 self._model_context,
                                                 ExceptionType.DISCOVER,
                                                 self._credential_injector)
        self._weblogic_helper = WebLogicHelper(_logger)
        self._wlst_helper = WlstHelper(ExceptionType.DISCOVER)
        self._mbean_utils = MBeanUtils(self._model_context, self._aliases,
                                       ExceptionType.DISCOVER)
        self._wls_version = self._weblogic_helper.get_actual_weblogic_version()

    def discover_domain_mbean(self, model_top_folder_name):
        """
        Discover the domain specific MBean and its configuration attributes.
        :return: model name for domain MBean:dictionary containing the discovered Domain MBean attributes
        """
        _method_name = 'discover_domain_mbean'
        _logger.entering(model_top_folder_name,
                         class_name=_class_name,
                         method_name=_method_name)
        result = OrderedDict()
        location = LocationContext(self._base_location)
        location.append_location(model_top_folder_name)
        name = self._find_singleton_name_in_folder(location)
        if name is not None:
            _logger.info('WLSDPLY-06644',
                         model_top_folder_name,
                         class_name=_class_name,
                         method_name=_method_name)
            location.add_name_token(self._aliases.get_name_token(location),
                                    name)
            self._populate_model_parameters(result, location)
            # if any subfolders exist, discover
            self._discover_subfolders(result, location)
        _logger.exiting(class_name=_class_name, method_name=_method_name)
        return model_top_folder_name, result

    # methods for use only by the subclasses
    def _populate_model_parameters(self, dictionary, location):
        """
        Populate the model dictionary with the attribute values discovered at the current location. Perform
        any special processing for a specific attribute before storing into the model dictionary.
        :param dictionary: where to store the discovered attributes
        :param location: context containing current location information
        :return: dictionary of model attribute name and wlst value
        """
        _method_name = '_populate_model_parameters'
        wlst_path = self._aliases.get_wlst_attributes_path(location)
        _logger.finer('WLSDPLY-06100',
                      wlst_path,
                      class_name=_class_name,
                      method_name=_method_name)

        if not self.wlst_cd(wlst_path, location):
            return

        wlst_lsa_params = self._get_attributes_for_current_location(location)
        _logger.finest('WLSDPLY-06102',
                       self._wlst_helper.get_pwd(),
                       wlst_lsa_params,
                       class_name=_class_name,
                       method_name=_method_name)
        wlst_get_params = self._get_required_attributes(location)
        _logger.finest('WLSDPLY-06103',
                       str(location),
                       wlst_get_params,
                       class_name=_class_name,
                       method_name=_method_name)
        if wlst_lsa_params is not None:
            for wlst_lsa_param in wlst_lsa_params:
                if wlst_lsa_param in wlst_get_params:
                    success, wlst_value = self._get_attribute_value_with_get(
                        wlst_lsa_param, wlst_path)
                    if not success:
                        continue
                else:
                    _logger.finer('WLSDPLY-06131',
                                  wlst_lsa_param,
                                  class_name=_class_name,
                                  method_name=_method_name)
                    wlst_value = wlst_lsa_params[wlst_lsa_param]
                self._add_to_dictionary(dictionary, location, wlst_lsa_param,
                                        wlst_value, wlst_path)

        # These will come after the lsa / get params in the ordered dictionary
        wlst_extra_params = self._get_additional_parameters(location)
        _logger.finest('WLSDPLY-06149',
                       str(location),
                       wlst_extra_params,
                       class_name=_class_name,
                       method_name=_method_name)
        if wlst_extra_params is not None:
            for wlst_extra_param in wlst_extra_params:
                if wlst_extra_param in wlst_get_params:
                    success, wlst_value = self._get_attribute_value_with_get(
                        wlst_extra_param, wlst_path)
                    if success:
                        self._add_to_dictionary(dictionary, location,
                                                wlst_extra_param, wlst_value,
                                                wlst_path)
                    else:
                        _logger.info('WLSDPLY-06152',
                                     wlst_extra_param,
                                     location.get_folder_path(),
                                     class_name=_class_name,
                                     method_name=_method_name)
                elif self._is_defined_attribute(location, wlst_extra_param):
                    _logger.info('WLSDPLY-06154',
                                 wlst_extra_param,
                                 location.get_folder_path(),
                                 class_name=_class_name,
                                 method_name=_method_name)
                else:
                    _logger.info('WLSDPLY-06153',
                                 wlst_extra_param,
                                 location.get_folder_path(),
                                 class_name=_class_name,
                                 method_name=_method_name)

    def _get_attribute_value_with_get(self, wlst_get_param, wlst_path):
        _method_name = '_get_attribute_value_with_get'
        _logger.finest('WLSDPLY-06104',
                       wlst_get_param,
                       class_name=_class_name,
                       method_name=_method_name)
        success = False
        wlst_value = None
        try:
            wlst_value = self._wlst_helper.get(wlst_get_param)
            success = True
        except DiscoverException, pe:
            _logger.warning('WLSDPLY-06127',
                            wlst_get_param,
                            wlst_path,
                            pe.getLocalizedMessage(),
                            class_name=_class_name,
                            method_name=_method_name)
        return success, wlst_value
class AliasPasswordTestCase(unittest.TestCase):
    """
    Test domain-encrypted passwords in a model.
    """

    _logger = PlatformLogger('wlsdeploy.aliases')
    _wls_version = '12.2.1.3'
    _wlst_password_name = "Password"
    _wlst_password_encrypted_name = "PasswordEncrypted"

    _password = '******'
    _encrypted_password = '******'

    def setUp(self):
        model_context = ModelContext("test", {})
        self.aliases = Aliases(model_context,
                               wlst_mode=WlstModes.OFFLINE,
                               wls_version=self._wls_version)
        self.online_aliases = Aliases(model_context,
                                      wlst_mode=WlstModes.ONLINE,
                                      wls_version=self._wls_version)

        self.location = aliases_test.get_jdbc_driver_params_location(
            "Mine", self.aliases)

    def testOfflineModelNames(self):
        # Using offline WLST, only PasswordEncrypted is an attribute, and its value is encrypted.
        # The model name should be PasswordEncrypted.
        model_name, model_value = \
            self.aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_encrypted_name,
                                                            self._encrypted_password)
        self.assertEquals(model_name, PASSWORD_ENCRYPTED)

    def testOnlineModelNames(self):
        # Using online WLST, both Password and PasswordEncrypted are WLST attributes.

        # The PasswordEncrypted WLST attribute should translate to the PasswordEncrypted model attribute.
        model_name, model_value = \
            self.online_aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_encrypted_name,
                                                                   self._encrypted_password)
        self.assertEqual(model_name, PASSWORD_ENCRYPTED)

        # The Password WLST attribute should be skipped, since its value cannot be retrieved.
        # This is accomplished by returning a model name of None.
        model_name, model_value = \
            self.online_aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_name,
                                                                   self._encrypted_password)
        self.assertEquals(model_name, None)

    def testOfflineWlstNames(self):
        # Using offline WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST
        # attribute, regardless of whether the password is encrypted.

        # using encrypted password
        wlst_name, wlst_value = \
            self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password)
        self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
        self.assertEqual(wlst_value, self._encrypted_password)

        # using unencrypted password
        wlst_name, wlst_value = \
            self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
        self.assertEquals(wlst_name, self._wlst_password_encrypted_name)

    def testOnlineWlstNames(self):
        # Using online WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST
        # attribute if the password is encrypted, otherwise to Password.

        # using encrypted password
        wlst_name, wlst_value = \
            self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED,
                                                                  self._encrypted_password)
        self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
        self.assertEqual(wlst_value, self._encrypted_password)

        # using unencrypted password
        wlst_name, wlst_value = \
            self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
        self.assertEquals(wlst_name, self._wlst_password_name)