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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
ae02e2d6
Commit
ae02e2d6
authored
Nov 03, 2011
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor: fix on promises
parent
0737bcf0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
46 deletions
+48
-46
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+48
-46
No files found.
slapos/grid/slapgrid.py
View file @
ae02e2d6
...
@@ -282,6 +282,10 @@ class Slapgrid(object):
...
@@ -282,6 +282,10 @@ class Slapgrid(object):
""" Main class for SlapGrid. Fetches and processes informations from master
""" Main class for SlapGrid. Fetches and processes informations from master
server and pushes usage information to master server.
server and pushes usage information to master server.
"""
"""
class
PromiseError
(
Exception
):
pass
def
__init__
(
self
,
def
__init__
(
self
,
software_root
,
software_root
,
instance_root
,
instance_root
,
...
@@ -422,6 +426,49 @@ class Slapgrid(object):
...
@@ -422,6 +426,49 @@ class Slapgrid(object):
launchSupervisord
(
self
.
supervisord_socket
,
launchSupervisord
(
self
.
supervisord_socket
,
self
.
supervisord_configuration_path
)
self
.
supervisord_configuration_path
)
def
_checkPromises
(
self
,
computer_partition
):
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition
.
getId
())
uid
,
gid
=
None
,
None
stat_info
=
os
.
stat
(
instance_path
)
#stat sys call to get statistics informations
uid
=
stat_info
.
st_uid
gid
=
stat_info
.
st_gid
# Get the list of promises
promise_dir
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'promise'
)
if
os
.
path
.
exists
(
promise_dir
)
and
os
.
path
.
isdir
(
promise_dir
):
cwd
=
instance_path
promises_list
=
os
.
listdir
(
promise_dir
)
# Check whether every promise is kept
for
promise
in
promises_list
:
command
=
os
.
path
.
join
(
promise_dir
,
promise
)
kw
=
dict
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
process_handler
=
SlapPopen
(
command
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
cwd
,
env
=
None
,
**
kw
)
time
.
sleep
(
self
.
promise_timeout
)
promise
=
os
.
path
.
basename
(
command
)
if
process_handler
.
poll
()
is
None
:
process_handler
.
kill
()
raise
Slapgrid
.
PromiseError
(
"The promise %r timed out"
%
promise
)
elif
process_handler
.
poll
()
!=
0
:
stderr
=
process_handler
.
communicate
()[
1
]
if
stderr
is
None
:
stderr
=
'No error output from %r.'
%
promise
raise
Slapgrid
.
PromiseError
(
stderr
)
def
processComputerPartitionList
(
self
):
def
processComputerPartitionList
(
self
):
"""Will start supervisord and process each Computer Partition.
"""Will start supervisord and process each Computer Partition.
"""
"""
...
@@ -462,6 +509,7 @@ class Slapgrid(object):
...
@@ -462,6 +509,7 @@ class Slapgrid(object):
local_partition
.
install
()
local_partition
.
install
()
computer_partition
.
available
()
computer_partition
.
available
()
local_partition
.
start
()
local_partition
.
start
()
self
.
_checkPromises
(
computer_partition
)
computer_partition
.
started
()
computer_partition
.
started
()
elif
computer_partition_state
==
"stopped"
:
elif
computer_partition_state
==
"stopped"
:
local_partition
.
install
()
local_partition
.
install
()
...
@@ -504,52 +552,6 @@ class Slapgrid(object):
...
@@ -504,52 +552,6 @@ class Slapgrid(object):
logger
.
error
(
exception
)
logger
.
error
(
exception
)
computer_partition
.
error
(
exception
)
computer_partition
.
error
(
exception
)
# Promises
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition
.
getId
())
uid
,
gid
=
None
,
None
stat_info
=
os
.
stat
(
instance_path
)
#stat sys call to get statistics informations
uid
=
stat_info
.
st_uid
gid
=
stat_info
.
st_gid
# Get the list of promises
promise_dir
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'promise'
)
if
os
.
path
.
exists
(
promise_dir
)
and
os
.
path
.
isdir
(
promise_dir
):
cwd
=
instance_path
promises_list
=
os
.
listdir
(
promise_dir
)
# Check whether every promise is kept
for
promise
in
promises_list
:
command
=
os
.
path
.
join
(
promise_dir
,
promise
)
kw
=
dict
()
if
not
self
.
console
:
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
process_handler
=
SlapPopen
(
command
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
cwd
,
env
=
None
,
**
kw
)
time
.
sleep
(
self
.
promise_timeout
)
promise
=
os
.
path
.
basename
(
command
)
if
process_handler
.
poll
()
is
None
:
process_handler
.
kill
()
computer_partition
.
error
(
"The promise %r timed out"
%
promise
)
elif
process_handler
.
poll
()
!=
0
:
stderr
=
process_handler
.
communicate
()[
1
]
if
stderr
is
None
:
stderr
=
'No error output from %r.'
%
promise
computer_partition
.
error
(
stderr
)
logger
.
info
(
"Finished computer partitions..."
)
logger
.
info
(
"Finished computer partitions..."
)
return
clean_run
return
clean_run
...
...
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