Add progress indication to SMM update
Refactor the support added to support IMMv2 RDOC to be reusable, and apply it to SMM updates as well. Change-Id: I01cd3dca8b14230c0487e2e7261fde412efedf8d
This commit is contained in:
@@ -32,7 +32,6 @@ import random
|
||||
import re
|
||||
import socket
|
||||
import struct
|
||||
import threading
|
||||
import urllib
|
||||
import weakref
|
||||
|
||||
@@ -78,21 +77,6 @@ def fixup_str(propstr):
|
||||
' \xff\x00')
|
||||
|
||||
|
||||
class FileUploader(threading.Thread):
|
||||
|
||||
def __init__(self, webclient, url, filename, data=None, otherfields=None):
|
||||
self.wc = webclient
|
||||
self.url = url
|
||||
self.filename = filename
|
||||
self.data = data
|
||||
self.otherfields = otherfields
|
||||
super(FileUploader, self).__init__()
|
||||
|
||||
def run(self):
|
||||
self.rsp = self.wc.upload(self.url, self.filename, self.data,
|
||||
otherfields=self.otherfields)
|
||||
|
||||
|
||||
class IMMClient(object):
|
||||
logouturl = '/data/logout'
|
||||
bmcname = 'IMM'
|
||||
@@ -337,8 +321,9 @@ class IMMClient(object):
|
||||
uploadfields['uploadType'] = 'iframe'
|
||||
uploadfields['available'] = alloc['available']
|
||||
uploadfields['checksum'] = xid
|
||||
ut = FileUploader(self.wc, '/designs/imm/upload/rp_image_upload.esp',
|
||||
filename, otherfields=uploadfields)
|
||||
ut = webclient.FileUploader(
|
||||
self.wc, '/designs/imm/upload/rp_image_upload.esp', filename,
|
||||
otherfields=uploadfields)
|
||||
ut.start()
|
||||
while ut.isAlive():
|
||||
ut.join(3)
|
||||
@@ -1181,9 +1166,8 @@ class XCCClient(IMMClient):
|
||||
|
||||
def upload_media(self, filename, progress=None):
|
||||
xid = random.randint(0, 1000000000)
|
||||
uploadthread = FileUploader(self.wc,
|
||||
'/upload?X-Progress-ID={0}'.format(xid),
|
||||
filename, None)
|
||||
uploadthread = webclient.FileUploader(
|
||||
self.wc, '/upload?X-Progress-ID={0}'.format(xid), filename, None)
|
||||
uploadthread.start()
|
||||
while uploadthread.isAlive():
|
||||
uploadthread.join(3)
|
||||
@@ -1268,9 +1252,8 @@ class XCCClient(IMMClient):
|
||||
if rsv['return'] != 0:
|
||||
raise Exception('Unexpected return to reservation: ' + repr(rsv))
|
||||
xid = random.randint(0, 1000000000)
|
||||
uploadthread = FileUploader(self.wc,
|
||||
'/upload?X-Progress-ID={0}'.format(xid),
|
||||
filename, data)
|
||||
uploadthread = webclient.FileUploader(
|
||||
self.wc, '/upload?X-Progress-ID={0}'.format(xid), filename, data)
|
||||
uploadthread.start()
|
||||
uploadstate = None
|
||||
while uploadthread.isAlive():
|
||||
|
||||
@@ -399,13 +399,19 @@ class SMMClient(object):
|
||||
data = z.open(filename)
|
||||
break
|
||||
progress({'phase': 'upload', 'progress': 0.0})
|
||||
url = self.wc # this is just to get self.st1 initted
|
||||
self.wc.request('POST', '/data', 'set=fwType:10') # SMM firmware
|
||||
rsp = self.wc.getresponse()
|
||||
rsp.read()
|
||||
url = '/fwupload/fwupload.esp?ST1={0}'.format(self.st1)
|
||||
self.wc.upload(url, filename, data, formname='fileUpload',
|
||||
otherfields={'preConfig': 'on'})
|
||||
fu = webclient.FileUploader(
|
||||
self.wc, url, filename, data, formname='fileUpload',
|
||||
otherfields={'preConfig': 'on'})
|
||||
fu.start()
|
||||
while fu.isAlive():
|
||||
fu.join(3)
|
||||
if progress:
|
||||
progress({'phase': 'upload',
|
||||
'progress': 100 * self.wc.get_upload_progress()})
|
||||
progress({'phase': 'validating', 'progress': 0.0})
|
||||
url = '/data'
|
||||
self.wc.request('POST', url, 'get=fwVersion,spfwInfo')
|
||||
|
||||
@@ -20,6 +20,7 @@ import json
|
||||
import pyghmi.exceptions as pygexc
|
||||
import socket
|
||||
import ssl
|
||||
import threading
|
||||
|
||||
try:
|
||||
import Cookie
|
||||
@@ -41,6 +42,22 @@ BND = 'TbqbLUSn0QFjx9gxiQLtgBK4Zu6ehLqtLs4JOBS50EgxXJ2yoRMhTrmRXxO1lkoAQdZx16'
|
||||
uploadforms = {}
|
||||
|
||||
|
||||
class FileUploader(threading.Thread):
|
||||
|
||||
def __init__(self, webclient, url, filename, data=None, formname=None,
|
||||
otherfields=None):
|
||||
self.wc = webclient
|
||||
self.url = url
|
||||
self.filename = filename
|
||||
self.data = data
|
||||
self.otherfields = otherfields
|
||||
super(FileUploader, self).__init__()
|
||||
|
||||
def run(self):
|
||||
self.rsp = self.wc.upload(self.url, self.filename, self.data,
|
||||
otherfields=self.otherfields)
|
||||
|
||||
|
||||
def get_upload_form(filename, data, formname, otherfields):
|
||||
if not formname:
|
||||
formname = filename
|
||||
|
||||
Reference in New Issue
Block a user