Skip to content

Commit

Permalink
Fixed issue downloading AHS files locally within a specified date range
Browse files Browse the repository at this point in the history
  • Loading branch information
Yergidy committed Nov 1, 2018
1 parent 5d2b14c commit 5c2c2d2
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/extensions/iLO COMMANDS/ServerlogsCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
NoContentsFoundForOperationError, IncompatibleiLOVersionError,\
InvalidCListFileError, PartitionMoutingError, \
MultipleServerConfigError, UnabletoFindDriveError, \
InvalidMSCfileInputError, Encryption
InvalidMSCfileInputError, Encryption, LOGGER

if os.name == 'nt':
import win32api
Expand Down Expand Up @@ -192,6 +192,7 @@ def runmpfunc(self, mpfile=None, outputdir=None, options=None):
:type outputdir: string.
"""
self.logoutobj.run("")
LOGGER.info("Validating input server collection file.")
data = self.validatempfile(mpfile=mpfile, options=options)

if not data:
Expand Down Expand Up @@ -321,7 +322,8 @@ def validatempfile(self, mpfile=None, options=None):
line = str(line).replace("\n", "")
self.queue.put(linelist)
data.append(linelist)
except Exception, excp:
except Exception as excp:
LOGGER.info("{}".format(str(excp)))
raise excp

if data:
Expand Down Expand Up @@ -356,6 +358,7 @@ def addmaintenancelogentry(self, options, path=None):
:param path: path to post maintainence log
:type path: str
"""
LOGGER.info("Adding maintenance logs")
if options.mainmes is None:
raise InvalidCommandLineErrorOPTS("")

Expand Down Expand Up @@ -383,6 +386,7 @@ def clearlog(self, path):
:param path: path to post clear log action
:type path: str
"""
LOGGER.info("Clearing logs.")
if path and self.typepath.defs.isgen9:
if path.endswith(u"/Entries"):
path = path[:-len(u"/Entries")]
Expand Down Expand Up @@ -411,6 +415,7 @@ def downloaddata(self, path=None, options=None):
:type path: str
"""
if path:
LOGGER.info("Getting data from {}".format(str(path)))
if options.service == 'AHS':
data = self._rdmc.app.get_handler(path, silent=True, \
uncache=True)
Expand Down Expand Up @@ -483,6 +488,7 @@ def returnimlpath(self, options=None):
:param options: command line options
:type options: list.
"""
LOGGER.info("Obtaining IML path for download.")
path = ""
sel = self.typepath.defs.typestring
val = self.typepath.defs.logservicetype
Expand Down Expand Up @@ -586,6 +592,7 @@ def returnahspath(self, options):
:param options: command line options
:type options: list.
"""
LOGGER.info("Obtaining AHS path for download.")
path = ""

if options.filename:
Expand Down Expand Up @@ -693,6 +700,7 @@ def savedata(self, options=None, data=None):
:param data: log data
:type data: dict
"""
LOGGER.info("Saving/Writing data...")
if data:
data = self.filterdata(data=data, tofilter=options.filter)
if options.service == 'AHS':
Expand All @@ -718,9 +726,9 @@ def downloadahslocally(self, options=None):
"""
try:
self.downloadahslocalworker(options)
except Exception, excp:
except:
self.unmountbb()
raise excp
raise
return

def downloadahslocalworker(self, options):
Expand All @@ -729,6 +737,7 @@ def downloadahslocalworker(self, options):
:param options: command line options
:type options: list.
"""
LOGGER.info("Entering AHS local download functions...")
self.dontunmount = True

if self.typepath.ilogen < 4:
Expand All @@ -754,7 +763,10 @@ def downloadahslocalworker(self, options):
(manual_ovr, abspath) = self.getbbabspath()
self.dontunmount = False

LOGGER.info("Blackbox folder path:{}".format(','.join(next(os.walk\
(abspath))[2])))
self.abspath = os.path.join(abspath, 'data')
LOGGER.info("Blackbox data files path:{}".format(self.abspath))

self.updateiloversion()
cfilelist = self.getclistfilelisting()
Expand All @@ -770,6 +782,7 @@ def downloadahslocalworker(self, options):

def updateiloversion(self):
"""Update iloversion to create appropriate headers."""
LOGGER.info("Updating iloversion to format data appropriately")
self.lib.updateiloversion.argtypes = [ctypes.c_float]
self.lib.updateiloversion(float('2.'+str(self.typepath.ilogen)))

Expand All @@ -779,6 +792,7 @@ def createahsfile(self, ahsfile=None):
:param ahsfile: ahsfilename
:type ahsfile: str
"""
LOGGER.info("Creating AHS file from the formatted data.")
self.clearahsfile(ahsfile=ahsfile)
self.lib.setAHSFilepath.argtypes = [ctypes.c_char_p]
self.lib.setAHSFilepath(os.path.abspath(ahsfile))
Expand All @@ -792,6 +806,7 @@ def clearahsfile(self, ahsfile=None):
:param ahsfile: ahsfilename
:type ahsfile: str
"""
LOGGER.info("Clear redundant AHS file in current folder.")
try:
os.remove(ahsfile)
except:
Expand All @@ -805,7 +820,9 @@ def getdatfilelisting(self, cfilelist=None, allfile=None):
:param allfile: all files within blackbox
:type allfile: list
"""
LOGGER.info("Reading Blackbox to determine data files.")
allfile = list(set(allfile)|set(cfilelist))
LOGGER.info("Final filelist {0}".format(str(allfile)))
for files in allfile:
if files.startswith((".", "..")):
continue
Expand All @@ -825,6 +842,7 @@ def getdatfilelisting(self, cfilelist=None, allfile=None):

def getfilenames(self, options=None, cfilelist=None):
"""Get all file names from the blackbox directory."""
LOGGER.info("Obtaining all relevant file names from Blackbox.")
datelist = list()
allfiles = list()

Expand Down Expand Up @@ -867,6 +885,7 @@ def getfilenames(self, options=None, cfilelist=None):
if files in ("ilo_boot_support.zbb", "sys_boot_support.zbb"):
allfiles.append(files)
filenames.append(files)
LOGGER.info("{0}, number of files{1}".format(files, len(filenames)))
continue
filenoext = files.rsplit(".", 1)[0]
filesplit = filenoext.split("-")
Expand All @@ -883,7 +902,7 @@ def getfilenames(self, options=None, cfilelist=None):
except:
pass

_ = [cfilelist.remove(fil) for fil in list(cfilelist) if fil not in allfiles]
_ = [cfilelist.remove(fil) for fil in list(cfilelist) if fil not in filenames]

if options.downloadallahs:
strdate = min(datelist) if datelist else strdate
Expand All @@ -892,6 +911,9 @@ def getfilenames(self, options=None, cfilelist=None):
strdate = max(min(datelist), strdate) if datelist else strdate
enddate = min(max(datelist), enddate) if datelist else enddate

LOGGER.info("All filenames: {0}; Download files: {1}".format(\
str(filenames), str(allfiles)))

if atleastonefile:
self.updateminmaxdate(strdate=strdate, enddate=enddate)
return filenames if options.downloadallahs else allfiles
Expand All @@ -907,6 +929,7 @@ def updateminmaxdate(self, strdate=None, enddate=None):
:param enddate: ending date of ahs logs
:type enddate: datetime obj
"""
LOGGER.info("Updating min and max dates for download.")
self.lib.updateMinDate.argtypes = [ctypes.c_int, \
ctypes.c_int, ctypes.c_int]
self.lib.updateMinDate(strdate.year, strdate.month, strdate.day)
Expand All @@ -916,6 +939,7 @@ def updateminmaxdate(self, strdate=None, enddate=None):

def getclistfilelisting(self):
"""Get files present within clist.pkg ."""
LOGGER.info("Getting all config files that are required.")
sclistpath = os.path.join(self.abspath, "clist.pkg")
cfilelist = []
if os.path.isfile(sclistpath):
Expand Down Expand Up @@ -943,11 +967,13 @@ def getclistfilelisting(self):

count = count-1
revcount = revcount+1
LOGGER.info("CLIST files {0}".format(str(cfilelist)))

return cfilelist

def getbbabspath(self):
"""Get blackbox folder path."""
LOGGER.info("Obtaining the absolute path of blackbox.")
count = 0

while count < 20:
Expand Down Expand Up @@ -988,6 +1014,7 @@ def getbbabspath(self):

def manualmountbb(self):
"""Manually mount blackbox when after fixed time."""
LOGGER.info("Manually mounting the blackbox.")

try:
context = pyudev.Context()
Expand Down Expand Up @@ -1018,12 +1045,14 @@ def manualunmountbb(self, dirpath):
:param dirpath: mounted directory path
:type dirpath: str
"""
LOGGER.info("Manually unmounting the blackbox.")
pmount = subprocess.Popen(['umount', dirpath], stdout=subprocess.PIPE, \
stderr=subprocess.PIPE)
_, _ = pmount.communicate()

def mountbb(self):
"""Mount blackbox."""
LOGGER.info("Mounting blackbox...")
bs2 = risblobstore2.BlobStore2()
bs2.mount_blackbox()
bs2.channel.close()
Expand All @@ -1037,6 +1066,7 @@ def unmountbb(self):

def get_available_drives(self):
"""Obtain all drives"""
LOGGER.info("Unmounting blackbox...")
if 'Windows' not in platform.system():
return []

Expand All @@ -1053,6 +1083,7 @@ def filterdata(self, data=None, tofilter=None):
:param tofilter: command line filter option
:type tofilter: str
"""
LOGGER.info("Filtering logs based on requsted options.")
if tofilter and data:
try:
if (str(tofilter)[0] == str(tofilter)[-1])\
Expand Down Expand Up @@ -1082,6 +1113,7 @@ def getahsfilename(self, options):
:param options: command line options
:type options: list.
"""
LOGGER.info("Obtaining Serialnumber from iLO for AHS filename.")

sel = self.typepath.defs.typestring
val = u"ComputerSystem."
Expand Down

0 comments on commit 5c2c2d2

Please sign in to comment.