2
0
mirror of https://opendev.org/x/pyghmi synced 2025-01-13 19:27:48 +00:00

Consolidate IMM date string parsing

Various strings/date formats may be used
in different places, and in fact the same place.
Use a consolidated catch-all parser to convert
the strings to a datetime.

Change-Id: Ie84229056ba55806bce1527ea263a80c29ff7048
This commit is contained in:
Jarrod Johnson 2016-11-15 10:45:26 -05:00
parent 2cfec95558
commit 4fcc75899e
2 changed files with 31 additions and 10 deletions

View File

@ -493,7 +493,8 @@ class OEMHandler(generic.OEMHandler):
if len(bdata['data'][:]) != 3:
self._hasimm = False
return False
self._hasimm = ord(bdata['data'][1]) & 1 == 1
rdata = bytearray(bdata['data'][:])
self._hasimm = (rdata[1] & 1 == 1) or (rdata[1] & 16 == 16)
return self._hasimm
def get_oem_firmware(self, bmcver):

View File

@ -21,6 +21,30 @@ import pyghmi.util.webclient as webclient
import urllib
def _parse_builddate(strval):
try:
return datetime.strptime(strval, '%Y/%m/%d %H:%M:%S')
except ValueError:
pass
try:
return datetime.strptime(strval, '%Y-%m-%d %H:%M:%S')
except ValueError:
pass
try:
return datetime.strptime(strval, '%Y/%m/%d')
except ValueError:
pass
try:
return datetime.strptime(strval, '%m/%d/%Y')
except ValueError:
pass
try:
return datetime.strptime(strval, '%m %d %Y')
except ValueError:
pass
return None
def get_imm_property(ipmicmd, propname):
propname = propname.encode('utf-8')
proplen = len(propname) | 0b10000000
@ -63,14 +87,14 @@ def get_imm_webclient(imm, certverify, uid, password):
def parse_imm_buildinfo(buildinfo):
buildid = buildinfo[:9].rstrip(' \x00')
bdt = ' '.join(buildinfo[9:].replace('\x00', ' ').split())
bdate = datetime.strptime(bdt, '%Y/%m/%d %H:%M:%S')
bdate = _parse_builddate(bdt)
return (buildid, bdate)
def datefromprop(propstr):
if propstr is None:
return None
return datetime.strptime(propstr, '%Y/%m/%d')
return _parse_builddate(propstr)
def fetch_grouped_properties(ipmicmd, groupinfo):
@ -171,14 +195,10 @@ def fetch_agentless_firmware(ipmicmd, certverify):
firm['releaseDate'] and
firm['releaseDate'] != 'N/A'):
try:
bdata['date'] = datetime.strptime(
firm['releaseDate'], '%m/%d/%Y')
bdata['date'] = _parse_builddate(
firm['releaseDate'])
except ValueError:
try:
bdata['date'] = datetime.strptime(
firm['releaseDate'], '%m %d %Y')
except ValueError:
pass
pass
yield ('{0} {1}'.format(aname, fname), bdata)
storagedata = get_cached_data(ipmicmd, 'lenovo_cached_storage')
if not storagedata: