Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.core
Commits
24fb62a4
Commit
24fb62a4
authored
Feb 09, 2018
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update, integrate to slapgrid
parent
7fb88480
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
48 deletions
+87
-48
slapos/grid/promise/__init__.py
slapos/grid/promise/__init__.py
+69
-42
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+18
-6
No files found.
slapos/grid/promise/__init__.py
View file @
24fb62a4
...
...
@@ -54,35 +54,35 @@ class BaseResult(object):
self
.
__message
=
message
self
.
__date
=
date
def
hasFailed
(
self
):
return
not
self
.
__problem
def
hasFailed
(
self
):
return
not
self
.
__problem
@
property
def
type
(
self
):
return
"Base Result"
return
"Base Result"
@
property
def
message
(
self
):
return
self
.
__message
def
message
(
self
):
return
self
.
__message
@
property
def
date
(
self
):
return
self
.
__date
return
self
.
__date
class
TestResult
(
BaseResult
):
@
property
def
type
(
self
):
return
"Test Result"
return
"Test Result"
class
AnomalyResult
(
BaseResult
):
@
property
def
type
(
self
):
return
"Anomaly Result"
return
"Anomaly Result"
class
PromiseQueueResult
(
object
):
def
__init__
(
self
,
path
,
name
,
title
,
result
,
execution_time
=
0
):
self
.
path
=
path
self
.
name
=
name
...
...
@@ -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):
...
...
@@ -386,7 +396,7 @@ class PromiseRunner(Process):
Initialise Promise Runner
@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.
"""
Process.__init__()
...
...
@@ -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,
...
...
@@ -529,15 +542,18 @@ class PromiseLauncher(object):
name=promise_name,
title=promise_instance.getTitle(),
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)
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_module,
logger=self.logger
...
...
@@ -628,26 +644,37 @@ class PromiseLauncher(object):
"""
promise_list = []
# 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)]
base_config = {
'log-folder': self.log_folder,
'partition-folder': self.partition_folder,
'debug': True,
'master-url': self.master_url,
'partition-cert': self.partition_cert,
'partition-key': self.partition_key,
'partition-id': self.partition_id,
'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]
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)]
base_config = {
'log-folder': self.log_folder,
'partition-folder': self.partition_folder,
'debug': True,
'master-url': self.master_url,
'partition-cert': self.partition_cert,
'partition-key': self.partition_key,
'partition-id': self.partition_id,
'computer-id': self.computer_id,
'queue': self.queue_result,
}
config.update(base_config)
self._launchPromise(promise, promise_name, config)
for promise in promise_list:
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)
slapos/grid/slapgrid.py
View file @
24fb62a4
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment