Skip to content

Commit 48a7b04

Browse files
Add a few corrections and a unit test for aliases get default value
1 parent 418be84 commit 48a7b04

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

core/src/main/python/wlsdeploy/tool/util/variable_injector.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ def __init__(self, program_name, model, model_context=None, version=None):
9292
self.__original = copy.deepcopy(model)
9393
self.__model = model
9494
self.__model_context = model_context
95+
if self.__model_context:
96+
self.__wlst_mode = self.__model_context.get_target_wlst_mode()
97+
else:
98+
self.__wlst_mode = WlstModes.OFFLINE
9599
self.__section_keys = model_sections.get_model_top_level_keys()
96100
self.__section_keys.remove(model_sections.get_model_domain_info_key())
97101

98102
if version:
99-
self.__aliases = Aliases(model_context, WlstModes.OFFLINE, version, None)
103+
self.__aliases = Aliases(model_context, self.__wlst_mode, version, None)
100104
else:
101105
self.__aliases = Aliases(model_context)
102106

@@ -526,26 +530,25 @@ def _check_insert_attribute_model(self, location, model_section, attribute, inje
526530
_method_name = '_check_insert_attribute_model'
527531
if attribute not in model_section and (FORCE in injector_values and Boolean(injector_values[FORCE])):
528532
value = self.__aliases.get_model_attribute_default_value(location, attribute)
529-
# This is the best I can do - need a get_default_value_model function(location, attribute)
530-
__, wlst_value = self.__aliases.get_wlst_attribute_name_and_value(location, attribute, value)
531-
_logger.fine('WLSDPLY-19540', attribute, location.get_folder_path(), wlst_value,
533+
_logger.fine('WLSDPLY-19540', attribute, location.get_folder_path(), value,
532534
class_name=_class_name, method_name=_method_name)
533-
model_section[attribute] = wlst_value
535+
model_section[attribute] = value
534536

535537
def _check_replace_variable_value(self, location, attribute, variable_value, injector_values):
536538
_method_name = '_format_variable_value'
539+
value = variable_value
537540
if VARIABLE_VALUE in injector_values:
538541
value = injector_values[VARIABLE_VALUE]
539542
# might add code to call a method to populate the replacement value
540543
try:
541-
self.__aliases.get_wlst_attribute_name_and_value(location, attribute, value)
542-
variable_value = value
544+
wlst_attribute_name = self.__aliases.get_wlst_attribute_name(location, attribute)
545+
__, value = self.__aliases.get_model_attribute_name_and_value(location, wlst_attribute_name, value)
543546
_logger.fine('WLSDPLY-19542', value, variable_value, attribute, location.get_folder_path(),
544547
class_name=_class_name, method_name=_method_name)
545548
except AliasException, ae:
546549
_logger.warning('WLSDPLY-19541', value, attribute, location, ae.getLocalizedMessage(),
547550
class_name=_class_name, method_name=_method_name)
548-
return variable_value
551+
return value
549552

550553

551554
def get_default_variable_injector_file_name(variable_injector_file_name=VARIABLE_INJECTOR_FILE_NAME):

core/src/test/python/variable_injector_test.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
"""
5-
import os
65
import unittest
76

87
import wlsdeploy.util.variables as variables
@@ -156,10 +155,10 @@ def testWithSegmentInList(self):
156155
variable_injector.REGEXP] = [list_entry]
157156
actual = self._helper.inject_variables(replacement_dict)
158157
self._compare_to_expected_dictionary(expected, actual)
159-
list = self._model['resources']['WLDFSystemResource']['MyWldfModule']['WLDFResource']['Harvester'][
158+
wldf_list = self._model['resources']['WLDFSystemResource']['MyWldfModule']['WLDFResource']['Harvester'][
160159
'HarvestedType']['weblogic.management.runtime.ServerRuntimeMBean']['HarvestedAttribute']
161160
found = False
162-
for entry in list:
161+
for entry in wldf_list:
163162
if entry == '@@PROP:WLDFSystemResource.MyWldfModule.WLDFResource.Harvester.HarvestedType.' \
164163
'weblogic.management.runtime.ServerRuntimeMBean.HarvestedAttribute@@':
165164
found = True
@@ -179,11 +178,10 @@ def testWithSegmentInStringInList(self):
179178
variable_injector.REGEXP] = [list_entry]
180179
actual = self._helper.inject_variables(replacement_dict)
181180
self._compare_to_expected_dictionary(expected, actual)
182-
list = \
183-
self._model['resources']['WLDFSystemResource']['MyWldfModule']['WLDFResource']['Harvester']['HarvestedType'][
184-
'weblogic.management.runtime.ServerRuntimeMBean']['HarvestedInstance']
181+
wldf_list = self._model['resources']['WLDFSystemResource']['MyWldfModule']['WLDFResource']['Harvester'][
182+
'HarvestedType']['weblogic.management.runtime.ServerRuntimeMBean']['HarvestedInstance']
185183
found = False
186-
for entry in list:
184+
for entry in wldf_list:
187185
if entry == 'com.bea:Name=@@PROP:WLDFSystemResource.MyWldfModule.WLDFResource.Harvester.HarvestedType.' \
188186
'weblogic.management.runtime.ServerRuntimeMBean.HarvestedInstance--ManagedServer@@' \
189187
',Type=ServerRuntime':
@@ -246,7 +244,6 @@ def testWithVariableHelperKeywords(self):
246244
self.assertEqual(self._variable_file, variable_file_name)
247245
self.assertEqual(True, inserted)
248246
actual = variables.load_variables(self._variable_file)
249-
print actual
250247
self._compare_to_expected_dictionary(expected, actual)
251248

252249
def testForceAttribute(self):
@@ -260,6 +257,15 @@ def testForceAttribute(self):
260257
actual = self._helper.inject_variables(replacement_dict)
261258
self._compare_to_expected_dictionary(expected, actual)
262259

260+
def testForceAttributeWithTwoDefaults(self):
261+
expected = dict()
262+
expected['JMSSystemResource.MyJmsModule.JmsResource.Template.JmsTemplate.MaximumMessageSize'] = '0'
263+
replacement_dict = dict()
264+
replacement_dict['JMSSystemResource.JmsResource.Template.MaximumMessageSize'] = dict()
265+
replacement_dict['JMSSystemResource.JmsResource.Template.MaximumMessageSize'][variable_injector.FORCE] = True
266+
actual = self._helper.inject_variables(replacement_dict)
267+
self._compare_to_expected_dictionary(expected, actual)
268+
263269
def testReplaceVariableValueAttribute(self):
264270
expected = dict()
265271
expected[
@@ -272,6 +278,7 @@ def testReplaceVariableValueAttribute(self):
272278
'JNDIProperty[java.naming.security.principal].Value'][
273279
variable_injector.VARIABLE_VALUE] = 'k8s'
274280
actual = self._helper.inject_variables(replacement_dict)
281+
print actual
275282
self._compare_to_expected_dictionary(expected, actual)
276283

277284
def testReplaceVariableValueSegmentInString(self):
@@ -283,8 +290,8 @@ def testReplaceVariableValueSegmentInString(self):
283290
list_entry = dict()
284291
list_entry[variable_injector.REGEXP_PATTERN] = '(?<=HOST=)[\w.-]+(?=\))'
285292
list_entry[variable_injector.REGEXP_SUFFIX] = 'Host'
286-
replacement_dict['JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'][variable_injector.REGEXP] = [
287-
list_entry]
293+
replacement_dict['JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'][
294+
variable_injector.REGEXP] = [list_entry]
288295
replacement_dict['JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'][
289296
variable_injector.VARIABLE_VALUE] = 'den00chv'
290297
actual = self._helper.inject_variables(replacement_dict)

core/src/test/resources/variable_insertion.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ topology:
3535
SSL:
3636
Enabled: true
3737
ListenPort: 9004
38+
DefaultFileStore:
39+
InitialSize: 512
3840
ListenPort: 9003
3941
AdminServer:
4042
ListenAddress: 127.0.0.1
@@ -44,6 +46,13 @@ topology:
4446
ListenPort: 9002
4547
ListenPort: 9001
4648
resources:
49+
SelfTuning:
50+
MaxThreadsConstraint:
51+
ThreeMax:
52+
Count: 3
53+
WorkManager:
54+
MaxThWM:
55+
Target: mycluster
4756
MailSession:
4857
MyMailSession:
4958
Properties:
@@ -97,6 +106,9 @@ resources:
97106
Key: bar
98107
Value: True
99108
JNDIPropertiesCredentialEncrypted: '--FIX ME--'
109+
Template:
110+
JmsTemplate:
111+
InsertionPausedAtStartup: true
100112
JDBCSystemResource:
101113
Database1:
102114
DescriptorFileName: 'jdbc/Database1-3195-jdbc.xml'

0 commit comments

Comments
 (0)