From 1d15dff06f9e8ec996e348bf988f640c8df28c80 Mon Sep 17 00:00:00 2001 From: Samir Mulani Date: Mon, 6 Nov 2023 12:51:09 -0600 Subject: [PATCH] Added support to configure the multiple lpars. Addressed review comments. 1. Fixed indentation issues. 2. Removed unwanted debug print statement. Signed-off-by: Samir Mulani --- testcases/MachineConfig.py | 154 ++++++++++++++++++++++--------------- 1 file changed, 91 insertions(+), 63 deletions(-) diff --git a/testcases/MachineConfig.py b/testcases/MachineConfig.py index 78844beb5..b5354878e 100755 --- a/testcases/MachineConfig.py +++ b/testcases/MachineConfig.py @@ -40,6 +40,7 @@ log = OpTestLogger.optest_logger_glob.get_logger(__name__) + class MachineConfig(unittest.TestCase): def setUp(self): @@ -48,7 +49,7 @@ def setUp(self): self.cv_SYSTEM = conf.system() self.bmc_type = conf.args.bmc_type self.machine_config = json.loads(conf.args.machine_config) - if self.bmc_type == "FSP_PHYP" or self.bmc_type == "EBMC_PHYP" : + if self.bmc_type == "FSP_PHYP" or self.bmc_type == "EBMC_PHYP": self.hmc_user = conf.args.hmc_username self.hmc_password = conf.args.hmc_password self.hmc_ip = conf.args.hmc_ip @@ -57,7 +58,8 @@ def setUp(self): self.cv_HMC = self.cv_SYSTEM.hmc self.lpar_prof = conf.args.lpar_prof self.lpar_flag = False - try: self.lpar_list = conf.args.lpar_list + try: + self.lpar_list = conf.args.lpar_list except AttributeError: self.lpar_list = "" self.util = OpTestUtil(conf) @@ -73,7 +75,8 @@ def validate_secureboot_parameter(self, machine_config): False - if secureboot is set to 'off' ''' sb_valid_states = ['on', 'off'] - secureboot_parameter_state = re.findall("secureboot=[a-z][a-z]+", str(machine_config))[0].split('=')[1] + secureboot_parameter_state = re.findall( + "secureboot=[a-z][a-z]+", str(machine_config))[0].split('=')[1] if str(secureboot_parameter_state) not in sb_valid_states: self.skipTest("%s is not a valid state for secureboot. " "Secureboot valid states can be either set to 'on' or 'off'" % str(secureboot_parameter_state)) @@ -81,21 +84,21 @@ def validate_secureboot_parameter(self, machine_config): return True else: return False - - def update_hmc_object(self, target_hmc_ip, target_hmc_username, target_hmc_password, - managed_system, lpar_name): + + def update_hmc_object(self, target_hmc_ip, target_hmc_username, target_hmc_password, + managed_system, lpar_name): """ In case of multi lpar configuration here we are creating multiple objects[In sequence] as per lpar change. """ conf = OpTestConfiguration.conf self.cv_HMC = OpTestHMC.OpTestHMC(target_hmc_ip, - target_hmc_username, - target_hmc_password, - managed_system=managed_system, - lpar_name=lpar_name, - lpar_prof=conf.args.lpar_prof - ) + target_hmc_username, + target_hmc_password, + managed_system=managed_system, + lpar_name=lpar_name, + lpar_prof=conf.args.lpar_prof + ) self.cv_HMC.set_system(conf.system()) def runTest(self): @@ -105,7 +108,8 @@ def runTest(self): self.lpar_flag = True for lpar in self.lpar_list: lpar = lpar.strip() - self.update_hmc_object(self.hmc_ip, self.hmc_user, self.hmc_password, self.system_name, lpar) + self.update_hmc_object( + self.hmc_ip, self.hmc_user, self.hmc_password, self.system_name, lpar) for key in self.machine_config: self.callConfig(key, lpar) else: @@ -114,39 +118,43 @@ def runTest(self): def callConfig(self, key, lpar=""): - if lpar !="": + if lpar != "": self.lpar_name = lpar - - status=0 + + status = 0 if key == "lpar": self.sb_enable = None - config_value=self.machine_config['lpar'] + config_value = self.machine_config['lpar'] if 'secureboot' in config_value: - self.sb_enable = self.validate_secureboot_parameter(self.machine_config) - status=LparConfig(self.cv_HMC,self.system_name,self.lpar_name,self.lpar_prof,self.machine_config['lpar'],sb_enable=self.sb_enable).LparSetup(self.lpar_flag) + self.sb_enable = self.validate_secureboot_parameter( + self.machine_config) + status = LparConfig(self.cv_HMC, self.system_name, self.lpar_name, self.lpar_prof, + self.machine_config['lpar'], sb_enable=self.sb_enable).LparSetup(self.lpar_flag) if status: self.fail(status) if key == "cec": - lmb_size= None + lmb_size = None num_hugepages = None setup = 0 if not self.cv_HMC.lpar_vios: self.skipTest("Please pass lpar_vios in config file.") - config_value=self.machine_config['cec'] + config_value = self.machine_config['cec'] valid_size = [128, 256, 1024, 2048, 4096] if "lmb" in config_value: setup = 1 - lmb_size = re.findall('lmb=[0-9]+', str(self.machine_config))[0].split('=')[1] + lmb_size = re.findall( + 'lmb=[0-9]+', str(self.machine_config))[0].split('=')[1] if int(lmb_size) not in valid_size: self.skipTest("%s is not valid lmb size, " "valid lmb sizes are 128, 256, 1024, 2048, 4096" % lmb_size) if "hugepages" in config_value: setup = 1 num_hugepages = re.findall( - 'hugepages=[0-9]+', str(self.machine_config))[0].split('=')[1] + 'hugepages=[0-9]+', str(self.machine_config))[0].split('=')[1] - status = CecConfig(self.cv_HMC,self.system_name,self.lpar_name,self.lpar_prof,lmb=lmb_size,hugepages=num_hugepages).CecSetup() + status = CecConfig(self.cv_HMC, self.system_name, self.lpar_name, + self.lpar_prof, lmb=lmb_size, hugepages=num_hugepages).CecSetup() if status: self.fail(status) if not setup: @@ -167,8 +175,10 @@ def callConfig(self, key, lpar=""): "valid hugepage sizes are 1G, 2M, 16M, 16G" % hugepage_size) if 'secureboot' in config_value: setup = 1 - sb_enable = self.validate_secureboot_parameter(self.machine_config) - status = OsConfig(self.cv_HMC, self.system_name, self.lpar_name, self.lpar_prof, self.machine_config['os'],enable=sb_enable, hugepage=hugepage_size).Ossetup() + sb_enable = self.validate_secureboot_parameter( + self.machine_config) + status = OsConfig(self.cv_HMC, self.system_name, self.lpar_name, self.lpar_prof, + self.machine_config['os'], enable=sb_enable, hugepage=hugepage_size).Ossetup() if status: self.fail(status) if not setup: @@ -184,13 +194,14 @@ class LparConfig(): vpmem=0 or vpmem=1 Ex: machine_config="cpu=dedicated,vtpm=1,vpmem=1" ''' - def __init__(self, cv_HMC=None, system_name= None, - lpar_name=None, lpar_prof=None, machin_config =None, sb_enable=None): + + def __init__(self, cv_HMC=None, system_name=None, + lpar_name=None, lpar_prof=None, machin_config=None, sb_enable=None): self.cv_HMC = cv_HMC self.system_name = system_name self.lpar_name = lpar_name self.lpar_prof = lpar_prof - self.machine_config=machin_config + self.machine_config = machin_config self.hmc_con = self.cv_HMC.ssh conf = OpTestConfiguration.conf self.cv_SYSTEM = conf.system() @@ -212,30 +223,34 @@ def LparSetup(self, lpar_config=""): proc_mode = None if "cpu=shared" in self.machine_config: conf = OpTestConfiguration.conf - try: self.sharing_mode = conf.args.sharing_mode + try: + self.sharing_mode = conf.args.sharing_mode except AttributeError: self.sharing_mode = "cap" - try: self.min_proc_units = float(conf.args.min_proc_units) + try: + self.min_proc_units = float(conf.args.min_proc_units) except AttributeError: self.min_proc_units = 1.0 - try: self.desired_proc_units = float(conf.args.desired_proc_units) + try: + self.desired_proc_units = float(conf.args.desired_proc_units) except AttributeError: self.desired_proc_units = 2.0 - try: self.max_proc_units = float(conf.args.max_proc_units) + try: + self.max_proc_units = float(conf.args.max_proc_units) except AttributeError: self.max_proc_units = 2.0 - try: self.overcommit_ratio = int(conf.args.overcommit_ratio) + try: + self.overcommit_ratio = int(conf.args.overcommit_ratio) except AttributeError: self.overcommit_ratio = 1 proc_mode = 'shared' curr_proc_mode = self.cv_HMC.get_proc_mode() - print("==========================> samir===========================###########################: ", lpar_config) - if proc_mode in curr_proc_mode and lpar_config == True: + if proc_mode in curr_proc_mode and lpar_config == True: log.info("System is already booted in shared mode.") else: self.cv_HMC.profile_bckup() self.cv_HMC.change_proc_mode(proc_mode, self.sharing_mode, self.min_proc_units, - self.desired_proc_units, self.max_proc_units, self.overcommit_ratio) + self.desired_proc_units, self.max_proc_units, self.overcommit_ratio) ''' If cpu=dedicated is passed in machine_config lpar proc mode changes to dedicated mode. @@ -249,16 +264,20 @@ def LparSetup(self, lpar_config=""): if "cpu=dedicated" in self.machine_config: conf = OpTestConfiguration.conf - try: self.sharing_mode = conf.args.sharing_mode + try: + self.sharing_mode = conf.args.sharing_mode except AttributeError: self.sharing_mode = "share_idle_procs" - try: self.min_proc_units = conf.args.min_proc_units + try: + self.min_proc_units = conf.args.min_proc_units except AttributeError: self.min_proc_units = "1" - try: self.desired_proc_units = conf.args.desired_proc_units + try: + self.desired_proc_units = conf.args.desired_proc_units except AttributeError: self.desired_proc_units = "2" - try: self.max_proc_units = conf.args.max_proc_units + try: + self.max_proc_units = conf.args.max_proc_units except AttributeError: self.max_proc_units = "2" proc_mode = 'ded' @@ -270,7 +289,6 @@ def LparSetup(self, lpar_config=""): self.cv_HMC.change_proc_mode(proc_mode, self.sharing_mode, self.min_proc_units, self.desired_proc_units, self.max_proc_units) - if "vtpm=1" in self.machine_config: conf = OpTestConfiguration.conf vtpm_enabled = self.cv_HMC.vtpm_state() @@ -280,14 +298,16 @@ def LparSetup(self, lpar_config=""): proc_compat_mode = self.cv_HMC.get_proc_compat_mode() if "POWER10" in proc_compat_mode: self.vtpm_version = 2.0 - try: self.vtpm_encryption = conf.args.vtpm_encryption + try: + self.vtpm_encryption = conf.args.vtpm_encryption except AttributeError: self.vtpm_encryption = "Power10v1" elif proc_compat_mode[0] in ["POWER9_base", "POWER9", "POWER8"]: self.vtpm_version = 1.2 else: log.info("Unknown processor compact mode") - self.cv_HMC.enable_vtpm(self.vtpm_version, self.vtpm_encryption) + self.cv_HMC.enable_vtpm( + self.vtpm_version, self.vtpm_encryption) vtpm_enabled = self.cv_HMC.vtpm_state() if vtpm_enabled[0] == "1": log.info("System booted with VTPM enabled") @@ -309,13 +329,15 @@ def LparSetup(self, lpar_config=""): if "vpmem=1" in self.machine_config: conf = OpTestConfiguration.conf - try: self.pmem_name = conf.args.pmem_name + try: + self.pmem_name = conf.args.pmem_name except AttributeError: self.pmem_name = "vol1" - try: self.pmem_size = conf.args.pmem_size + try: + self.pmem_size = conf.args.pmem_size except AttributeError: self.pmem_size = "8192" - if self.cv_HMC.vpmem_count() [0] >= "1": + if self.cv_HMC.vpmem_count()[0] >= "1": self.cv_HMC.remove_vpmem() current_lmb = self.cv_HMC.get_lmb_size() if int(self.pmem_size) % int(current_lmb[0]) != 0: @@ -323,13 +345,15 @@ def LparSetup(self, lpar_config=""): self.cv_HMC.configure_vpmem(self.pmem_name, self.pmem_size) curr_num_volumes = self.cv_HMC.vpmem_count() if curr_num_volumes[0] >= "1": - log.info("Configured vpmem %s of %sMB" % (self.pmem_name, self.pmem_size)) + log.info("Configured vpmem %s of %sMB" % + (self.pmem_name, self.pmem_size)) else: return "Failed to configure pmem" if "nx_gzip" in self.machine_config: conf = OpTestConfiguration.conf - try: self.qos_credits = round(float(conf.args.qos_credits)) + try: + self.qos_credits = round(float(conf.args.qos_credits)) except AttributeError: self.qos_credits = 10 proc_compat_mode = self.cv_HMC.get_proc_compat_mode() @@ -343,16 +367,17 @@ def LparSetup(self, lpar_config=""): """ if "slot=" in self.machine_config: - ioslot_drc_names = "".join(self.machine_config[self.machine_config.index("slot=")+len("slot=")+1:]) + ioslot_drc_names = "".join( + self.machine_config[self.machine_config.index("slot=")+len("slot=")+1:]) ioslot_drc_names = ",".join(ioslot_drc_names[:ioslot_drc_names.index("=")].split(",")[:-1]) \ if "=" in ioslot_drc_names else ioslot_drc_names self.cv_HMC.add_ioslot(ioslot_drc_names) - if self.sb_enable is not None : + if self.sb_enable is not None: self.cv_HMC.hmc_secureboot_on_off(self.sb_enable) - + self.cv_HMC.run_command("chsysstate -r lpar -m %s -o on -n %s -f %s" % - (self.system_name, self.lpar_name, self.lpar_prof)) + (self.system_name, self.lpar_name, self.lpar_prof)) time.sleep(5) curr_proc_mode = self.cv_HMC.get_proc_mode() if proc_mode: @@ -377,6 +402,7 @@ def runTest(self): self.cv_HMC.lpar_prof = self.cv_HMC.lpar_prof + "_bck" self.cv_HMC.poweron_lpar() + class CecConfig(): ''' @@ -388,7 +414,8 @@ class CecConfig(): in config file Ex: machine_config={"cec":"hugepages=4"} ''' - def __init__(self, cv_HMC=None, system_name= None, + + def __init__(self, cv_HMC=None, system_name=None, lpar_name=None, lpar_prof=None, lmb=None, hugepages=None): self.cv_HMC = cv_HMC @@ -412,7 +439,7 @@ def CecSetup(self): if self.setup: self.cv_HMC.poweron_system() self.ValidateCEC_Setup() - ##loading system + # loading system self.cv_HMC.run_command("chsysstate -r lpar -m %s -o on -n %s -f %s" % (self.system_name, self.lpar_name, self.lpar_prof)) time.sleep(5) @@ -428,28 +455,30 @@ def ValidateCEC_Setup(self): if self.num_hugepages: self.current_hgpg = self.cv_HMC.get_16gb_hugepage_size() if int(self.current_hgpg[0]) != 0: - log.info("System configured with %s 16gb Hugepage" % self.current_hgpg[0]) + log.info("System configured with %s 16gb Hugepage" % + self.current_hgpg[0]) self.cv_HMC.poweroff_lpar() self.setting_16gb_hugepage_profile() else: self.cec_dict['hugepages'] = self.num_hugepages def lmb_setup(self): - #Configure the lmb as per user request + # Configure the lmb as per user request self.cv_HMC.configure_lmb(self.lmb_size) - self.setup =1 + self.setup = 1 def hugepage_16gb_setup(self): - #configure the number of 16gb hugepages as per user request + # configure the number of 16gb hugepages as per user request self.cv_HMC.configure_16gb_hugepage(self.num_hugepages) self.setup = 1 def setting_16gb_hugepage_profile(self): self.current_hgpg = self.cv_HMC.get_16gb_hugepage_size() attrs = "min_num_huge_pages={0},desired_num_huge_pages={0},max_num_huge_pages={0}" .format( - int(self.current_hgpg[0])) + int(self.current_hgpg[0])) self.cv_HMC.set_lpar_cfg(attrs) + class OsConfig(): ''' This Class assign huge page in the system based on MMU either Radix or hash and validate @@ -508,14 +537,14 @@ def OsHugepageSetup(self): self.fail("16M is not supported in Radix") elif self.size_hgpg == "2M": self.no_hgpg = int(self.percentile / 2) - elif self.size_hgpg == "1G": + elif self.size_hgpg == "1G": self.no_hgpg = int(self.percentile / 1024) elif 'Hash' in self.mmu and self.size_hgpg == "16M": self.no_hgpg = int(self.percentile / 16) self.obj.update_kernel_cmdline(self.os_level, "hugepagesz=%s hugepages=%s" % ( - self.size_hgpg, self.no_hgpg), + self.size_hgpg, self.no_hgpg), "", reboot=True, reboot_cmd=True) @@ -535,7 +564,6 @@ def OsHugepageSetup(self): else: log.info("%s Hugepage validation successful!" % self.size_hgpg) - def configure_os_16gb_hugepage(self): if 'Radix' in self.mmu: self.obj.update_kernel_cmdline(self.os_level,