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
Arnaud Véron
slapos.core
Commits
8e0369a2
Commit
8e0369a2
authored
Jul 27, 2011
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code factorization of report running and promise checking
parent
65494a3a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
44 deletions
+44
-44
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+44
-44
No files found.
slapos/grid/slapgrid.py
View file @
8e0369a2
...
@@ -472,6 +472,23 @@ class Slapgrid(object):
...
@@ -472,6 +472,23 @@ class Slapgrid(object):
return
False
return
False
def
_runCommandsAsUserAndYieldPopen
(
self
,
commands_list
,
user
,
cwd
):
uid
,
gid
=
user
for
command
in
commands_list
:
kw
=
dict
()
if
not
self
.
console
:
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
process_handler
=
SlapPopen
(
command
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
cwd
,
env
=
None
,
**
kw
)
yield
(
process_handler
,
command
)
def
agregateAndSendUsage
(
self
):
def
agregateAndSendUsage
(
self
):
"""Will agregate usage from each Computer Partition.
"""Will agregate usage from each Computer Partition.
"""
"""
...
@@ -494,6 +511,13 @@ class Slapgrid(object):
...
@@ -494,6 +511,13 @@ class Slapgrid(object):
else
:
else
:
script_list_to_run
=
[]
script_list_to_run
=
[]
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
#We now generate the pseudorandom name for the xml file
#We now generate the pseudorandom name for the xml file
# and we add it in the invocation_list
# and we add it in the invocation_list
f
=
tempfile
.
NamedTemporaryFile
()
f
=
tempfile
.
NamedTemporaryFile
()
...
@@ -502,30 +526,18 @@ class Slapgrid(object):
...
@@ -502,30 +526,18 @@ class Slapgrid(object):
name_xml
)
name_xml
)
failed_script_list
=
[]
failed_script_list
=
[]
for
script
in
script_list_to_run
:
commands_to_run
=
[
(
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
,
script
),
invocation_list
=
[]
path_to_slapreport
,
invocation_list
.
append
(
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
,
)
script
))
for
script
in
script_list_to_run
]
#We add the xml_file name in the invocation_list
#f = tempfile.NamedTemporaryFile()
cwd
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
)
#name_xml = '%s.%s' % ('slapreport', os.path.basename(f.name))
#path_to_slapreport = os.path.join(instance_path, 'var', name_xml)
for
process_handler
,
command
in
self
.
_runCommandAsUserAndYieldPopen
(
commands_to_run
,
(
uid
,
gid
),
invocation_list
.
append
(
path_to_slapreport
)
cwd
):
#Dropping privileges
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
kw
=
dict
()
if
not
self
.
console
:
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
process_handler
=
SlapPopen
(
invocation_list
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
),
env
=
None
,
**
kw
)
result
=
process_handler
.
communicate
()[
0
]
result
=
process_handler
.
communicate
()[
0
]
if
self
.
console
:
if
self
.
console
:
result
=
'Please consult messages above'
result
=
'Please consult messages above'
...
@@ -535,39 +547,27 @@ class Slapgrid(object):
...
@@ -535,39 +547,27 @@ class Slapgrid(object):
clean_run
=
False
clean_run
=
False
failed_script_list
.
append
(
"Script %r failed with %s."
%
(
script
,
result
))
failed_script_list
.
append
(
"Script %r failed with %s."
%
(
script
,
result
))
logger
.
warning
(
"Failed to run %r, the result was.
\
n
%s"
%
logger
.
warning
(
"Failed to run %r, the result was.
\
n
%s"
%
(
invocation_list
,
result
))
(
command
,
result
))
if
len
(
failed_script_list
):
if
len
(
failed_script_list
):
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_list
))
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_list
))
#
#
# Checking if the promises are kept
# Checking if the promises are kept
#
#
# XXX-Antoine: I thought about factorizing this code with
# the above one. But it seemed like a lot to get through.
# Get the list of promises
# Get the list of promises
promise_dir
=
os
.
join
(
instance_path
,
'etc'
,
'promise'
)
promise_dir
=
os
.
join
(
instance_path
,
'etc'
,
'promise'
)
promises_list
=
os
.
listdir
(
promise_dir
)
commands_to_run
=
os
.
listdir
(
promise_dir
)
cwd
=
instance_path
# Check whether every promise is kept
# Check whether every promise is kept
for
promise
in
promises_list
:
for
process_handler
,
command
in
self
.
_runCommandAsUserAndYieldPopen
(
commands_to_run
,
command_line
=
[
promise
]
(
uid
,
gid
),
cwd
):
uid
,
gid
=
None
,
None
stat_info
=
os
.
stat
(
instance_path
)
uid
,
gid
=
stat_info
.
st_uid
,
stat_info
.
st_gid
kw
=
dict
()
if
not
self
.
console
:
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
process_handler
=
SlapPopen
(
command_line
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
instance_path
,
env
=
None
,
**
kw
)
time
.
sleep
(
3
)
# 3 seconds timeout
time
.
sleep
(
3
)
# 3 seconds timeout
promise
=
os
.
path
.
basename
(
command
)
if
process_handler
.
poll
()
is
None
:
if
process_handler
.
poll
()
is
None
:
process_handler
.
kill
()
process_handler
.
kill
()
computer_partition
.
error
(
"The promise '%s' timed out"
%
promise
)
computer_partition
.
error
(
"The promise '%s' timed out"
%
promise
)
...
...
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