From 6542e7cc20774825f186329b7e640b40b95e6670 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 1 Feb 2021 15:30:01 -0500 Subject: [PATCH] Slow down setting configuration Problems may occur if setting configuration in a script and multiple transactions are attempted back to back. Also, it can be confusing to set settings and then readback the old settings. Address both concerns by only returning from set when the transaction manifests in the data returned from the peer system. Change-Id: I93f360e0e2a3360bed460534bb924df1472d2bfb --- pyghmi/ipmi/oem/lenovo/config.py | 9 ++++++--- pyghmi/ipmi/oem/lenovo/imm.py | 26 ++++++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/config.py b/pyghmi/ipmi/oem/lenovo/config.py index 9cd40d17..826700d1 100644 --- a/pyghmi/ipmi/oem/lenovo/config.py +++ b/pyghmi/ipmi/oem/lenovo/config.py @@ -51,7 +51,7 @@ def fromstring(inputdata): def run_command_with_retry(connection, data): - tries = 15 + tries = 240 while tries: tries -= 1 try: @@ -472,7 +472,7 @@ class LenovoFirmwareConfig(object): return options - def set_fw_options(self, options): + def set_fw_options(self, options, checkonly=False): changes = False random.seed() ident = 'ASU-%x-%x-%x-0' % (random.getrandbits(48), @@ -539,7 +539,9 @@ class LenovoFirmwareConfig(object): choice.append(instance) if not changes: - return + return False + if checkonly: + return True xml = etree.tostring(configurations) data = EfiCompressor.FrameworkCompress(xml, len(xml)) @@ -547,3 +549,4 @@ class LenovoFirmwareConfig(object): size=len(data)) self.imm_write(filehandle, len(data), data) self.imm_close(filehandle) + return True diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 1e29bc86..b7d8a439 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -253,6 +253,26 @@ class IMMClient(object): else: raise pygexc.InvalidParameterValue( '{0} not a known setting'.format(key)) + self.merge_changeset(changeset) + changepending = True + if changeset: + try: + changepending = self.fwc.set_fw_options(self.fwo) + except Exception: + self.fwo = None + self.fwovintage = 0 + raise + giveup = util._monotonic_time() + 60 + while changeset and changepending: + ipmisession.Session.pause(1) + self.fwo = self.fwc.get_fw_options(fetchimm=fetchimm) + self.fwovintage = util._monotonic_time() + if self.fwovintage > giveup: + break + self.merge_changeset(changeset) + changepending = self.fwc.set_fw_options(self.fwo, checkonly=True) + + def merge_changeset(self, changeset): for key in changeset: if isinstance(changeset[key], six.string_types): changeset[key] = {'value': changeset[key]} @@ -293,12 +313,6 @@ class IMMClient(object): self.fwo[key]['new_value'] = newnewvalues[0] else: self.fwo[key]['new_value'] = newnewvalues - if changeset: - try: - self.fwc.set_fw_options(self.fwo) - except Exception: - self.fwo = None - raise def clear_bmc_configuration(self): self.ipmicmd.xraw_command(0x2e, 0xcc,