Commit d5b915b6 authored by Xiaowu Zhang's avatar Xiaowu Zhang

promise: add check zope longrequest log promise

parent cd9a7718
from zope import interface as zope_interface
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise
import time
import os
import sys
import re
r = re.compile("^([0-9]+\-[0-9]+\-[0-9]+ [0-9]+\:[0-9]+\:[0-9]+)(\,[0-9]+) - ([A-z]+) (.*)$")
class RunPromise(GenericPromise):
zope_interface.implements(interface.IPromise)
def __init__(self, config):
GenericPromise.__init__(self, config)
self.setPeriodicity(minute=10)
def sense(self):
log_file = self.getConfig('log-file')
error_threshold = self.getConfig('error-threshold')
maximum_delay = self.getConfig('maximum-delay')
error_amount = 0
if not os.path.exists(log_file):
# file don't exist, nothing to check
self.logger.info("log file does not exist: log check skipped")
return 0
with open(log_file) as f:
f.seek(0, 2)
block_end_byte = f.tell()
f.seek(-min(block_end_byte, 4096*10), 1)
data = f.read()
for line in reversed(data.splitlines()):
m = r.match(line)
if m is None:
continue
dt, _, level, msg = m.groups()
try:
t = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
except ValueError:
continue
if maximum_delay and (time.time()-time.mktime(t)) > maximum_delay:
# no result in the latest hour
break
error_amount += 1
if error_amount > error_threshold:
self.logger.error('ERROR=%s' % error_amount)
else:
self.logger.info('INFO=%s' % error_amount)
def test(self):
return self._test(result_count=1, failure_amount=1)
def anomaly(self):
return self._test(result_count=3, failure_amount=3)
DATETIME,928 - Thread 140691697874688: Started on 1542293628.8; Running for 4.0 secs; request: GET
retry count: 0
form: {}
other: {'AcceptLanguage': {},
'PARENTS': [<Application at >],
'RESPONSE': HTTPResponse(''),
'SERVER_URL': '',
'URL': '',
'method': 'GET'}
Traceback:
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZServer/PubCore/ZServerPublisher.py", line 31, in __init__
response=b)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 455, in publish_module
environ, debug, request, response)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Products.LongRequestLogger-2.1.0-py2.7.egg/Products/LongRequestLogger/__init__.py", line 19, in publish_module_standard
return publish_module_standard.original(*args, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 249, in publish_module_standard
response = publish(request, module_name, after_list, debug=debug)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/Localizer/patches.py", line 84, in new_publish
x = zope_publish(request, module_name, after_list, debug)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 138, in publish
request, bind=1)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/mapply.py", line 77, in mapply
if debug is not None: return debug(object,args,context)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 48, in call_object
result=apply(object,args) # Type s<cr> to step into published object.
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2467, in addERP5Site
**{k: kw.get(k, v) for k, v in default_kw.iteritems()
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 100, in manage_addERP5Site
sql_reset=sql_reset)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 1964, in create
reindex=reindex, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2374, in setup
self.setupERP5Core(p,**kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2398, in setupERP5Core
bt = template_tool.download(url)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Tool/TemplateTool.py", line 382, in download
bt = self._download_local(path, id)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Tool/TemplateTool.py", line 328, in _download_local
bt.importFile(path)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 5860, in importFile
item_object.importFile(bta)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 585, in importFile
bta.importFiles(self)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 431, in importFiles
item._importFile(file_name, f)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 4001, in _importFile
return ObjectTemplateItem._importFile(self, file_name, *args, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 957, in _importFile
self.removeProperties(obj, 0)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/ExportImport.py", line 85, in importFile
return customImporters[magic](self, f, clue)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5Type/patches/ppml.py", line 818, in importXML
return jar.importFile(outfile,clue)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/ExportImport.py", line 98, in importFile
return self.get(return_oid_list[0])
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/transaction-1.7.0-py2.7.egg/transaction/_transaction.py", line 205, in savepoint
return savepoint
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/transaction-1.7.0-py2.7.egg/transaction/_transaction.py", line 684, in __init__
savepoints.append(savepoint)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 1193, in savepoint
return result
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 643, in _commit
self._added_during_commit = None
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 717, in _store_objects
self._handle_serial(oid, s)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 1346, in store
self._file.write(header)
DATETIME,945 - Thread 140691697874688: Started on 1542293628.8; Running for 6.1 secs; Traceback:
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZServer/PubCore/ZServerPublisher.py", line 31, in __init__
response=b)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 455, in publish_module
environ, debug, request, response)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Products.LongRequestLogger-2.1.0-py2.7.egg/Products/LongRequestLogger/__init__.py", line 19, in publish_module_standard
return publish_module_standard.original(*args, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 249, in publish_module_standard
response = publish(request, module_name, after_list, debug=debug)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/Localizer/patches.py", line 84, in new_publish
x = zope_publish(request, module_name, after_list, debug)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 138, in publish
request, bind=1)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/mapply.py", line 77, in mapply
if debug is not None: return debug(object,args,context)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 48, in call_object
result=apply(object,args) # Type s<cr> to step into published object.
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2467, in addERP5Site
**{k: kw.get(k, v) for k, v in default_kw.iteritems()
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 100, in manage_addERP5Site
sql_reset=sql_reset)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 1964, in create
reindex=reindex, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2374, in setup
self.setupERP5Core(p,**kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2398, in setupERP5Core
bt = template_tool.download(url)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Tool/TemplateTool.py", line 382, in download
bt = self._download_local(path, id)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Tool/TemplateTool.py", line 328, in _download_local
bt.importFile(path)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 5860, in importFile
item_object.importFile(bta)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 585, in importFile
bta.importFiles(self)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 431, in importFiles
item._importFile(file_name, f)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 4001, in _importFile
return ObjectTemplateItem._importFile(self, file_name, *args, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 936, in _importFile
obj = connection.importFile(file_obj, customImporters=customImporters)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/ExportImport.py", line 85, in importFile
return customImporters[magic](self, f, clue)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5Type/patches/ppml.py", line 818, in importXML
return jar.importFile(outfile,clue)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/ExportImport.py", line 95, in importFile
t.savepoint(optimistic=True)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/transaction-1.7.0-py2.7.egg/transaction/_transaction.py", line 195, in savepoint
savepoint = Savepoint(self, optimistic, *self._resources)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/transaction-1.7.0-py2.7.egg/transaction/_transaction.py", line 682, in __init__
savepoint = savepoint()
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 1178, in savepoint
self._commit(None)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 639, in _commit
self._store_objects(ObjectWriter(obj), transaction)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 698, in _store_objects
s = self._storage.store(oid, serial, p, '', transaction)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 1347, in store
self._file.write(data)
DATETIME,972 - Thread 140691697874688: Started on 1542293628.8; Running for 8.1 secs; Traceback:
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZServer/PubCore/ZServerPublisher.py", line 31, in __init__
response=b)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 455, in publish_module
environ, debug, request, response)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Products.LongRequestLogger-2.1.0-py2.7.egg/Products/LongRequestLogger/__init__.py", line 19, in publish_module_standard
return publish_module_standard.original(*args, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 249, in publish_module_standard
response = publish(request, module_name, after_list, debug=debug)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/Localizer/patches.py", line 84, in new_publish
x = zope_publish(request, module_name, after_list, debug)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 138, in publish
request, bind=1)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/mapply.py", line 77, in mapply
if debug is not None: return debug(object,args,context)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/Zope2-2.13.28-py2.7.egg/ZPublisher/Publish.py", line 48, in call_object
result=apply(object,args) # Type s<cr> to step into published object.
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2467, in addERP5Site
**{k: kw.get(k, v) for k, v in default_kw.iteritems()
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 100, in manage_addERP5Site
sql_reset=sql_reset)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 1964, in create
reindex=reindex, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2374, in setup
self.setupERP5Core(p,**kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/ERP5Site.py", line 2398, in setupERP5Core
bt = template_tool.download(url)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Tool/TemplateTool.py", line 382, in download
bt = self._download_local(path, id)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Tool/TemplateTool.py", line 328, in _download_local
bt.importFile(path)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 5860, in importFile
item_object.importFile(bta)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 585, in importFile
bta.importFiles(self)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 431, in importFiles
item._importFile(file_name, f)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 4001, in _importFile
return ObjectTemplateItem._importFile(self, file_name, *args, **kw)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5/Document/BusinessTemplate.py", line 957, in _importFile
self.removeProperties(obj, 0)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/ExportImport.py", line 85, in importFile
return customImporters[magic](self, f, clue)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/parts/erp5/product/ERP5Type/patches/ppml.py", line 818, in importXML
return jar.importFile(outfile,clue)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/ExportImport.py", line 98, in importFile
return self.get(return_oid_list[0])
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/transaction-1.7.0-py2.7.egg/transaction/_transaction.py", line 205, in savepoint
return savepoint
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/transaction-1.7.0-py2.7.egg/transaction/_transaction.py", line 682, in __init__
savepoint = savepoint()
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 1178, in savepoint
self._commit(None)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 639, in _commit
self._store_objects(ObjectWriter(obj), transaction)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 698, in _store_objects
s = self._storage.store(oid, serial, p, '', transaction)
File "/srv/slapgrid/slappart10/srv/runner/software/f57b129e434a946b25a1a611eef1a7d0/eggs/ZODB-4.4.5-py2.7.egg/ZODB/Connection.py", line 1341, in store
self._file.seek(self.position)
##############################################################################
#
# Copyright (c) 2018 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from slapos.test.promise.plugin import TestPromisePluginMixin
import os
from slapos.test.promise import data
import time
from slapos.grid.promise import PromiseError
class TestCheckErrorOnZopeLongrequestLog(TestPromisePluginMixin):
def setUp(self):
TestPromisePluginMixin.setUp(self)
self.promise_name = "check-error-on-zope_longrequest-log.py"
self.base_path = "/".join(data.__file__.split("/")[:-1])
self.log_file = self.base_path + "/longrequest_logger_zope.log"
self.test_log_file = self.base_path + "/SOFTINST-0_longrequest_logger_zope.log"
self._update_logs()
def get_time(self, sec):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()-sec))
def _update_logs(self):
i = 600
new = ""
old = ""
with open(self.log_file) as f:
for line in f:
new += line.replace("DATETIME", self.get_time(i))
old += line.replace("DATETIME", self.get_time(i + 3600))
i -= 1
with open(self.test_log_file, "w") as f:
f.write(old)
f.write(new)
def test_01_no_delay_no_error_threshold(self):
content = """from slapos.promise.plugin.check_error_on_zope_longrequest_log import RunPromise
extra_config_dict = {
'log-file': '%(log_file)s',
'error-threshold': 0,
'maximum-delay': 0
}
""" % {'log_file': self.test_log_file}
self.writePromise(self.promise_name, content)
self.configureLauncher()
with self.assertRaises(PromiseError):
self.launcher.run()
result = self.getPromiseResult(self.promise_name)
self.assertEquals(result['result']['message'], "ERROR=6")
def test_02_no_delay_error_threshold(self):
content = """from slapos.promise.plugin.check_error_on_zope_longrequest_log import RunPromise
extra_config_dict = {
'log-file': '%(log_file)s',
'error-threshold': 7,
'maximum-delay': 0
}
""" % {'log_file': self.test_log_file}
self.writePromise(self.promise_name, content)
self.configureLauncher()
self.launcher.run()
result = self.getPromiseResult(self.promise_name)
self.assertEquals(result['result']['message'], "INFO=6")
def test_03_delay_no_error_threshold(self):
content = """from slapos.promise.plugin.check_error_on_zope_longrequest_log import RunPromise
extra_config_dict = {
'log-file': '%(log_file)s',
'error-threshold': 2,
'maximum-delay': 3600
}
""" % {'log_file': self.test_log_file}
self.writePromise(self.promise_name, content)
self.configureLauncher()
with self.assertRaises(PromiseError):
self.launcher.run()
result = self.getPromiseResult(self.promise_name)
self.assertEquals(result['result']['message'], "ERROR=3")
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment