Commit 24fb62a4 authored by Alain Takoudjou's avatar Alain Takoudjou

update, integrate to slapgrid

parent 7fb88480
...@@ -54,35 +54,35 @@ class BaseResult(object): ...@@ -54,35 +54,35 @@ class BaseResult(object):
self.__message = message self.__message = message
self.__date = date self.__date = date
def hasFailed(self): def hasFailed(self):
return not self.__problem return not self.__problem
@property @property
def type(self): def type(self):
return "Base Result" return "Base Result"
@property @property
def message(self): def message(self):
return self.__message return self.__message
@property @property
def date(self): def date(self):
return self.__date return self.__date
class TestResult(BaseResult): class TestResult(BaseResult):
@property @property
def type(self): def type(self):
return "Test Result" return "Test Result"
class AnomalyResult(BaseResult): class AnomalyResult(BaseResult):
@property @property
def type(self): def type(self):
return "Anomaly Result" return "Anomaly Result"
class PromiseQueueResult(object): class PromiseQueueResult(object):
def __init__(self, path, name, title, result, execution_time=0): def __init__(self, path, name, title, result, execution_time=0):
self.path = path self.path = path
self.name = name self.name = name
...@@ -363,16 +363,26 @@ class PromiseWrapper(GenericPromise): ...@@ -363,16 +363,26 @@ class PromiseWrapper(GenericPromise):
self.logger.info(message) self.logger.info(message)
def test(self): def test(self):
failed = False """
Fail if the latest 2 messages has failed.
"""
failed_count = 0
message = "" message = ""
latest_result_list = self.getLastPromiseResultList(latest_minute=2, latest_result_list = self.getLastPromiseResultList(latest_minute=4,
only_failure=False) only_failure=False)
for result in latest_result_list:
if result[1] == 'ERROR':
failed = True
message += '\n' + result[2]
return TestResult(problem=failed, message=message) if len(latest_result_list) == 0:
return TestResult(problem=False, message="No result")
latest_result_list.reverse()
for in in range(0, 2):
if latest_result_list[i][1] == 'ERROR':
failed_count += 1
return TestResult(
problem=failed_count == 2,
message=latest_result_list[0][2]
)
class PromiseRunner(Process): class PromiseRunner(Process):
...@@ -386,7 +396,7 @@ class PromiseRunner(Process): ...@@ -386,7 +396,7 @@ class PromiseRunner(Process):
Initialise Promise Runner Initialise Promise Runner
@param promise_instance: Promise instance from GenericPromise class @param promise_instance: Promise instance from GenericPromise class
@param allow_bang: Bolean saying if bang should be called in case of @param allow_bang: Bolean saying if bang should be called in case of
anomaly failure. anomaly failure.
""" """
Process.__init__() Process.__init__()
...@@ -426,6 +436,8 @@ class PromiseLauncher(object): ...@@ -426,6 +436,8 @@ class PromiseLauncher(object):
Base path of the partition Base path of the partition
promise-dir promise-dir
Promises folder, all promises scripts will be imported from that folder Promises folder, all promises scripts will be imported from that folder
old-promise-dir
Old promises folder, where to find bash, shell and standard promises
log-folder log-folder
Folder where promises will write logs. Can be None Folder where promises will write logs. Can be None
check-anomaly check-anomaly
...@@ -453,6 +465,7 @@ class PromiseLauncher(object): ...@@ -453,6 +465,7 @@ class PromiseLauncher(object):
self.__config = { self.__config = {
'promise-timeout': 20, 'promise-timeout': 20,
'promise-dir': None, 'promise-dir': None,
'old-promise-dir': None,
'log-folder': None, 'log-folder': None,
'profile': False, 'profile': False,
'uid': None, 'uid': None,
...@@ -529,15 +542,18 @@ class PromiseLauncher(object): ...@@ -529,15 +542,18 @@ class PromiseLauncher(object):
name=promise_name, name=promise_name,
title=promise_instance.getTitle(), title=promise_instance.getTitle(),
execution_time=execution_time execution_time=execution_time
) )
def _launchPromise(self, promise_module, promise_name, argument_dict): def _launchPromise(self, promise_name, argument_dict, promise_module=None):
""" """
Launch the promise and save the result if `self.save_method` is not None Launch the promise and save the result if `self.save_method` is not None
If no save method is set, raise PromiseError in case of failure If no save method is set, raise PromiseError in case of failure
""" """
self.logger.info("Checking promise %s..." % promise_name) self.logger.info("Checking promise %s..." % promise_name)
promise_instance = promise_module.RunPromise(argument_dict) if promise_module is None:
promise_instance = PromiseWrapper(argument_dict)
else:
promise_instance = promise_module.RunPromise(argument_dict)
promise_process = PromiseRunner( promise_process = PromiseRunner(
promise_module, promise_module,
logger=self.logger logger=self.logger
...@@ -628,26 +644,37 @@ class PromiseLauncher(object): ...@@ -628,26 +644,37 @@ class PromiseLauncher(object):
""" """
promise_list = [] promise_list = []
# load all promises so we can catch import errors before launch them if os.path.exists(self.promise_dir) and os.path.isdir(self.promise_dir):
promise_list = [(promise_name, self._loadPromiseModule(promise_name)) # load all promises so we can catch import errors before launch them
for promise_name in os.listdir(self.promise_dir)] promise_list = [(promise_name, self._loadPromiseModule(promise_name))
for promise_name in os.listdir(self.promise_dir)]
base_config = {
'log-folder': self.log_folder, base_config = {
'partition-folder': self.partition_folder, 'log-folder': self.log_folder,
'debug': True, 'partition-folder': self.partition_folder,
'master-url': self.master_url, 'debug': True,
'partition-cert': self.partition_cert, 'master-url': self.master_url,
'partition-key': self.partition_key, 'partition-cert': self.partition_cert,
'partition-id': self.partition_id, 'partition-key': self.partition_key,
'computer-id': self.computer_id, 'partition-id': self.partition_id,
'queue': self.queue_result, 'computer-id': self.computer_id,
} 'queue': self.queue_result,
for promise in promise_list:
config = {
'path': os.path.join(self.promise_dir, promise[0]),
'name': promise[0]
} }
config.update(base_config) for promise in promise_list:
self._launchPromise(promise, promise_name, config) config = {
'path': os.path.join(self.promise_dir, promise[0]),
'name': promise[0]
}
config.update(base_config)
self._launchPromise(promise_name, config, promise)
if os.path.exists(self.old_promise_dir) and os.path.isdir(self.old_promise_dir):
# run old promise styles
for promise_name in self.old_promise_dir:
config = {
'path': os.path.join(self.old_promise_dir, promise_name),
'name': promise_name
}
config.update(base_config)
# We will use PromiseWrapper class to run this
self._launchPromise(promise_name, config)
...@@ -60,8 +60,8 @@ from slapos.grid.svcbackend import (launchSupervisord, ...@@ -60,8 +60,8 @@ from slapos.grid.svcbackend import (launchSupervisord,
createSupervisordConfiguration, createSupervisordConfiguration,
_getSupervisordConfigurationDirectory, _getSupervisordConfigurationDirectory,
_getSupervisordSocketPath) _getSupervisordSocketPath)
from slapos.grid.utils import (md5digest, dropPrivileges, SlapPopen, updateFile, from slapos.grid.utils import (md5digest, dropPrivileges, SlapPopen, updateFile)
checkPromiseList, PromiseError) from slapos.grid.promise import PromiseLauncher
from slapos.human import human2bytes from slapos.human import human2bytes
import slapos.slap import slapos.slap
from netaddr import valid_ipv4, valid_ipv6 from netaddr import valid_ipv4, valid_ipv6
...@@ -627,12 +627,24 @@ stderr_logfile_backups=1 ...@@ -627,12 +627,24 @@ stderr_logfile_backups=1
#stat sys call to get statistics informations #stat sys call to get statistics informations
uid = stat_info.st_uid uid = stat_info.st_uid
gid = stat_info.st_gid gid = stat_info.st_gid
promise_dir = os.path.join(instance_path, 'etc', 'promise') promise_dir = os.path.join(instance_path, 'etc', 'plugins')
old_promise_dir = os.path.join(instance_path, 'etc', 'promise')
if not checkPromiseList(promise_dir, self.promise_timeout, uid=uid, gid=gid, promise_config = {
'promise-dir': promise_dir,
'old-promise-dir': old_promise_dir,
'promise-timeout': self.promise_timeout,
'uid': uid,
'gid': gid,
'partition-folder': instance_path
}
promise_checker = PromiseLauncher(config=promise_config, logger=self.logger)
return promise_checker.run()
"""if not checkPromiseList(promise_dir, self.promise_timeout, uid=uid, gid=gid,
cwd=instance_path, logger=self.logger, profile=False, cwd=instance_path, logger=self.logger, profile=False,
raise_on_failure=True): raise_on_failure=True):
self.logger.info("No promise.") self.logger.info("No promise.")"""
def _endInstallationTransaction(self, computer_partition): def _endInstallationTransaction(self, computer_partition):
partition_id = computer_partition.getId() partition_id = computer_partition.getId()
......
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