Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Nicolas Wavrant
slapos.toolbox
Commits
14aad48d
Commit
14aad48d
authored
Apr 04, 2018
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise.plugin: uses 'extra_config_dict' to send custom promise parameters
/reviewed-on
nexedi/slapos.toolbox!33
parent
4460d47a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
25 deletions
+47
-25
slapos/promise/plugin/check_partition_deployment_state.py
slapos/promise/plugin/check_partition_deployment_state.py
+3
-4
slapos/promise/plugin/monitor_bootstrap_status.py
slapos/promise/plugin/monitor_bootstrap_status.py
+10
-17
slapos/promise/plugin/util.py
slapos/promise/plugin/util.py
+29
-0
slapos/test/promise/plugin/test_monitor_bootstrap_status.py
slapos/test/promise/plugin/test_monitor_bootstrap_status.py
+5
-4
No files found.
slapos/promise/plugin/check_partition_deployment_state.py
View file @
14aad48d
...
...
@@ -4,8 +4,6 @@ from slapos.grid.promise.generic import GenericPromise
import
os
from
datetime
import
datetime
MONITOR_URL
=
""
class
RunPromise
(
GenericPromise
):
zope_interface
.
implements
(
interface
.
IPromise
)
...
...
@@ -25,12 +23,13 @@ class RunPromise(GenericPromise):
log_name
=
'slapgrid-%s-error.log'
%
self
.
getConfig
(
'partition-id'
)
slapgrid_error_log_file
=
os
.
path
.
join
(
partition_folder
,
'.%s'
%
log_name
)
link_file
=
os
.
path
.
join
(
log_folder
,
log_name
)
monitor_url
=
self
.
getConfig
(
'monitor-url'
)
message
=
''
if
os
.
path
.
exists
(
slapgrid_error_log_file
)
and
\
os
.
stat
(
slapgrid_error_log_file
).
st_size
:
message
=
'Buildout failed to process %s.'
%
self
.
getConfig
(
'partition-id'
)
if
MONITOR_URL
:
message
+=
'
\
n
See %s/log/%s for more information.'
%
(
MONITOR_URL
,
log_name
)
if
monitor_url
:
message
+=
'
\
n
See %s/log/%s for more information.'
%
(
monitor_url
,
log_name
)
if
not
os
.
path
.
exists
(
link_file
):
os
.
symlink
(
slapgrid_error_log_file
,
link_file
)
else
:
...
...
slapos/promise/plugin/monitor_bootstrap_status.py
View file @
14aad48d
...
...
@@ -4,11 +4,7 @@ from slapos.grid.promise.generic import GenericPromise
import
os
import
time
import
psutil
from
slapos.runner.utils
import
tail
PROCESS_PID_FILE
=
""
PROCESS_NAME
=
""
STATUS_FILE
=
""
from
.util
import
tail_file
class
RunPromise
(
GenericPromise
):
...
...
@@ -19,20 +15,17 @@ class RunPromise(GenericPromise):
self
.
setPeriodicity
(
minute
=
2
)
def
sense
(
self
):
if
PROCESS_PID_FILE
==
""
or
PROCESS_NAME
==
""
or
STATUS_FILE
==
""
:
self
.
logger
.
info
(
""
)
return
if
not
os
.
path
.
exists
(
PROCESS_PID_FILE
):
process_pid_file
=
self
.
getConfig
(
'process-pid-file'
)
if
not
os
.
path
.
exists
(
process_pid_file
):
self
.
logger
.
info
(
"Bootstrap didn't run!"
)
return
with
open
(
PROCESS_PID_FILE
)
as
f
:
with
open
(
process_pid_file
)
as
f
:
try
:
pid
=
int
(
f
.
read
())
except
ValueError
,
e
:
raise
ValueError
(
"%r is empty or doesn't contain a valid pid number: %s"
%
(
PROCESS_PID_FILE
,
str
(
e
)))
process_pid_file
,
str
(
e
)))
try
:
process
=
psutil
.
Process
(
pid
)
...
...
@@ -51,18 +44,18 @@ class RunPromise(GenericPromise):
# process exited
pass
if
os
.
path
.
exists
(
STATUS_FILE
)
and
not
os
.
stat
(
STATUS_FILE
).
st_size
:
status_file
=
self
.
getConfig
(
'status-file'
)
if
os
.
path
.
exists
(
status_file
)
and
not
os
.
stat
(
status_file
).
st_size
:
self
.
logger
.
info
(
"Bootstrap OK"
)
return
message
=
"Monitor bootstrap exited with error."
log_file
=
os
.
path
.
join
(
self
.
getPartitionFolder
(),
".%s_%s.log"
%
(
self
.
getConfig
(
'partition-id'
),
PROCESS_NAME
))
self
.
getConfig
(
'process-name'
)
))
if
os
.
path
.
exists
(
log_file
):
with
open
(
log_file
)
as
f
:
message
+=
"
\
n
---- Latest monitor-boostrap.log ----
\
n
"
message
+=
tail
(
f
,
4
)
message
+=
"
\
n
---- Latest monitor-boostrap.log ----
\
n
"
message
+=
tail_file
(
log_file
,
4
)
self
.
logger
.
error
(
message
)
...
...
slapos/promise/plugin/util.py
0 → 100644
View file @
14aad48d
def
tail_file
(
file_path
,
line_count
=
10
):
"""
Returns the last lines of file.
"""
line_list
=
[]
with
open
(
file_path
)
as
f
:
BUFSIZ
=
1024
f
.
seek
(
0
,
2
)
bytes
=
f
.
tell
()
size
=
line_count
+
1
block
=
-
1
while
size
>
0
and
bytes
>
0
:
if
bytes
-
BUFSIZ
>
0
:
# Seek back one whole BUFSIZ
f
.
seek
(
block
*
BUFSIZ
,
2
)
line_list
.
insert
(
0
,
f
.
read
(
BUFSIZ
))
else
:
f
.
seek
(
0
,
0
)
# only read what was not read
line_list
.
insert
(
0
,
f
.
read
(
bytes
))
line_len
=
line_list
[
0
].
count
(
'
\
n
'
)
size
-=
line_len
bytes
-=
BUFSIZ
block
-=
1
return
'
\
n
'
.
join
(
''
.
join
(
line_list
).
splitlines
()[
-
line_count
:])
\ No newline at end of file
slapos/test/promise/plugin/test_monitor_bootstrap_status.py
View file @
14aad48d
...
...
@@ -38,11 +38,12 @@ class TestPromiseMonitorBoostrap(TestPromisePluginMixin):
self
.
promise_name
=
"my-monitor-bootstrap.py"
content
=
"""from slapos.promise.plugin.monitor_bootstrap_status import RunPromise
from slapos.promise.plugin import monitor_bootstrap_status
monitor_bootstrap_status.PROCESS_PID_FILE = "%(pid_file)s"
monitor_bootstrap_status.PROCESS_NAME = "monitor.boostrap"
monitor_bootstrap_status.STATUS_FILE = "%(state_file)s"
extra_config_dict = {
'process-pid-file': "%(pid_file)s",
'process-name': "monitor.boostrap",
'status-file': "%(state_file)s",
}
"""
%
{
'pid_file'
:
self
.
pid_file
,
'state_file'
:
self
.
state_file
}
self
.
writePromise
(
self
.
promise_name
,
content
)
...
...
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