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
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
1d1bcf8b
Commit
1d1bcf8b
authored
Mar 15, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Plain Diff
slapgrid: Fix promises not being logged to logfile
See merge request
nexedi/slapos.core!356
parents
3c0c7a03
c879dd93
Pipeline
#20167
failed with stage
in 0 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
21 deletions
+56
-21
slapos/grid/promise/runpromises.py
slapos/grid/promise/runpromises.py
+5
-5
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+18
-14
slapos/grid/utils.py
slapos/grid/utils.py
+7
-2
slapos/tests/test_slapgrid.py
slapos/tests/test_slapgrid.py
+26
-0
No files found.
slapos/grid/promise/runpromises.py
View file @
1d1bcf8b
...
@@ -60,11 +60,11 @@ promise_checker = PromiseLauncher(config=config, logger=app.log)
...
@@ -60,11 +60,11 @@ promise_checker = PromiseLauncher(config=config, logger=app.log)
# Run promises
# Run promises
# Redirect std
out to stderr (logger only uses stderr already
)
# Redirect std
err to stdout (logger uses stderr
)
# to reserve std
out
for error reporting
# to reserve std
err exclusively
for error reporting
out
=
os
.
dup
(
1
)
err
=
os
.
dup
(
2
)
os
.
dup2
(
2
,
1
)
os
.
dup2
(
1
,
2
)
try
:
try
:
promise_checker
.
run
()
promise_checker
.
run
()
...
@@ -73,5 +73,5 @@ except Exception as e:
...
@@ -73,5 +73,5 @@ except Exception as e:
error_str
=
unicode
(
str
(
e
),
'utf-8'
,
'repr'
)
error_str
=
unicode
(
str
(
e
),
'utf-8'
,
'repr'
)
else
:
else
:
error_str
=
str
(
e
)
error_str
=
str
(
e
)
os
.
write
(
out
,
error_str
.
encode
(
'utf-8'
,
'repr'
))
os
.
write
(
err
,
error_str
.
encode
(
'utf-8'
,
'repr'
))
sys
.
exit
(
2
if
isinstance
(
e
,
PromiseError
)
else
1
)
sys
.
exit
(
2
if
isinstance
(
e
,
PromiseError
)
else
1
)
slapos/grid/slapgrid.py
View file @
1d1bcf8b
...
@@ -726,26 +726,30 @@ stderr_logfile_backups=1
...
@@ -726,26 +726,30 @@ stderr_logfile_backups=1
else
:
else
:
command
.
append
(
'--'
+
option
)
command
.
append
(
'--'
+
option
)
command
.
append
(
str
(
value
))
command
.
append
(
str
(
value
))
process
=
subprocess
.
Popen
(
command
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
,
logger
=
self
.
logger
),
cwd
=
instance_path
,
universal_newlines
=
True
,
stdout
=
subprocess
.
PIPE
)
promises
=
plugins
+
len
(
listifdir
(
legacy_promise_dir
))
promises
=
plugins
+
len
(
listifdir
(
legacy_promise_dir
))
# Add a timeout margin to let the process kill the promises and cleanup
# Add a timeout margin to let the process kill the promises and cleanup
timeout
=
promises
*
self
.
promise_timeout
+
10
timeout
=
promises
*
self
.
promise_timeout
+
10
# The runpromise script uses stderr exclusively to propagate exception
# messages. It otherwise redirects stderr to stdout so that all outputs
# from the promises go to stdout.
try
:
try
:
# The logger logs everything to stderr, so runpromise redirects
process
=
SlapPopen
(
# stdout to stderr in case a promise prints to stdout
command
,
# and reserves stdout to progagate exception messages.
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
,
logger
=
self
.
logger
),
out
,
_
=
process
.
communicate
(
timeout
=
timeout
)
cwd
=
instance_path
,
universal_newlines
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
logger
=
self
.
logger
,
timeout
=
timeout
,
)
stderr
=
process
.
stderr
.
read
()
if
process
.
returncode
==
2
:
if
process
.
returncode
==
2
:
raise
PromiseError
(
out
)
raise
PromiseError
(
stderr
)
elif
process
.
returncode
:
elif
process
.
returncode
:
raise
Exception
(
out
)
raise
Exception
(
stderr
)
elif
out
:
elif
stderr
:
self
.
logger
.
warn
(
'Promise runner unexpected output:
\
n
%s'
,
out
)
self
.
logger
.
warn
(
'Promise runner unexpected output:
\
n
%s'
,
stderr
)
except
subprocess
.
TimeoutExpired
:
except
subprocess
.
TimeoutExpired
:
killProcessTree
(
process
.
pid
,
self
.
logger
)
killProcessTree
(
process
.
pid
,
self
.
logger
)
# The timeout margin was exceeded but this should be infrequent
# The timeout margin was exceeded but this should be infrequent
...
...
slapos/grid/utils.py
View file @
1d1bcf8b
...
@@ -34,13 +34,17 @@ import os
...
@@ -34,13 +34,17 @@ import os
import
pkg_resources
import
pkg_resources
import
pwd
import
pwd
import
stat
import
stat
import
subprocess
import
sys
import
sys
import
threading
import
threading
import
logging
import
logging
import
psutil
import
psutil
import
time
import
time
if
sys
.
version_info
>=
(
3
,):
import
subprocess
else
:
import
subprocess32
as
subprocess
from
slapos.grid.exception
import
BuildoutFailedError
,
WrongPermissionError
from
slapos.grid.exception
import
BuildoutFailedError
,
WrongPermissionError
...
@@ -119,6 +123,7 @@ class SlapPopen(subprocess.Popen):
...
@@ -119,6 +123,7 @@ class SlapPopen(subprocess.Popen):
"""
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
logger
=
kwargs
.
pop
(
'logger'
)
logger
=
kwargs
.
pop
(
'logger'
)
timeout
=
kwargs
.
pop
(
'timeout'
,
None
)
debug
=
kwargs
.
pop
(
'debug'
,
False
)
debug
=
kwargs
.
pop
(
'debug'
,
False
)
if
debug
:
if
debug
:
...
@@ -154,7 +159,7 @@ class SlapPopen(subprocess.Popen):
...
@@ -154,7 +159,7 @@ class SlapPopen(subprocess.Popen):
args
=
(
self
.
stdout
,
output_lines
,
logger
))
args
=
(
self
.
stdout
,
output_lines
,
logger
))
t
.
start
()
t
.
start
()
try
:
try
:
self
.
wait
()
self
.
wait
(
timeout
=
timeout
)
finally
:
finally
:
t
.
join
()
t
.
join
()
self
.
output
=
''
.
join
(
output_lines
)
self
.
output
=
''
.
join
(
output_lines
)
...
...
slapos/tests/test_slapgrid.py
View file @
1d1bcf8b
...
@@ -4214,6 +4214,32 @@ class TestSlapgridPluginPromiseWithInstancePython(TestSlapgridPromiseWithMaster)
...
@@ -4214,6 +4214,32 @@ class TestSlapgridPluginPromiseWithInstancePython(TestSlapgridPromiseWithMaster)
dummyLogger.mock_calls[-1][1][0] % dummyLogger.mock_calls[-1][1][1:],
dummyLogger.mock_calls[-1][1][0] % dummyLogger.mock_calls[-1][1][1:],
"
0
[(
not
ready
)]:
Promise
'failing_promise_plugin.py'
failed
with
output
:
h
é
h
é
fake
promise
plugin
error
")
"
0
[(
not
ready
)]:
Promise
'failing_promise_plugin.py'
failed
with
output
:
h
é
h
é
fake
promise
plugin
error
")
def test_succeeding_promise_logs_output(self):
computer = self.getTestComputerClass()(self.software_root, self.instance_root, 1, 1)
instance, = computer.instance_list
name = "
succeeding_promise_plugin
.
py
"
output = "
hehe
fake
promise
plugin
succeded
!
"
instance.requested_state = 'started'
instance.setPluginPromise(
name,
promise_content="""if 1:
return self.logger.info(%r)
""" % output,
)
with httmock.HTTMock(computer.request_handler),
\
patch.object(self.grid.logger, 'info',) as dummyLogger:
self.launchSlapgrid()
self.assertIn(
"
Checking
promise
%
s
...
" % name,
dummyLogger.mock_calls[-4][1][0] % dummyLogger.mock_calls[-4][1][1:])
self.assertIn(
output,
dummyLogger.mock_calls[-3][1][0] % dummyLogger.mock_calls[-3][1][1:])
class TestSlapgridPluginPromiseWithInstancePythonOldSlapOSCompatibility(
class TestSlapgridPluginPromiseWithInstancePythonOldSlapOSCompatibility(
...
...
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