def testMergeDifferentProperties(self): dictionary = _build_model_one('@@PROP:server1a@@') new_dictionary = _build_model_two('@@PROP:server1b@@') variables = _build_variable_map() cla_helper.merge_model_dictionaries(dictionary, new_dictionary, variables) # print("Merged model: " + str(dictionary)) self._check_merged_server(dictionary, '@@PROP:server1a@@')
def testMergeNameToDeletedName(self): dictionary = _build_delete_model('m1') new_dictionary = _build_model_two('m1') variables = {} cla_helper.merge_model_dictionaries(dictionary, new_dictionary, variables) # print("Merged model: " + str(dictionary)) server = self._check_single_server(dictionary, 'm1') self.assertEquals(2, len(server), "server should have two attributes")
def testMergeDeletedNameToName(self): dictionary = _build_model_one('m1') new_dictionary = _build_delete_model('m1') variables = {} cla_helper.merge_model_dictionaries(dictionary, new_dictionary, variables) # print("Merged model: " + str(dictionary)) servers = dictionary['Servers'] self.assertEquals(0, len(servers), "there should be no servers after delete")
def testMergeMatchingProperties(self): dictionary = _build_model_one('@@PROP:server1@@') new_dictionary = _build_model_two('@@PROP:server1@@') variables = {} # no variables are needed to resolve this cla_helper.merge_model_dictionaries(dictionary, new_dictionary, variables) # print("Merged model: " + str(dictionary)) servers = dictionary['Servers'] self.assertEquals(1, len(servers), "there should be one server") self._check_merged_server(dictionary, '@@PROP:server1@@')
def testMergeModels(self): dictionary = { "Servers": { "m1": { "ListenPort": 9000, "ListenDelaySecs": 5 }, "m2": { "ListenPort": 9002 } } } new_dictionary = { "Servers": { "m1": { "ListenPort": 9001, "MaxOpenSockCount": 7, }, "m3": { "ListenPort": 9003 } } } variables = {} cla_helper.merge_model_dictionaries(dictionary, new_dictionary, variables) # print("Merged model: " + str(dictionary)) servers = dictionary['Servers'] m1 = servers['m1'] self.assertEquals(9001, m1['ListenPort'], "m1 should have listen port 9001") self.assertEquals(5, m1['ListenDelaySecs'], "m1 should have listen delay secs 5") self.assertEquals(7, m1['MaxOpenSockCount'], "m1 should have max open sock count 7") self.assertEquals(9002, servers['m2']['ListenPort'], "m2 should be in model, listen port 9002") self.assertEquals(9003, servers['m3']['ListenPort'], "m3 should be in model, listen port 9003")
def walk(self): """ Replace password attributes in each model file with secret tokens, and write each model. Generate a script to create the required secrets. Create any additional output specified for the target environment. """ _method_name = "walk" model_file_name = None # create a merged model that is not substituted merged_model_dictionary = {} try: model_file_list = self.model_files.split(',') for model_file in model_file_list: if os.path.splitext(model_file)[1].lower() == ".yaml": model_file_name = model_file FileToPython(model_file_name, True).parse() aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE) validator = Validator(self.model_context, aliases, wlst_mode=WlstModes.OFFLINE) # Just merge and validate but without substitution model_dictionary = cla_helper.merge_model_files(model_file_name, None) variable_file = self.model_context.get_variable_file() if not os.path.exists(variable_file): variable_file = None return_code = validator.validate_in_tool_mode(model_dictionary, variables_file_name=variable_file, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: self._logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL self.current_dict = model_dictionary self.__walk_model_section(model.get_model_domain_info_key(), self.current_dict, aliases.get_model_section_top_level_folder_names(DOMAIN_INFO)) self.__walk_model_section(model.get_model_topology_key(), self.current_dict, aliases.get_model_topology_top_level_folder_names()) self.__walk_model_section(model.get_model_resources_key(), self.current_dict, aliases.get_model_resources_top_level_folder_names()) self.current_dict = self._apply_filter_and_inject_variable(self.current_dict, self.model_context) file_name = os.path.join(self.output_dir, os.path.basename(model_file_name)) fos = JFileOutputStream(file_name, False) writer = JPrintWriter(fos, True) pty = PythonToYaml(self.current_dict) pty._write_dictionary_to_yaml_file(self.current_dict, writer) writer.close() cla_helper.merge_model_dictionaries(merged_model_dictionary, self.current_dict, None) # filter variables or secrets that are no longer in the merged, filtered model filter_helper.apply_filters(merged_model_dictionary, "discover", self.model_context) self.credential_injector.filter_unused_credentials(merged_model_dictionary) # use a merged, substituted, filtered model to get domain name and create additional target output. full_model_dictionary = cla_helper.load_model(_program_name, self.model_context, self._aliases, "discover", WlstModes.OFFLINE) target_config = self.model_context.get_target_configuration() if target_config.uses_credential_secrets(): target_configuration_helper.generate_k8s_script(self.model_context, self.credential_injector.get_variable_cache(), full_model_dictionary, ExceptionType.VALIDATE) # create any additional outputs from full model dictionary target_configuration_helper.create_additional_output(Model(full_model_dictionary), self.model_context, self._aliases, self.credential_injector, ExceptionType.VALIDATE) except ValidateException, te: self._logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception(te.getLocalizedMessage(), error=te) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL