From eb7869bfa7ceaf741dd245b841442ce98d1a2122 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 2 Apr 2019 13:03:51 -0400 Subject: [PATCH] Handle 413 directly on the upload 413 may return on the upload, but sometimes not the status query. Support the direct evaluation of the return code. Change-Id: I4e8e8f4a03adc00d4c1de3a1fe4fbcb5d1b3d8f3 --- pyghmi/ipmi/oem/lenovo/imm.py | 2 +- pyghmi/util/webclient.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 0b553a59..2622fba2 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -1498,7 +1498,7 @@ class XCCClient(IMMClient): progress({'phase': 'upload', 'progress': 100.0 * rsp['received'] / rsp['size']}) elif rsp['state'] != 'done': - if rsp.get('status', None) == 413: + if rsp.get('status', None) == 413 or uploadthread.rspstatus == 413: raise Exception('File is larger than supported') raise Exception('Unexpected result:' + repr(rsp)) uploadstate = rsp['state'] diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index fd746b95..fe770b8b 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -53,11 +53,17 @@ class FileUploader(threading.Thread): self.data = data self.otherfields = otherfields self.formname = formname + self.rsp = '' + self.rspstatus = 500 super(FileUploader, self).__init__() def run(self): - self.rsp = self.wc.upload(self.url, self.filename, self.data, - self.formname, otherfields=self.otherfields) + try: + self.rsp = self.wc.upload(self.url, self.filename, self.data, + self.formname, otherfields=self.otherfields) + except Exception: + self.rspstatus = self.wc.rspstatus + raise class FileDownloader(threading.Thread): @@ -244,6 +250,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): del uploadforms[filename] except KeyError: # something could have already deleted it pass + self.rspstatus = rsp.status if rsp.status != 200: raise Exception('Unexpected response in file upload: ' + rsp.read())