Skip to content

Commit 3fdbc77

Browse files
author
spoorthy s
committed
Extract memory validation into common function for processor modes
Changes: - Added validate_and_adjust_memory() method to LparConfig class - Validates and adjusts memory values to ensure min <= desired <= max - Maintains consistent validation behavior across both processor modes - Logs warnings when memory values are automatically adjusted Signed-off-by: Spoorthy S <spoorts2@in.ibm.com>
1 parent 1571e81 commit 3fdbc77

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

testcases/MachineConfig.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,34 @@ def __init__(self, cv_HMC=None, system_name=None,
231231
self.util = OpTestUtil(conf)
232232
self.sb_enable = sb_enable
233233

234+
def validate_and_adjust_memory(self, min_memory, desired_memory, max_memory):
235+
'''
236+
Validates and adjusts memory values to ensure min <= desired <= max.
237+
Returns a tuple of (min_memory, desired_memory, max_memory) as strings.
238+
'''
239+
# Convert to integers for comparison and validation
240+
min_mem = int(min_memory)
241+
desired_mem = int(desired_memory)
242+
max_mem = int(max_memory)
243+
244+
# Validate and adjust memory values to ensure min <= desired <= max
245+
if desired_mem > max_mem:
246+
log.warning("desired_memory (%s) exceeds max_memory (%s). Adjusting desired_memory to %s" %
247+
(desired_mem, max_mem, max_mem))
248+
desired_mem = max_mem
249+
250+
if min_mem > desired_mem:
251+
log.warning("min_memory (%s) exceeds desired_memory (%s). Adjusting min_memory to %s" %
252+
(min_mem, desired_mem, desired_mem))
253+
min_mem = desired_mem
254+
255+
if min_mem > max_mem:
256+
log.warning("min_memory (%s) exceeds max_memory (%s). Adjusting min_memory to %s" %
257+
(min_mem, max_mem, max_mem))
258+
min_mem = max_mem
259+
260+
return (str(min_mem), str(desired_mem), str(max_mem))
261+
234262
def LparSetup(self, lpar_config=""):
235263
'''
236264
If cpu=shared is passed in machine_config lpar proc mode
@@ -280,6 +308,11 @@ def LparSetup(self, lpar_config=""):
280308
except AttributeError:
281309
self.max_memory = int(self.cv_HMC.get_available_mem_resources()[
282310
0]) + self.cv_HMC.get_stealable_mem_resources_lpar()
311+
312+
# Use common validation function
313+
self.min_memory, self.desired_memory, self.max_memory = self.validate_and_adjust_memory(
314+
self.min_memory, self.desired_memory, self.max_memory)
315+
283316
proc_mode = 'shared'
284317
self.cv_HMC.profile_bckup()
285318
self.cv_HMC.change_proc_mode(proc_mode, self.sharing_mode,
@@ -330,6 +363,11 @@ def LparSetup(self, lpar_config=""):
330363
except AttributeError:
331364
self.max_memory = int(self.cv_HMC.get_available_mem_resources()[
332365
0]) + self.cv_HMC.get_stealable_mem_resources_lpar()
366+
367+
# Use common validation function
368+
self.min_memory, self.desired_memory, self.max_memory = self.validate_and_adjust_memory(
369+
self.min_memory, self.desired_memory, self.max_memory)
370+
333371
proc_mode = 'ded'
334372
self.cv_HMC.profile_bckup()
335373
self.cv_HMC.change_proc_mode(proc_mode, self.sharing_mode,

0 commit comments

Comments
 (0)