Commit 0b2708b4 authored by Alain Takoudjou's avatar Alain Takoudjou

new promise plugin folder, add promise to check monitor bootstrap and partition state

promise check_partition_deployment_state.py that buildout didn't fail to process the partition, if failed
the promise will show the latest buildout logs.
the promise monitor_bootstrap_status.py is used to check monitor bootstrap is ok
parent ab39414c
from zope import interface as zope_interface
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise
import os
from datetime import datetime
MONITOR_URL = ""
class RunPromise(GenericPromise):
zope_interface.implements(interface.IPromise)
def __init__(self, config):
GenericPromise.__init__(self, config)
self.setPeriodicity(minute=1)
def sense(self):
"""
Run the promise code and store the result
raise error, log error message, ... for failure
"""
partition_folder = self.getPartitionFolder()
log_folder = os.path.join(partition_folder, 'var/log')
log_name = 'slapgrid-%s-error.log' % self.getConfig('partition-id')
slapgrid_error_log_file = os.path.join(partition_folder, '.%s' % log_name)
link_file = os.path.join(log_folder, log_name)
message = ''
if os.path.exists(slapgrid_error_log_file) and \
os.stat(slapgrid_error_log_file).st_size:
message = 'Buildout failed to process %s.' % self.getConfig('partition-id')
if MONITOR_URL:
message += '\nSee %s/log/%s for more information.' % (MONITOR_URL, log_name)
if not os.path.exists(link_file):
os.symlink(slapgrid_error_log_file, link_file)
else:
if os.path.exists(link_file):
os.unlink(link_file)
if message:
self.logger.error(message)
else:
self.logger.info("buildout is OK")
def test(self):
"""
Test promise and say if problem is detected or not
Return TestResult object
"""
return self._test(result_count=1, failure_amount=1)
def anomaly(self):
return self._test(result_count=2, failure_amount=2)
from zope import interface as zope_interface
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise
import os
import time
import psutil
from slapos.runner.utils import tail
PROCESS_PID_FILE = ""
PROCESS_NAME = ""
STATUS_FILE = ""
class RunPromise(GenericPromise):
zope_interface.implements(interface.IPromise)
def __init__(self, config):
GenericPromise.__init__(self, config)
self.setPeriodicity(minute=2)
def sense(self):
if PROCESS_PID_FILE == "" or PROCESS_NAME == "" or STATUS_FILE == "":
self.logger.info("")
return
if not os.path.exists(PROCESS_PID_FILE):
self.logger.info("Bootstrap didn't run!")
return
with open(PROCESS_PID_FILE) as f:
try:
pid = int(f.read())
except ValueError, e:
raise ValueError("%r is empty or doesn't contain a valid pid number: %s" % (
PROCESS_PID_FILE, str(e)))
try:
process = psutil.Process(pid)
command_string = ' '.join(process.cmdline())
if "monitor.bootstrap" in command_string and \
self.getPartitionFolder() in command_string:
for i in range(0, 15):
if process.is_running():
time.sleep(1)
else:
break
else:
self.logger.error("Monitor bootstrap is running for more than 15 seconds!")
return
except psutil.NoSuchProcess:
# process exited
pass
if os.path.exists(STATUS_FILE) and not os.stat(STATUS_FILE).st_size:
self.logger.info("Bootstrap OK")
return
message = "Monitor bootstrap exited with error."
log_file = os.path.join(self.getPartitionFolder(), ".%s_%s.log" % (
self.getConfig('partition-id'),
PROCESS_NAME))
if os.path.exists(log_file):
with open(log_file) as f:
message += "\n ---- Latest monitor-boostrap.log ----\n"
message += tail(f, 4)
self.logger.error(message)
def test(self):
return self._test(result_count=1, failure_amount=1)
def anomaly(self):
# bang if we have 3 error successively
return self._anomaly(result_count=3, failure_amount=3)
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