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

update, integrate to slapgrid

parent 7fb88480
......@@ -363,16 +363,26 @@ class PromiseWrapper(GenericPromise):
self.logger.info(message)
def test(self):
failed = False
"""
Fail if the latest 2 messages has failed.
"""
failed_count = 0
message = ""
latest_result_list = self.getLastPromiseResultList(latest_minute=2,
latest_result_list = self.getLastPromiseResultList(latest_minute=4,
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):
......@@ -426,6 +436,8 @@ class PromiseLauncher(object):
Base path of the partition
promise-dir
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
Folder where promises will write logs. Can be None
check-anomaly
......@@ -453,6 +465,7 @@ class PromiseLauncher(object):
self.__config = {
'promise-timeout': 20,
'promise-dir': None,
'old-promise-dir': None,
'log-folder': None,
'profile': False,
'uid': None,
......@@ -531,12 +544,15 @@ class PromiseLauncher(object):
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
If no save method is set, raise PromiseError in case of failure
"""
self.logger.info("Checking promise %s..." % promise_name)
if promise_module is None:
promise_instance = PromiseWrapper(argument_dict)
else:
promise_instance = promise_module.RunPromise(argument_dict)
promise_process = PromiseRunner(
promise_module,
......@@ -628,6 +644,7 @@ class PromiseLauncher(object):
"""
promise_list = []
if os.path.exists(self.promise_dir) and os.path.isdir(self.promise_dir):
# load all promises so we can catch import errors before launch them
promise_list = [(promise_name, self._loadPromiseModule(promise_name))
for promise_name in os.listdir(self.promise_dir)]
......@@ -649,5 +666,15 @@ class PromiseLauncher(object):
'name': promise[0]
}
config.update(base_config)
self._launchPromise(promise, promise_name, 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,
createSupervisordConfiguration,
_getSupervisordConfigurationDirectory,
_getSupervisordSocketPath)
from slapos.grid.utils import (md5digest, dropPrivileges, SlapPopen, updateFile,
checkPromiseList, PromiseError)
from slapos.grid.utils import (md5digest, dropPrivileges, SlapPopen, updateFile)
from slapos.grid.promise import PromiseLauncher
from slapos.human import human2bytes
import slapos.slap
from netaddr import valid_ipv4, valid_ipv6
......@@ -627,12 +627,24 @@ stderr_logfile_backups=1
#stat sys call to get statistics informations
uid = stat_info.st_uid
gid = stat_info.st_gid
promise_dir = os.path.join(instance_path, 'etc', 'promise')
if not checkPromiseList(promise_dir, self.promise_timeout, uid=uid, gid=gid,
promise_dir = os.path.join(instance_path, 'etc', 'plugins')
old_promise_dir = os.path.join(instance_path, 'etc', 'promise')
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,
raise_on_failure=True):
self.logger.info("No promise.")
self.logger.info("No promise.")"""
def _endInstallationTransaction(self, computer_partition):
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