Commit 34981cd7 authored by bourgesl's avatar bourgesl
Browse files

Merge branch 'release/2021_02_09'

parents d129ae4f 78f7e657
Pipeline #59560 skipped with stage
......@@ -264,8 +264,17 @@ class EsoWrapperFactory(object):
logger.debug(f"from_cache(): cache file '{cache_file_path}' missing")
return None
# get file stats:
file_stats = os.stat(cache_file_path)
# Case 1b: Cache file is 0-size (empty <=> I/O write failure):
if file_stats.st_size == 0:
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"from_cache(): cache file '{cache_file_path}' is empty")
return None
if date_updated:
a_mtime = arrow.get(os.stat(cache_file_path).st_mtime).floor('second')
a_mtime = arrow.get(file_stats.st_mtime).floor('second')
# It's necessary to reset the timezone (to UTC)...
a_updated = arrow.get(date_updated).floor('second').to('UTC')
......@@ -305,17 +314,18 @@ class EsoWrapperFactory(object):
html_content_root = BeautifulSoup(html_content, 'html5lib')
header_string = html_content_root.select('pre')[0].text
# Save cache file
cache_file_path = self.build_cache_path(header_id, make_dirs=True)
logger.info(f"from_eso(): save cache file '{cache_file_path}'")
if len(header_string):
# Save cache file (not empty <=> I/O write failure):
cache_file_path = self.build_cache_path(header_id, make_dirs=True)
logger.info(f"from_eso(): save cache file '{cache_file_path}'")
with open(cache_file_path, 'w') as output_file:
output_file.write(header_string)
with open(cache_file_path, 'w') as output_file:
output_file.write(header_string)
if date_updated:
# It's necessary to reset the timezone (to UTC)...
a_updated = arrow.get(date_updated).floor('second').to('UTC')
self.setFileModTime(cache_file_path, a_updated)
if date_updated:
# It's necessary to reset the timezone (to UTC)...
a_updated = arrow.get(date_updated).floor('second').to('UTC')
self.setFileModTime(cache_file_path, a_updated)
# Build ESO Wrapper from string
header = self.from_string(header_string, header_id, date_updated)
......
......@@ -40,6 +40,7 @@ class ViewHealth(ViewAbstract):
pg_stats = None
db_tags = None
state = True
try:
# 1. Database availability
self.db_session.execute("SELECT 1")
......@@ -89,34 +90,36 @@ class ViewHealth(ViewAbstract):
last_mod_date = Header.last_modification_date(self.db_session)
# Set HTTP 500 to let kubernetes liveliness fail
except DBAPIError:
self.request.response.status = 500
state = False
except OperationalError:
self.request.response.status = 500
state = False
except StatementError:
self.request.response.status = 500
state = False
# 3: Data path
services['data directory'] = os.path.exists(self.settings.get('obsportal.paths.data'))
services['data directory'] = check_path(self.settings.get('obsportal.paths.data'))
# 4: Logs path
services['logs directory'] = os.path.exists(self.settings.get('obsportal.paths.logs'))
services['logs directory'] = check_path(self.settings.get('obsportal.paths.logs'))
# 5: Tmp path
services['tmp directory'] = os.path.exists(self.settings.get('obsportal.paths.tmp'))
services['tmp directory'] = check_path(self.settings.get('obsportal.paths.tmp'))
# Final status on all services:
state = True
for status in services.values():
if not status:
state = False
break
if state:
# update final status on all services:
for status in services.values():
if not status:
state = False
break
if not state:
logger.warning(f"Health check failed: {services}")
# Set HTTP 500 to let kubernetes liveliness fail
self.request.response.status = 500
try:
logger.warning(f"Health check failed: {services}")
except Exception as e:
print(f"Health check failed: {services}")
return {
'settings': self.settings,
......@@ -140,3 +143,24 @@ class ViewHealth(ViewAbstract):
'pg_stats': pg_stats,
'db_tags': db_tags
}
def check_path(path, test_write=True):
state = False
try:
if os.path.exists(path):
if test_write:
# check writing in path:
test_file_path = os.path.join(path, "test-fs.log")
with open(test_file_path, 'w') as output_file:
output_file.write("TEST WRITE")
os.remove(test_file_path)
state=True
except Exception as e:
logger.error(f"check_path('{path}'): failed", e)
return state
......@@ -24,7 +24,7 @@ mv ${logFile} ${logFile}.$(date +"%F_%T")
mv ${vmFile} ${vmFile}.$(date +"%F_%T")
echo "Start vmstat in background..."
vmstat -t 10 2>&1 > ${vmFile} &
vmstat -t 60 2>&1 > ${vmFile} &
# Upgrade the database structure
CMD="obsportal-cli database upgrade --settings=client.ini"
......
Supports Markdown
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