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
7dbd8742
Commit
7dbd8742
authored
Feb 14, 2018
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make promise runner work on monitor
parent
ed597075
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
40 deletions
+36
-40
slapos/grid/promise/__init__.py
slapos/grid/promise/__init__.py
+36
-40
No files found.
slapos/grid/promise/__init__.py
View file @
7dbd8742
...
...
@@ -33,7 +33,6 @@ import sys
import
logging
import
time
import
importlib
import
ConfigParser
import
re
import
traceback
import
psutil
...
...
@@ -43,7 +42,6 @@ from abc import ABCMeta, abstractmethod
from
multiprocessing
import
Process
,
Queue
as
MQueue
import
Queue
from
datetime
import
datetime
,
timedelta
from
threading
import
Thread
from
slapos.grid.promise
import
interface
from
slapos.grid.utils
import
dropPrivileges
from
zope
import
interface
as
zope_interface
...
...
@@ -57,7 +55,7 @@ class BaseResult(object):
self
.
__message
=
message
self
.
__date
=
date
if
self
.
__date
is
None
:
self
.
__date
=
datetime
.
now
()
self
.
__date
=
datetime
.
utc
now
()
def
hasFailed
(
self
):
return
self
.
__problem
...
...
@@ -91,7 +89,8 @@ class PromiseQueueResult(object):
def
__init__
(
self
,
path
,
name
,
title
,
result
,
execution_time
=
0
):
self
.
path
=
path
self
.
name
=
name
self
.
result
=
result
self
.
item
=
result
self
.
title
=
title
self
.
execution_time
=
execution_time
class
GenericPromise
(
object
):
...
...
@@ -448,8 +447,7 @@ class PromiseRunner(Process):
class PromiseLauncher(object):
def __init__(self, config=None, logger=None, config_file=None,
save_method=None):
def __init__(self, config=None, logger=None, save_method=None):
"""
Promise launcher will run promises
...
...
@@ -464,9 +462,9 @@ class PromiseLauncher(object):
Maximum promise execution time before timeout. Default: 20
partition-folder
Base path of the partition
promise-
di
r
promise-
folde
r
Promises folder, all promises scripts will be imported from that folder
old-promise-
di
r
old-promise-
folde
r
Old promises folder, where to find bash, shell and standard promises
log-folder
Folder where promises will write logs. Can be None
...
...
@@ -490,14 +488,17 @@ class PromiseLauncher(object):
User GID
profile
If True, show Promise consumption and execution time information
run-only-promise-list:
A list of promise from plugins directory that will be executed
"""
self.save_method = save_method
self.__config = {
'promise-timeout': 20,
'promise-
di
r': None,
'old-promise-
di
r': None,
'promise-
folde
r': None,
'old-promise-
folde
r': None,
'log-folder': None,
'partition-folder': None,
'profile': False,
'uid': None,
'gid': None,
...
...
@@ -507,17 +508,16 @@ class PromiseLauncher(object):
'partition-id': None,
'computer-id': None,
'debug': True,
'check-anomaly': False
'check-anomaly': False,
'run-only-promise-list': None
}
if config_file is not None:
self.loadConfigFromFile(config_file)
if config is not None:
self.__config.update(config)
for key, value in self.__config.items():
setattr(self, key.replace('-', '_'), value or None)
if self.promise_
di
r is None:
if self.promise_
folde
r is None:
raise ValueError("
Promise
folder
is
missing
in
configuration
!
")
if logger is None:
...
...
@@ -534,13 +534,6 @@ class PromiseLauncher(object):
self.queue_result = MQueue()
self.bang_called = False
def _loadConfigFromFile(self, config_file):
config = ConfigParser.ConfigParser()
config.read([config_file])
if config.has_section('promises'):
for key, value in config.items('promises'):
self.__config[key] = value
def _loadPromiseModule(self, promise_name):
"""Load a promise from promises directory."""
...
...
@@ -568,8 +561,8 @@ class PromiseLauncher(object):
else:
result = TestResult(problem=True, message=message)
return PromiseQueueResult(
result
=result,
path=os.path.join(self.promise_
di
r, promise_name),
item
=result,
path=os.path.join(self.promise_
folde
r, promise_name),
name=promise_name,
title=promise_instance.getTitle(),
execution_time=execution_time
...
...
@@ -580,8 +573,7 @@ class PromiseLauncher(object):
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 self.profile:
self.logger.info("
Checking
promise
%
s
...
" % promise_name)
self.logger.info("
Checking
promise
%
s
...
" % promise_name)
try:
if promise_module is None:
promise_instance = PromiseWrapper(argument_dict)
...
...
@@ -629,19 +621,19 @@ class PromiseLauncher(object):
messsage="
No
output
returned
by
the
promise
",
execution_time=execution_time
)
self.save_method(queue_item)
self.save_method(
result=
queue_item)
break
if queue_item.
result
.hasFailed():
if queue_item.
item
.hasFailed():
if self.save_method is None:
raise PromiseError(queue_item.
result
.message)
elif isinstance(queue_item.
result
, AnomalyResult):
raise PromiseError(queue_item.
item
.message)
elif isinstance(queue_item.
item
, AnomalyResult):
# stop to bang as it was called
self.bang_called = True
if self.save_method is not None:
queue_item.execution_time = execution_time
self.save_method(queue_item)
self.save_method(
result=
queue_item)
break
if ps_profile:
...
...
@@ -667,7 +659,7 @@ class PromiseLauncher(object):
if self.save_method is None:
raise PromiseError(message)
else:
self.save_method(self._getErrorPromiseResult(
self.save_method(
result=
self._getErrorPromiseResult(
promise_instance,
promise_name=promise_name,
message=message,
...
...
@@ -694,37 +686,41 @@ class PromiseLauncher(object):
'queue': self.queue_result,
}
if os.path.exists(self.promise_
dir) and os.path.isdir(self.promise_di
r):
if os.path.exists(self.promise_
folder) and os.path.isdir(self.promise_folde
r):
# if there is no __init file, add it
init_file = os.path.join(self.promise_
di
r, '__init__.py')
init_file = os.path.join(self.promise_
folde
r, '__init__.py')
if not os.path.exists(init_file):
with open(init_file, 'w') as f:
f.write("")
os.chmod(init_file, 0644)
if sys.path[0] != self.promise_
di
r:
sys.path[0:0] = [self.promise_
di
r]
if sys.path[0] != self.promise_
folde
r:
sys.path[0:0] = [self.promise_
folde
r]
promise_list = []
# load all promises so we can catch import errors before launch them
for promise_name in os.listdir(self.promise_
di
r):
for promise_name in os.listdir(self.promise_
folde
r):
if promise_name.startswith('__init__') or
\
not promise_name.endswith('.py'):
continue
if self.run_only_promise_list is not None and not
\
promise_name in self.run_only_promise_list:
continue
promise_list.append((promise_name,
self._loadPromiseModule(promise_name)))
for promise in promise_list:
config = {
'path': os.path.join(self.promise_
di
r, promise[0]),
'path': os.path.join(self.promise_
folde
r, promise[0]),
'name': promise[0]
}
config.update(base_config)
self._launchPromise(promise_name, config, promise[1])
if os.path.exists(self.old_promise_dir) and os.path.isdir(self.old_promise_dir):
if not self.run_only_promise_list and os.path.exists(self.old_promise_folder)
\
and os.path.isdir(self.old_promise_folder):
# run old promise styles
for promise_name in os.listdir(self.old_promise_
di
r):
promise_path = os.path.join(self.old_promise_
di
r, promise_name)
for promise_name in os.listdir(self.old_promise_
folde
r):
promise_path = os.path.join(self.old_promise_
folde
r, promise_name)
if not os.path.isfile(promise_path) or
\
not os.access(promise_path, os.X_OK):
self.logger.warning("
Bad
promise
file
at
%
r
.
" % promise_path)
...
...
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