class ValidationTestCase(unittest.TestCase): _program_name = 'validation_test' _class_name = 'ValidationTestCase' _resources_dir = '../../test-classes' # _variable_file = _resources_dir + "/test_sub_variable_file.properties" # _model_file = _resources_dir + '/test_empty.json' # _variable_file = _resources_dir + "/test_invalid_variable_file.properties" # _archive_file = _resources_dir + "/test_jms_archive.zip" def setUp(self): self.name = 'ValidationTestCase' self._logger = PlatformLogger('wlsdeploy.validate') self.wls_helper = WebLogicHelper(self._logger) # add summary handler to validate logger to check results self._summary_handler = SummaryHandler() self._logger.logger.addHandler(self._summary_handler) def tearDown(self): # remove summary handler for next test suite self._logger.logger.removeHandler(self._summary_handler) 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) self.assertNotEqual(return_code, Validator.ReturnCode.STOP)
exit_code = 0 try: # First we enable the stdout again and then redirect the stdoout to a string output stream # call isRestartRequired to get the output, capture the string and then silence wlst output again # __wlst_helper.enable_stdout() sostream = StringOutputStream() System.setOut(PrintStream(sostream)) restart_required = __wlst_helper.is_restart_required() is_restartreq_output = sostream.get_string() __wlst_helper.silence() if model_context.is_rollback_if_restart_required( ) and restart_required: __wlst_helper.cancel_edit() __logger.severe('WLSDPLY_09015', is_restartreq_output) exit_code = CommandLineArgUtil.PROG_ROLLBACK_IF_RESTART_EXIT_CODE else: __wlst_helper.save() __wlst_helper.activate() if restart_required: exit_code = CommandLineArgUtil.PROG_RESTART_REQUIRED except BundleAwareException, ex: __release_edit_session_and_disconnect() raise ex model_deployer.deploy_applications(model, model_context, aliases, wlst_mode=__wlst_mode)
te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) return CommandLineArgUtil.PROG_ERROR_EXIT_CODE variable_file = model_context.get_variable_file() variables = None if variable_file is not None: try: variables = variable_helper.load_variables(variable_file) except VariableException, ve: __logger.severe('WLSDPLY-04207', _program_name, variable_file, ve.getLocalizedMessage(), error=ve, class_name=_class_name, method_name=_method_name) return CommandLineArgUtil.PROG_ERROR_EXIT_CODE try: passphrase = model_context.get_encryption_passphrase() model_change_count, variable_change_count = \ encryption_utils.encrypt_model_dictionary(passphrase, model, variables) except EncryptionException, ee: __logger.severe('WLSDPLY-04208', _program_name, ee.getLocalizedMessage(), error=ee, class_name=_class_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 except VariableException, ve: _logger.severe('WLSDPLY-20009', _program_name, model_file_name, ve.getLocalizedMessage(), error=ve, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception(ve.getLocalizedMessage(), error=ve) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL except TranslateException, pe: _logger.severe('WLSDPLY-20009', _program_name, model_file_name, pe.getLocalizedMessage(), error=pe, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception(pe.getLocalizedMessage(), error=pe) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL obj = ModelDiffer(current_dict, past_dict, aliases) obj.calculate_changed_model() net_diff = obj.get_final_changed_model() print BLANK_LINE print format_message('WLSDPLY-05706', self.current_dict_file, self.past_dict_file) print BLANK_LINE if len(net_diff.keys()) == 0: print format_message('WLSDPLY-05710') print BLANK_LINE return 0
model_dictionary, variables_file_name=None, archive_file_name=model_context.get_archive_file_name()) except ValidateException, ex: __logger.severe('WLSDPLY-20000', _program_name, ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name) __clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) if return_code == Validator.ReturnCode.STOP: __logger.severe('WLSDPLY-20001', _program_name, class_name=_class_name, method_name=_method_name) __clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) def validateRCUArgsAndModel(model_context, model, alias_helper): has_atpdbinfo = 0 domain_info = model[model_constants.DOMAIN_INFO] if domain_info is not None: if model_constants.RCU_DB_INFO in domain_info: rcu_db_info = RcuDbInfo(alias_helper, domain_info[model_constants.RCU_DB_INFO]) has_tns_admin = rcu_db_info.has_tns_admin() has_regular_db = rcu_db_info.is_regular_db() has_atpdbinfo = rcu_db_info.has_atpdbinfo()
ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name) # create a minimal model for summary logging model_context = ModelContext(_program_name, dict()) __log_and_exit(model_context, exit_code, _class_name, _method_name) try: __clear_archive_file(model_context) except DiscoverException, ex: __logger.severe('WLSDPLY-06010', _program_name, model_context.get_archive_file_name(), ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name) __log_and_exit(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE, _class_name, _method_name) aliases = Aliases(model_context, wlst_mode=__wlst_mode) model = None try: model = __discover(model_context, aliases) except DiscoverException, ex: __logger.severe('WLSDPLY-06011', _program_name, model_context.get_domain_name(), model_context.get_domain_home(),
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) cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) cla_helper.clean_up_temp_files() tool_exit.end(model_context, exit_code) return if __name__ == '__main__' or __name__ == 'main': WebLogicDeployToolingVersion.logVersionInfo(_program_name) main(sys.argv)
model_context = None try: 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) __log_and_exit(exit_code, _class_name, _method_name) 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) sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE) inserted, model = __inject(model, model_context) if inserted: __logger.info('WLSDPLY-19604', class_name=_class_name, method_name=_method_name) try: __persist_model(model, model_context) except TranslateException, ex: __logger.severe('WLSDPLY-20024', _program_name, model_context.get_archive_file_name(), ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name) __log_and_exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE, _class_name, _method_name) __close_archive(model_context)
error=ex, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() sys.exit(exit_code) print_usage = model_context.get_print_usage() if print_usage is not None: try: model_validator = Validator(model_context, logger=__logger) model_validator.print_usage(print_usage) except ValidateException, ve: __logger.severe('WLSDPLY-05404', _program_name, ve.getLocalizedMessage(), error=ve, class_name=_class_name, method_name=_method_name) sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE) else: try: model_file_name = model_context.get_model_file() if model_file_name is not None: __perform_model_file_validation(model_file_name, model_context) summary_handler = SummaryHandler.findInstance() if summary_handler is not None: summary_level = summary_handler.getMaximumMessageLevel() if summary_level == Level.SEVERE: exit_code = CommandLineArgUtil.PROG_ERROR_EXIT_CODE
class CompareModelTestCase(unittest.TestCase): _resources_dir = '../../test-classes' _tests_dir = '../../unit-tests' _results_dir = _tests_dir + '/compare' _use_ordering = True def setUp(self): self.name = 'CompareModelTestCase' self._logger = PlatformLogger('wlsdeploy.compare_model') self._program_name = 'CompareModelTestCase' if not os.path.isdir(self._tests_dir): os.mkdir(self._tests_dir) if not os.path.isdir(self._results_dir): os.mkdir(self._results_dir) # add summary handler to validate logger to check results self._summary_handler = SummaryHandler() PlatformLogger('wlsdeploy.validate').logger.addHandler( self._summary_handler) def tearDown(self): # remove summary handler for next test suite PlatformLogger('wlsdeploy.validate').logger.removeHandler( self._summary_handler) def testCompareModelFull(self): _method_name = 'testCompareModelFull' _variables_file = self._resources_dir + '/compare_model_model1.10.properties' _new_model_file = self._resources_dir + '/compare_model_model2.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' 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), 14) self.assertEqual(model_dictionary.has_key('resources'), True) self.assertEqual(model_dictionary.has_key('topology'), True) self.assertEqual(model_dictionary.has_key('appDeployments'), True) self.assertEqual( model_dictionary['topology'].has_key('ServerTemplate'), True) self.assertEqual(model_dictionary['topology'].has_key('Cluster'), True) self.assertEqual( model_dictionary['topology']['ServerTemplate'].has_key( 'cluster-1-template'), True) self.assertEqual( model_dictionary['topology']['Cluster'].has_key('cluster-2'), 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['resources'].has_key('JMSSystemResource'), True) self.assertEqual( model_dictionary['resources']['JMSSystemResource'].has_key( 'MyJmsModule'), True) self.assertEqual( model_dictionary['resources'].has_key('SingletonService'), 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) self.assertEqual( model_dictionary['appDeployments']['Application'] ['myear'].has_key('ModuleType'), False) 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) if os.path.exists(_temp_dir): shutil.rmtree(_temp_dir) self.assertEqual(return_code, 0)
tool_exit.end(model_context, rc) except CLAException, ex: exit_code = 2 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() tool_exit.end(model_context, exit_code) except CompareException, ce: cla_helper.clean_up_temp_files() __logger.severe('WLSDPLY-05801', ce.getLocalizedMessage()) tool_exit.end(model_context, 2) except PyWLSTException, pe: cla_helper.clean_up_temp_files() __logger.severe('WLSDPLY-05801', pe.getLocalizedMessage()) tool_exit.end(model_context, 2) except: exc_type, exc_obj, exc_tb = sys.exc_info() eeString = traceback.format_exception(exc_type, exc_obj, exc_tb) cla_helper.clean_up_temp_files() __logger.severe('WLSDPLY-05801', eeString) tool_exit.end(model_context, 2) def format_message(key, *args): """
class OdlDeployer(object): """ Handle the ODL validation and configuration. """ __class_name = 'OdlHelper' def __init__(self, model, model_context, aliases, wlst_mode): self.model = model self.model_context = model_context self.aliases = aliases self.logger = PlatformLogger('wlsdeploy.deploy') self.wlst_mode = wlst_mode def configure_odl(self, parent_dict, parent_location): """ Apply the ODL configuration section of the model, if present. :param parent_dict: the model dictionary that may contains ODL configuration :param parent_location: the alias location of the parent dictionary (used for logging paths) """ _method_name = 'configure_odl' self.logger.entering(class_name=self.__class_name, method_name=_method_name) odl_info = dictionary_utils.get_dictionary_element( parent_dict, ODL_CONFIGURATION) if len(odl_info): typedef = self.model_context.get_domain_typedef() if not (typedef.is_jrf_domain_type() or typedef.is_restricted_jrf_domain_type()): self.logger.info('WLSDPLY-19709', class_name=self.__class_name, method_name=_method_name) elif self.wlst_mode == WlstModes.ONLINE: self.logger.info('WLSDPLY-19700', class_name=self.__class_name, method_name=_method_name) else: for config in odl_info: self._update_config(config, odl_info[config], parent_location) self.logger.exiting(class_name=self.__class_name, method_name=_method_name) return def _update_config(self, config_name, config_dictionary, parent_location): _method_name = '_update_config' config_location = LocationContext(parent_location).append_location( ODL_CONFIGURATION) token = self.aliases.get_name_token(config_location) config_location.add_name_token(token, config_name) servers = dictionary_utils.get_element(config_dictionary, _SERVERS) if servers is not None: servers_list = alias_utils.convert_to_type( 'list', servers, delimiter=MODEL_LIST_DELIMITER) for server in servers_list: self.logger.info('WLSDPLY-19708', ODL_CONFIGURATION, config_name, server, class_name=self.__class_name, method_name=_method_name) self._update_server(server, config_dictionary, config_location) def _update_server(self, name, dictionary, config_location): _method_name = '_update_server' # these imports are local, since they are only present in JRF environments. # this method is only called after that check has been made. from oracle.core.ojdl.weblogic.ODLConfiguration import CONFIG_DIR from oracle.core.ojdl.weblogic.ODLConfiguration import CONFIG_FILE from oracle.core.ojdl.logging.config import LoggingConfigurationDocument config_dir = File(self.model_context.get_domain_home(), CONFIG_DIR) server_dir = File(config_dir, name) config_file = File(server_dir, CONFIG_FILE) log_template_dir = config_dir.getParentFile() try: if config_file.exists(): source_file = config_file FileUtils.validateWritableFile(config_file.getPath()) else: # for dynamic servers, the logging config does not exist until the server is started. # read the from template file, verify that the server directory is present and writable. source_file = File(log_template_dir, LOGGING_TEMPLATE_FILE) FileUtils.validateExistingFile(source_file) if not server_dir.exists() and not server_dir.mkdirs(): ex = exception_helper.create_deploy_exception( 'WLSDPLY-19710', server_dir) self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name) raise ex FileUtils.validateWritableDirectory(server_dir.getPath()) document = LoggingConfigurationDocument( FileInputStream(source_file)) # configure AddJvmNumber add_jvm_number = dictionary_utils.get_element( dictionary, _ADD_JVM_NUMBER) if add_jvm_number is not None: document.setAddJvmNumber( alias_utils.convert_boolean(add_jvm_number)) # configure HandlerDefaults handler_defaults = dictionary_utils.get_dictionary_element( dictionary, _HANDLER_DEFAULTS) if handler_defaults is not None: for key in handler_defaults: value = handler_defaults[key] document.setHandlerDefault(key, _get_property_text(value)) # configure Handlers # do these before loggers, in case new handlers are assigned to loggers existing_handler_names = document.getHandlerNames() handlers = dictionary_utils.get_dictionary_element( dictionary, _HANDLER) if handlers is not None: for handler_name in handlers: handler = handlers[handler_name] self._configure_handler(handler_name, handler, document, existing_handler_names, config_location) # configure Loggers existing_logger_names = document.getLoggerNames() loggers = dictionary_utils.get_dictionary_element( dictionary, _LOGGER) if loggers is not None: for logger_name in loggers: logger = loggers[logger_name] self._configure_logger(logger_name, logger, document, existing_logger_names, config_location) document.writeDocument(FileOutputStream(config_file)) except (ParserConfigurationException, SAXException, IOException, IllegalArgumentException), ex: self.logger.severe('WLSDPLY-19707', name, ex.getLocalizedMessage(), class_name=self.__class_name, method_name=_method_name) return
class ValidationTestCase(unittest.TestCase): _program_name = 'validation_test' _class_name = 'ValidationTestCase' _resources_dir = '../../test-classes' # Model persistence file _wlsdeply_store_model = os.path.abspath( os.getcwd()) + '/' + _resources_dir + '/validate-mii-model.json' # _variable_file = _resources_dir + "/test_sub_variable_file.properties" # _model_file = _resources_dir + '/test_empty.json' # _variable_file = _resources_dir + "/test_invalid_variable_file.properties" # _archive_file = _resources_dir + "/test_jms_archive.zip" def setUp(self): self.name = 'ValidationTestCase' self._logger = PlatformLogger('wlsdeploy.validate') self.wls_helper = WebLogicHelper(self._logger) # add summary handler to validate logger to check results self._summary_handler = SummaryHandler() self._logger.logger.addHandler(self._summary_handler) # Define custom configuration path for WDT os.environ['WDT_CUSTOM_CONFIG'] = self._resources_dir # Indicate that WDT should persist model file os.environ['__WLSDEPLOY_STORE_MODEL__'] = self._wlsdeply_store_model def tearDown(self): # remove summary handler for next test suite self._logger.logger.removeHandler(self._summary_handler) # Clean up temporary WDT custom configuration environment variables # and model persistence files del os.environ['WDT_CUSTOM_CONFIG'] del os.environ['__WLSDEPLOY_STORE_MODEL__'] self.deleteFile(self._wlsdeply_store_model) 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) self.assertNotEqual(return_code, Validator.ReturnCode.STOP)