From b6fb57dfa521a51efd1dc4e8c15f0b368104b199 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 22 Jul 2019 11:12:19 -0400 Subject: [PATCH] Relay errors on invalid licenses License errors are now raised to the caller. Change-Id: I0fc107525b4d009dfd6c7ad52ab356a9dcaac5c0 --- pyghmi/ipmi/oem/lenovo/imm.py | 12 +++++++++++- pyghmi/redfish/oem/lenovo/xcc.py | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 0e8a7aea..7d9d392f 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -1836,14 +1836,24 @@ class XCCClient(IMMClient): break def apply_license(self, filename, progress=None): + license_errors = { + 310: "License is for a different model of system", + 311: "License is for a different system serial number", + 312: "License is invalid", + 313: "License is expired", + 314: "License usage limit reached", + } uploadthread = webclient.FileUploader(self.wc, '/upload', filename) uploadthread.start() uploadthread.join() rsp = json.loads(uploadthread.rsp) licpath = rsp.get('items', [{}])[0].get('path', None) if licpath: - self.wc.grab_json_response('/api/providers/imm_fod', + rsp = self.wc.grab_json_response('/api/providers/imm_fod', {'FOD_LicenseKeyInstall': licpath}) + if rsp.get('return', 0) in license_errors: + raise pygexc.InvalidParameterValue( + license_errors[rsp['return']]) return self.get_licenses() def get_user_expiration(self, uid): diff --git a/pyghmi/redfish/oem/lenovo/xcc.py b/pyghmi/redfish/oem/lenovo/xcc.py index 30f981a4..e9fa9b87 100644 --- a/pyghmi/redfish/oem/lenovo/xcc.py +++ b/pyghmi/redfish/oem/lenovo/xcc.py @@ -740,14 +740,24 @@ class OEMHandler(generic.OEMHandler): yield savefile def apply_license(self, filename, progress=None): + license_errors = { + 310: "License is for a different model of system", + 311: "License is for a different system serial number", + 312: "License is invalid", + 313: "License is expired", + 314: "License usage limit reached", + } uploadthread = webclient.FileUploader(self.wc, '/upload', filename) uploadthread.start() uploadthread.join() rsp = json.loads(uploadthread.rsp) licpath = rsp.get('items', [{}])[0].get('path', None) if licpath: - self.wc.grab_json_response('/api/providers/imm_fod', - {'FOD_LicenseKeyInstall': licpath}) + rsp = self.wc.grab_json_response('/api/providers/imm_fod', + {'FOD_LicenseKeyInstall': licpath}) + if rsp.get('return', 0) in license_errors: + raise pygexc.InvalidParameterValue( + license_errors[rsp['return']]) return self.get_licenses() def get_user_expiration(self, uid):