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):