Skip to content

Commit

Permalink
Remove day argument from log_match
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwaks committed Jan 24, 2019
1 parent efc7e95 commit 205d9be
Showing 1 changed file with 75 additions and 75 deletions.
150 changes: 75 additions & 75 deletions test/fw/ptl/lib/pbs_testlib.py
Expand Up @@ -3879,8 +3879,8 @@ def initialise_service(self):
the service
"""

def log_lines(self, logtype, id=None, n=50, tail=True, day=None,
starttime=None, endtime=None):
def log_lines(self, logtype, id=None, n=50, tail=True, starttime=None,
endtime=None):
"""
Return the last ``<n>`` lines of a PBS log file, which
can be one of ``server``, ``scheduler``, ``MoM``, or
Expand Down Expand Up @@ -3908,9 +3908,12 @@ def log_lines(self, logtype, id=None, n=50, tail=True, day=None,
``Scheduler``, ``MoM or tracejob``
"""
logval = None
lines = None
lines = []
sudo = False

if endtime is None:
endtime = int(time.time())
if starttime is None:
starttime = self.ctime
try:
if logtype == 'tracejob':
if id is None:
Expand All @@ -3924,47 +3927,60 @@ def log_lines(self, logtype, id=None, n=50, tail=True, day=None,
if n != 'ALL':
lines = lines[-n:]
else:
if day is None:
day = time.strftime("%Y%m%d", time.localtime(time.time()))
daystart = time.strftime("%Y%m%d", time.localtime(starttime))
dayend = time.strftime("%Y%m%d", time.localtime(endtime))
firstday_obj = datetime.datetime.strptime(daystart, '%Y%m%d')
lastday_obj = datetime.datetime.strptime(dayend, '%Y%m%d')
if logtype == 'accounting':
filename = os.path.join(self.pbs_conf['PBS_HOME'],
'server_priv', 'accounting', day)
logdir = os.path.join(self.pbs_conf['PBS_HOME'],
'server_priv', 'accounting')
sudo = True
elif (isinstance(self, Scheduler) and
'sched_log' in self.attributes):
# if setup is multi-sched then get logdir from
# its attributes
logdir = self.attributes['sched_log']
else:
if (isinstance(self, Scheduler) and
'sched_log' in self.attributes):
filename = os.path.join(
self.attributes['sched_log'], day)
else:
logval = self._instance_to_logpath(logtype)
if logval:
filename = os.path.join(self.pbs_conf['PBS_HOME'],
logval, day)
if n == 'ALL':
if self._is_local and not sudo:
lines = open(filename)
else:
lines = self.du.cat(self.hostname, filename, sudo=sudo,
level=logging.DEBUG2)['out']
elif self._is_local and not sudo:
if tail:
futils = FileUtils(filename, FILE_TAIL)
else:
futils = FileUtils(filename)
lines = futils.next(n)
else:
if tail:
cmd = ['/usr/bin/tail']
logval = self._instance_to_logpath(logtype)
if logval is None:
m = 'Invalid logtype'
raise PtlLogMatchError(rv=False, rc=-1, msg=m)
logdir = os.path.join(self.pbs_conf['PBS_HOME'], logval)
while firstday_obj <= lastday_obj:
day = firstday_obj.strftime("%Y%m%d")
filename = os.path.join(logdir, day)
if n == 'ALL':
if self._is_local and not sudo:
with open(filename) as f:
day_lines = f.readlines()
else:
day_lines = self.du.cat(
self.hostname, filename, sudo=sudo,
level=logging.DEBUG2)['out']
elif self._is_local and not sudo:
if tail:
futils = FileUtils(filename, FILE_TAIL)
else:
futils = FileUtils(filename)
day_lines = futils.next(n)
else:
cmd = ['/usr/bin/head']

pyexec = os.path.join(self.pbs_conf['PBS_EXEC'], 'python',
'bin', 'python')
osflav = self.du.get_platform(self.hostname, pyexec)
cmd += ['-n']
cmd += [str(n), filename]
lines = self.du.run_cmd(self.hostname, cmd, sudo=sudo,
level=logging.DEBUG2)['out']
if tail:
cmd = ['/usr/bin/tail']
else:
cmd = ['/usr/bin/head']

cmd += ['-n']
cmd += [str(n), filename]
day_lines = self.du.run_cmd(
self.hostname, cmd, sudo=sudo,
level=logging.DEBUG2)['out']
lines.extend(day_lines)
firstday_obj = firstday_obj + datetime.timedelta(days=1)
if n == 'ALL':
continue
n = n - len(day_lines)
if n <= 0:
break
except:
self.logger.error('error in log_lines ')
traceback.print_exc()
Expand All @@ -3973,7 +3989,7 @@ def log_lines(self, logtype, id=None, n=50, tail=True, day=None,
return lines

def _log_match(self, logtype, msg, id=None, n=50, tail=True,
allmatch=False, regexp=False, day=None, max_attempts=None,
allmatch=False, regexp=False, max_attempts=None,
interval=None, starttime=None, endtime=None,
level=logging.INFO, existence=True):
"""
Expand Down Expand Up @@ -4003,8 +4019,6 @@ def _log_match(self, logtype, msg, id=None, n=50, tail=True,
:param regexp: If true msg is a Python regular expression.
Defaults to False
:type regexp: bool
:param day: Optional day in YYYMMDD format.
:type day: str
:param max_attempts: the number of attempts to make to find
a matching entry
:type max_attempts: int
Expand Down Expand Up @@ -4049,8 +4063,6 @@ def _log_match(self, logtype, msg, id=None, n=50, tail=True,
max_attempts = 60
if interval is None:
interval = 0.5
if starttime is None and n != 'ALL':
starttime = self.ctime
rv = (None, None)
attempt = 1
lines = None
Expand All @@ -4065,7 +4077,7 @@ def _log_match(self, logtype, msg, id=None, n=50, tail=True,
while attempt <= max_attempts:
if attempt > 1:
attemptmsg = ' - attempt ' + str(attempt)
lines = self.log_lines(logtype, id, n=n, tail=tail, day=day,
lines = self.log_lines(logtype, id, n=n, tail=tail,
starttime=starttime, endtime=endtime)
rv = self.logutils.match_msg(lines, msg, allmatch=allmatch,
regexp=regexp, starttime=starttime,
Expand Down Expand Up @@ -4099,9 +4111,9 @@ def _log_match(self, logtype, msg, id=None, n=50, tail=True,
return rv

def accounting_match(self, msg, id=None, n=50, tail=True,
allmatch=False, regexp=False, day=None,
max_attempts=None, interval=None, starttime=None,
endtime=None, level=logging.INFO, existence=True):
allmatch=False, regexp=False, max_attempts=None,
interval=None, starttime=None, endtime=None,
level=logging.INFO, existence=True):
"""
Match given ``msg`` in given ``n`` lines of accounting log

Expand All @@ -4124,8 +4136,6 @@ def accounting_match(self, msg, id=None, n=50, tail=True,
:param regexp: If true msg is a Python regular expression.
Defaults to False
:type regexp: bool
:param day: Optional day in YYYMMDD format.
:type day: str
:param max_attempts: the number of attempts to make to find
a matching entry
:type max_attempts: int
Expand Down Expand Up @@ -4159,13 +4169,13 @@ def accounting_match(self, msg, id=None, n=50, tail=True,
number, not the absolute line number in the file.
"""
return self._log_match('accounting', msg, id, n, tail, allmatch,
regexp, day, max_attempts, interval, starttime,
regexp, max_attempts, interval, starttime,
endtime, level, existence)

def tracejob_match(self, msg, id=None, n=50, tail=True,
allmatch=False, regexp=False, day=None,
max_attempts=None, interval=None, starttime=None,
endtime=None, level=logging.INFO, existence=True):
allmatch=False, regexp=False, max_attempts=None,
interval=None, starttime=None, endtime=None,
level=logging.INFO, existence=True):
"""
Match given ``msg`` in given ``n`` lines of tracejob log

Expand All @@ -4187,8 +4197,6 @@ def tracejob_match(self, msg, id=None, n=50, tail=True,
:param regexp: If true msg is a Python regular expression.
Defaults to False
:type regexp: bool
:param day: Optional day in YYYMMDD format.
:type day: str
:param max_attempts: the number of attempts to make to find
a matching entry
:type max_attempts: int
Expand Down Expand Up @@ -4222,7 +4230,7 @@ def tracejob_match(self, msg, id=None, n=50, tail=True,
number, not the absolute line number in the file.
"""
return self._log_match('tracejob', msg, id, n, tail, allmatch,
regexp, day, max_attempts, interval, starttime,
regexp, max_attempts, interval, starttime,
endtime, level, existence)

def _save_config_file(self, dict_conf, fname):
Expand Down Expand Up @@ -4433,7 +4441,7 @@ def restart(self):
return self.start()

def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
regexp=False, day=None, max_attempts=None, interval=None,
regexp=False, max_attempts=None, interval=None,
starttime=None, endtime=None, level=logging.INFO,
existence=True):
"""
Expand All @@ -4458,8 +4466,6 @@ def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
:param regexp: If true msg is a Python regular expression.
Defaults to False
:type regexp: bool
:param day: Optional day in YYYMMDD format.
:type day: str
:param max_attempts: the number of attempts to make to find
a matching entry
:type max_attempts: int
Expand Down Expand Up @@ -4493,7 +4499,7 @@ def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
number, not the absolute line number in the file.
"""
return self._log_match(self, msg, id, n, tail, allmatch, regexp,
day, max_attempts, interval, starttime, endtime,
max_attempts, interval, starttime, endtime,
level=level, existence=existence)


Expand Down Expand Up @@ -4964,7 +4970,7 @@ def restart(self):
return self.start()

def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
regexp=False, day=None, max_attempts=None, interval=None,
regexp=False, max_attempts=None, interval=None,
starttime=None, endtime=None, level=logging.INFO,
existence=True):
"""
Expand All @@ -4989,8 +4995,6 @@ def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
:param regexp: If true msg is a Python regular expression.
Defaults to False
:type regexp: bool
:param day: Optional day in YYYMMDD format.
:type day: str
:param max_attempts: the number of attempts to make to find
a matching entry
:type max_attempts: int
Expand Down Expand Up @@ -5024,7 +5028,7 @@ def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
number, not the absolute line number in the file.
"""
return self._log_match(self, msg, id, n, tail, allmatch, regexp,
day, max_attempts, interval, starttime, endtime,
max_attempts, interval, starttime, endtime,
level=level, existence=existence)

def revert_to_defaults(self, reverthooks=True, revertqueues=True,
Expand Down Expand Up @@ -10699,7 +10703,7 @@ def restart(self):
return self.start()

def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
regexp=False, day=None, max_attempts=None, interval=None,
regexp=False, max_attempts=None, interval=None,
starttime=None, endtime=None, level=logging.INFO,
existence=True):
"""
Expand All @@ -10724,8 +10728,6 @@ def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
:param regexp: If true msg is a Python regular expression.
Defaults to False
:type regexp: bool
:param day: Optional day in YYYMMDD format.
:type day: str
:param max_attempts: the number of attempts to make to find
a matching entry
:type max_attempts: int
Expand Down Expand Up @@ -10758,7 +10760,7 @@ def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
.. note:: The matching line number is relative to the record
number, not the absolute line number in the file.
"""
return self._log_match(self, msg, id, n, tail, allmatch, regexp, day,
return self._log_match(self, msg, id, n, tail, allmatch, regexp,
max_attempts, interval, starttime, endtime,
level=level, existence=existence)

Expand Down Expand Up @@ -12714,7 +12716,7 @@ def restart(self):
return self.start()

def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
regexp=False, day=None, max_attempts=None, interval=None,
regexp=False, max_attempts=None, interval=None,
starttime=None, endtime=None, level=logging.INFO,
existence=True):
"""
Expand All @@ -12739,8 +12741,6 @@ def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
:param regexp: If true msg is a Python regular expression.
Defaults to False
:type regexp: bool
:param day: Optional day in YYYMMDD format.
:type day: str
:param max_attempts: the number of attempts to make to find
a matching entry
:type max_attempts: int
Expand Down Expand Up @@ -12773,7 +12773,7 @@ def log_match(self, msg=None, id=None, n=50, tail=True, allmatch=False,
.. note:: The matching line number is relative to the record
number, not the absolute line number in the file.
"""
return self._log_match(self, msg, id, n, tail, allmatch, regexp, day,
return self._log_match(self, msg, id, n, tail, allmatch, regexp,
max_attempts, interval, starttime, endtime,
level, existence)

Expand Down

0 comments on commit 205d9be

Please sign in to comment.