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
Paul Graydon
slapos.core
Commits
20e9ad51
Commit
20e9ad51
authored
Apr 25, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whitespace/indent cleanup
parent
6c003ece
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
87 deletions
+84
-87
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+46
-48
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+29
-31
slapos/grid/utils.py
slapos/grid/utils.py
+9
-8
No files found.
slapos/grid/SlapObject.py
View file @
20e9ad51
...
@@ -41,6 +41,7 @@ import textwrap
...
@@ -41,6 +41,7 @@ import textwrap
import
xmlrpclib
import
xmlrpclib
from
supervisor
import
xmlrpc
from
supervisor
import
xmlrpc
from
slapos.grid.utils
import
(
md5digest
,
getCleanEnvironment
,
bootstrapBuildout
,
from
slapos.grid.utils
import
(
md5digest
,
getCleanEnvironment
,
bootstrapBuildout
,
launchBuildout
,
SlapPopen
,
dropPrivileges
,
updateFile
)
launchBuildout
,
SlapPopen
,
dropPrivileges
,
updateFile
)
from
slapos.slap.slap
import
NotFoundError
from
slapos.slap.slap
import
NotFoundError
...
@@ -57,13 +58,14 @@ class Software(object):
...
@@ -57,13 +58,14 @@ class Software(object):
"""This class is responsible for installing a software release"""
"""This class is responsible for installing a software release"""
def
__init__
(
self
,
url
,
software_root
,
buildout
,
def
__init__
(
self
,
url
,
software_root
,
buildout
,
signature_private_key_file
=
None
,
signature_certificate_list
=
None
,
signature_private_key_file
=
None
,
signature_certificate_list
=
None
,
upload_cache_url
=
None
,
upload_dir_url
=
None
,
shacache_cert_file
=
None
,
upload_cache_url
=
None
,
upload_dir_url
=
None
,
shacache_cert_file
=
None
,
shacache_key_file
=
None
,
shadir_cert_file
=
None
,
shadir_key_file
=
None
,
shacache_key_file
=
None
,
shadir_cert_file
=
None
,
shadir_key_file
=
None
,
download_binary_cache_url
=
None
,
upload_binary_cache_url
=
None
,
download_binary_cache_url
=
None
,
upload_binary_cache_url
=
None
,
download_binary_dir_url
=
None
,
upload_binary_dir_url
=
None
,
download_binary_dir_url
=
None
,
upload_binary_dir_url
=
None
,
download_from_binary_cache_url_blacklist
=
[],
download_from_binary_cache_url_blacklist
=
[],
upload_to_binary_cache_url_blacklist
=
[]):
upload_to_binary_cache_url_blacklist
=
[]):
# XXX mutable defaults
"""Initialisation of class parameters
"""Initialisation of class parameters
"""
"""
self
.
url
=
url
self
.
url
=
url
...
@@ -125,7 +127,7 @@ class Software(object):
...
@@ -125,7 +127,7 @@ class Software(object):
if
self
.
url
.
startswith
(
url
):
if
self
.
url
.
startswith
(
url
):
blacklisted
=
True
blacklisted
=
True
self
.
logger
.
info
(
"Can't upload to binary cache: "
self
.
logger
.
info
(
"Can't upload to binary cache: "
"Software Release URL is blacklisted."
)
"Software Release URL is blacklisted."
)
break
break
if
not
blacklisted
:
if
not
blacklisted
:
self
.
uploadSoftwareRelease
(
tarpath
)
self
.
uploadSoftwareRelease
(
tarpath
)
...
@@ -137,8 +139,7 @@ class Software(object):
...
@@ -137,8 +139,7 @@ class Software(object):
it. If it fails, we notify the server.
it. If it fails, we notify the server.
"""
"""
root_stat_info
=
os
.
stat
(
self
.
software_root
)
root_stat_info
=
os
.
stat
(
self
.
software_root
)
os
.
environ
=
getCleanEnvironment
(
pwd
.
getpwuid
(
root_stat_info
.
st_uid
os
.
environ
=
getCleanEnvironment
(
pwd
.
getpwuid
(
root_stat_info
.
st_uid
).
pw_dir
)
).
pw_dir
)
if
not
os
.
path
.
isdir
(
self
.
software_path
):
if
not
os
.
path
.
isdir
(
self
.
software_path
):
os
.
mkdir
(
self
.
software_path
)
os
.
mkdir
(
self
.
software_path
)
extends_cache
=
tempfile
.
mkdtemp
()
extends_cache
=
tempfile
.
mkdtemp
()
...
@@ -146,31 +147,31 @@ class Software(object):
...
@@ -146,31 +147,31 @@ class Software(object):
# In case when running as root copy ownership, to simplify logic
# In case when running as root copy ownership, to simplify logic
for
path
in
[
self
.
software_path
,
extends_cache
]:
for
path
in
[
self
.
software_path
,
extends_cache
]:
path_stat_info
=
os
.
stat
(
path
)
path_stat_info
=
os
.
stat
(
path
)
if
root_stat_info
.
st_uid
!=
path_stat_info
.
st_uid
or
\
if
(
root_stat_info
.
st_uid
!=
path_stat_info
.
st_uid
or
root_stat_info
.
st_gid
!=
path_stat_info
.
st_gid
:
root_stat_info
.
st_gid
!=
path_stat_info
.
st_gid
)
:
os
.
chown
(
path
,
root_stat_info
.
st_uid
,
os
.
chown
(
path
,
root_stat_info
.
st_uid
,
root_stat_info
.
st_gid
)
root_stat_info
.
st_gid
)
try
:
try
:
buildout_parameter_list
=
[
buildout_parameter_list
=
[
'buildout:extends-cache=%s'
%
extends_cache
,
'buildout:extends-cache=%s'
%
extends_cache
,
'buildout:directory=%s'
%
self
.
software_path
,]
'buildout:directory=%s'
%
self
.
software_path
]
if
self
.
signature_private_key_file
or
\
if
(
self
.
signature_private_key_file
or
self
.
upload_cache_url
or
\
self
.
upload_cache_url
or
self
.
upload_dir_url
is
not
None
:
self
.
upload_dir_url
is
not
None
)
:
buildout_parameter_list
.
append
(
'buildout:networkcache-section=networkcache'
)
buildout_parameter_list
.
append
(
'buildout:networkcache-section=networkcache'
)
for
buildout_option
,
value
in
(
for
buildout_option
,
value
in
[
(
'%ssignature-private-key-file=%s'
,
self
.
signature_private_key_file
),
(
'%ssignature-private-key-file=%s'
,
self
.
signature_private_key_file
),
(
'%supload-cache-url=%s'
,
self
.
upload_cache_url
),
(
'%supload-cache-url=%s'
,
self
.
upload_cache_url
),
(
'%supload-dir-url=%s'
,
self
.
upload_dir_url
),
(
'%supload-dir-url=%s'
,
self
.
upload_dir_url
),
(
'%sshacache-cert-file=%s'
,
self
.
shacache_cert_file
),
(
'%sshacache-cert-file=%s'
,
self
.
shacache_cert_file
),
(
'%sshacache-key-file=%s'
,
self
.
shacache_key_file
),
(
'%sshacache-key-file=%s'
,
self
.
shacache_key_file
),
(
'%sshadir-cert-file=%s'
,
self
.
shadir_cert_file
),
(
'%sshadir-cert-file=%s'
,
self
.
shadir_cert_file
),
(
'%sshadir-key-file=%s'
,
self
.
shadir_key_file
),
(
'%sshadir-key-file=%s'
,
self
.
shadir_key_file
)
)
:
]
:
if
value
:
if
value
:
buildout_parameter_list
.
append
(
\
buildout_parameter_list
.
append
(
buildout_option
%
(
'networkcache:'
,
value
))
buildout_option
%
(
'networkcache:'
,
value
))
buildout_cfg
=
os
.
path
.
join
(
self
.
software_path
,
'buildout.cfg'
)
buildout_cfg
=
os
.
path
.
join
(
self
.
software_path
,
'buildout.cfg'
)
self
.
createProfileIfMissing
(
buildout_cfg
,
self
.
url
)
self
.
createProfileIfMissing
(
buildout_cfg
,
self
.
url
)
...
@@ -285,14 +286,13 @@ class Partition(object):
...
@@ -285,14 +286,13 @@ class Partition(object):
self
.
_updateCertificate
()
self
.
_updateCertificate
()
def
_updateCertificate
(
self
):
def
_updateCertificate
(
self
):
if
not
os
.
path
.
exists
(
self
.
key_file
)
or
\
if
not
os
.
path
.
exists
(
self
.
key_file
)
or
not
os
.
path
.
exists
(
self
.
cert_file
):
not
os
.
path
.
exists
(
self
.
cert_file
):
self
.
logger
.
info
(
'Certificate and key not found, downloading to %r and '
self
.
logger
.
info
(
'Certificate and key not found, downloading to %r and '
'%r'
%
(
self
.
cert_file
,
self
.
key_file
))
'%r'
%
(
self
.
cert_file
,
self
.
key_file
))
try
:
try
:
partition_certificate
=
self
.
computer_partition
.
getCertificate
()
partition_certificate
=
self
.
computer_partition
.
getCertificate
()
except
NotFoundError
:
except
NotFoundError
:
raise
NotFoundError
(
'Partition %s is not known from SlapOS Master.'
%
\
raise
NotFoundError
(
'Partition %s is not known from SlapOS Master.'
%
self
.
partition_id
)
self
.
partition_id
)
open
(
self
.
key_file
,
'w'
).
write
(
partition_certificate
[
'key'
])
open
(
self
.
key_file
,
'w'
).
write
(
partition_certificate
[
'key'
])
open
(
self
.
cert_file
,
'w'
).
write
(
partition_certificate
[
'certificate'
])
open
(
self
.
cert_file
,
'w'
).
write
(
partition_certificate
[
'certificate'
])
...
@@ -308,7 +308,7 @@ class Partition(object):
...
@@ -308,7 +308,7 @@ class Partition(object):
return
(
uid
,
gid
)
return
(
uid
,
gid
)
def
addServiceToGroup
(
self
,
partition_id
,
def
addServiceToGroup
(
self
,
partition_id
,
runner_list
,
path
,
extension
=
''
):
runner_list
,
path
,
extension
=
''
):
uid
,
gid
=
self
.
getUserGroupId
()
uid
,
gid
=
self
.
getUserGroupId
()
program_partition_template
=
pkg_resources
.
resource_stream
(
__name__
,
program_partition_template
=
pkg_resources
.
resource_stream
(
__name__
,
'templates/program_partition_supervisord.conf.in'
).
read
()
'templates/program_partition_supervisord.conf.in'
).
read
()
...
@@ -340,7 +340,7 @@ class Partition(object):
...
@@ -340,7 +340,7 @@ class Partition(object):
""" Creates configuration file from template in software_path, then
""" Creates configuration file from template in software_path, then
installs the software partition with the help of buildout
installs the software partition with the help of buildout
"""
"""
self
.
logger
.
info
(
"Installing Computer Partition %s..."
\
self
.
logger
.
info
(
"Installing Computer Partition %s..."
%
self
.
computer_partition
.
getId
())
%
self
.
computer_partition
.
getId
())
# Checks existence and permissions of Partition directory
# Checks existence and permissions of Partition directory
# Note : Partitions have to be created and configured before running slapgrid
# Note : Partitions have to be created and configured before running slapgrid
...
@@ -359,7 +359,7 @@ class Partition(object):
...
@@ -359,7 +359,7 @@ class Partition(object):
(
self
.
instance_path
,
permission
,
(
self
.
instance_path
,
permission
,
REQUIRED_COMPUTER_PARTITION_PERMISSION
))
REQUIRED_COMPUTER_PARTITION_PERMISSION
))
os
.
environ
=
getCleanEnvironment
(
pwd
.
getpwuid
(
os
.
environ
=
getCleanEnvironment
(
pwd
.
getpwuid
(
instance_stat_info
.
st_uid
).
pw_dir
)
instance_stat_info
.
st_uid
).
pw_dir
)
# Generates buildout part from template
# Generates buildout part from template
template_location
=
os
.
path
.
join
(
self
.
software_path
,
'instance.cfg'
)
template_location
=
os
.
path
.
join
(
self
.
software_path
,
'instance.cfg'
)
# Backward compatibility: "instance.cfg" file was named "template.cfg".
# Backward compatibility: "instance.cfg" file was named "template.cfg".
...
@@ -433,8 +433,7 @@ class Partition(object):
...
@@ -433,8 +433,7 @@ class Partition(object):
if
not
os
.
path
.
exists
(
buildout_binary
):
if
not
os
.
path
.
exists
(
buildout_binary
):
# use own buildout generation
# use own buildout generation
bootstrapBuildout
(
self
.
instance_path
,
self
.
buildout
,
bootstrapBuildout
(
self
.
instance_path
,
self
.
buildout
,
[
'buildout:bin-directory=%s'
%
os
.
path
.
join
(
self
.
instance_path
,
[
'buildout:bin-directory=%s'
%
os
.
path
.
join
(
self
.
instance_path
,
'sbin'
)])
'sbin'
)])
buildout_binary
=
os
.
path
.
join
(
self
.
instance_path
,
'sbin'
,
'buildout'
)
buildout_binary
=
os
.
path
.
join
(
self
.
instance_path
,
'sbin'
,
'buildout'
)
# Launches buildout
# Launches buildout
launchBuildout
(
self
.
instance_path
,
buildout_binary
)
launchBuildout
(
self
.
instance_path
,
buildout_binary
)
...
@@ -465,12 +464,12 @@ class Partition(object):
...
@@ -465,12 +464,12 @@ class Partition(object):
instance_id
=
partition_id
,
instance_id
=
partition_id
,
program_list
=
','
.
join
([
'_'
.
join
([
partition_id
,
runner
])
program_list
=
','
.
join
([
'_'
.
join
([
partition_id
,
runner
])
for
runner
in
runner_list
+
service_list
]))
for
runner
in
runner_list
+
service_list
]))
# Same method to add to service and run
# Same method to add to service and run
self
.
addServiceToGroup
(
partition_id
,
runner_list
,
self
.
run_path
)
self
.
addServiceToGroup
(
partition_id
,
runner_list
,
self
.
run_path
)
self
.
addServiceToGroup
(
partition_id
,
service_list
,
self
.
service_path
,
self
.
addServiceToGroup
(
partition_id
,
service_list
,
self
.
service_path
,
extension
=
getWatchdogID
())
extension
=
getWatchdogID
())
updateFile
(
self
.
supervisord_partition_configuration_path
,
updateFile
(
self
.
supervisord_partition_configuration_path
,
self
.
partition_supervisor_configuration
)
self
.
partition_supervisor_configuration
)
self
.
updateSupervisor
()
self
.
updateSupervisor
()
def
start
(
self
):
def
start
(
self
):
...
@@ -483,7 +482,7 @@ class Partition(object):
...
@@ -483,7 +482,7 @@ class Partition(object):
supervisor
.
startProcessGroup
(
partition_id
,
False
)
supervisor
.
startProcessGroup
(
partition_id
,
False
)
except
xmlrpclib
.
Fault
,
e
:
except
xmlrpclib
.
Fault
,
e
:
if
e
.
faultString
.
startswith
(
'BAD_NAME:'
):
if
e
.
faultString
.
startswith
(
'BAD_NAME:'
):
self
.
logger
.
info
(
"Nothing to start on %s..."
%
\
self
.
logger
.
info
(
"Nothing to start on %s..."
%
self
.
computer_partition
.
getId
())
self
.
computer_partition
.
getId
())
else
:
else
:
self
.
logger
.
info
(
"Requested start of %s..."
%
self
.
computer_partition
.
getId
())
self
.
logger
.
info
(
"Requested start of %s..."
%
self
.
computer_partition
.
getId
())
...
@@ -503,7 +502,7 @@ class Partition(object):
...
@@ -503,7 +502,7 @@ class Partition(object):
def
destroy
(
self
):
def
destroy
(
self
):
"""Destroys the partition and makes it available for subsequent use."
"""Destroys the partition and makes it available for subsequent use."
"""
"""
self
.
logger
.
info
(
"Destroying Computer Partition %s..."
\
self
.
logger
.
info
(
"Destroying Computer Partition %s..."
%
self
.
computer_partition
.
getId
())
%
self
.
computer_partition
.
getId
())
# Launches "destroy" binary if exists
# Launches "destroy" binary if exists
destroy_executable_location
=
os
.
path
.
join
(
self
.
instance_path
,
'sbin'
,
destroy_executable_location
=
os
.
path
.
join
(
self
.
instance_path
,
'sbin'
,
...
@@ -512,11 +511,11 @@ class Partition(object):
...
@@ -512,11 +511,11 @@ class Partition(object):
uid
,
gid
=
self
.
getUserGroupId
()
uid
,
gid
=
self
.
getUserGroupId
()
self
.
logger
.
debug
(
'Invoking %r'
%
destroy_executable_location
)
self
.
logger
.
debug
(
'Invoking %r'
%
destroy_executable_location
)
process_handler
=
SlapPopen
([
destroy_executable_location
],
process_handler
=
SlapPopen
([
destroy_executable_location
],
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
self
.
instance_path
,
cwd
=
self
.
instance_path
,
env
=
getCleanEnvironment
(
pwd
.
getpwuid
(
uid
).
pw_dir
),
env
=
getCleanEnvironment
(
pwd
.
getpwuid
(
uid
).
pw_dir
),
stdout
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
stderr
=
subprocess
.
STDOUT
)
if
process_handler
.
returncode
is
None
or
process_handler
.
returncode
!=
0
:
if
process_handler
.
returncode
is
None
or
process_handler
.
returncode
!=
0
:
message
=
'Failed to destroy Computer Partition in %r.'
%
\
message
=
'Failed to destroy Computer Partition in %r.'
%
\
self
.
instance_path
self
.
instance_path
...
@@ -589,4 +588,3 @@ class Partition(object):
...
@@ -589,4 +588,3 @@ class Partition(object):
supervisor
.
addProcessGroup
(
gname
)
supervisor
.
addProcessGroup
(
gname
)
self
.
logger
.
info
(
'Updated %r'
%
gname
)
self
.
logger
.
info
(
'Updated %r'
%
gname
)
self
.
logger
.
debug
(
'Supervisord updated'
)
self
.
logger
.
debug
(
'Supervisord updated'
)
slapos/grid/slapgrid.py
View file @
20e9ad51
...
@@ -155,14 +155,12 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
...
@@ -155,14 +155,12 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
parser
.
add_argument
(
"--maximal_delay"
,
parser
.
add_argument
(
"--maximal_delay"
,
help
=
"Deprecated. Will only work from configuration file in the future."
)
help
=
"Deprecated. Will only work from configuration file in the future."
)
# Parses arguments
# Parses arguments
if
not
argument_tuple
:
if
not
argument_tuple
:
# No arguments given to entry point : we parse sys.argv.
# No arguments given to entry point : we parse sys.argv.
argument_option_instance
=
parser
.
parse_args
()
argument_option_instance
=
parser
.
parse_args
()
else
:
else
:
argument_option_instance
=
\
argument_option_instance
=
parser
.
parse_args
(
list
(
argument_tuple
))
parser
.
parse_args
(
list
(
argument_tuple
))
# Parses arguments from config file, if needed, then merge previous arguments
# Parses arguments from config file, if needed, then merge previous arguments
option_dict
=
{}
option_dict
=
{}
configuration_file
=
argument_option_instance
.
configuration_file
[
0
]
configuration_file
=
argument_option_instance
.
configuration_file
[
0
]
...
@@ -243,8 +241,7 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
...
@@ -243,8 +241,7 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
certificate_repository_path
=
option_dict
.
get
(
'certificate_repository_path'
)
certificate_repository_path
=
option_dict
.
get
(
'certificate_repository_path'
)
if
certificate_repository_path
is
not
None
:
if
certificate_repository_path
is
not
None
:
if
not
os
.
path
.
isdir
(
certificate_repository_path
):
if
not
os
.
path
.
isdir
(
certificate_repository_path
):
parser
.
error
(
'Directory %r does not exist'
%
parser
.
error
(
'Directory %r does not exist'
%
certificate_repository_path
)
certificate_repository_path
)
# Supervisord configuration location
# Supervisord configuration location
if
not
option_dict
.
get
(
'supervisord_configuration_path'
):
if
not
option_dict
.
get
(
'supervisord_configuration_path'
):
...
@@ -259,9 +256,11 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
...
@@ -259,9 +256,11 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
option_dict
.
get
(
'signature-certificate-list'
,
None
)
option_dict
.
get
(
'signature-certificate-list'
,
None
)
if
signature_certificate_list_string
is
not
None
:
if
signature_certificate_list_string
is
not
None
:
cert_marker
=
"-----BEGIN CERTIFICATE-----"
cert_marker
=
"-----BEGIN CERTIFICATE-----"
signature_certificate_list
=
[
cert_marker
+
'
\
n
'
+
q
.
strip
()
\
signature_certificate_list
=
[
for
q
in
signature_certificate_list_string
.
split
(
cert_marker
)
\
cert_marker
+
'
\
n
'
+
q
.
strip
()
if
q
.
strip
()]
for
q
in
signature_certificate_list_string
.
split
(
cert_marker
)
if
q
.
strip
()
]
else
:
else
:
signature_certificate_list
=
None
signature_certificate_list
=
None
...
@@ -640,13 +639,12 @@ class Slapgrid(object):
...
@@ -640,13 +639,12 @@ class Slapgrid(object):
def
_launchSupervisord
(
self
):
def
_launchSupervisord
(
self
):
launchSupervisord
(
self
.
supervisord_socket
,
launchSupervisord
(
self
.
supervisord_socket
,
self
.
supervisord_configuration_path
,
self
.
supervisord_configuration_path
,
logger
=
self
.
logger
)
logger
=
self
.
logger
)
def
_checkPromises
(
self
,
computer_partition
):
def
_checkPromises
(
self
,
computer_partition
):
self
.
logger
.
info
(
"Checking promises..."
)
self
.
logger
.
info
(
"Checking promises..."
)
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
computer_partition
.
getId
())
computer_partition
.
getId
())
uid
,
gid
=
None
,
None
uid
,
gid
=
None
,
None
stat_info
=
os
.
stat
(
instance_path
)
stat_info
=
os
.
stat
(
instance_path
)
...
@@ -675,9 +673,10 @@ class Slapgrid(object):
...
@@ -675,9 +673,10 @@ class Slapgrid(object):
stdin
=
subprocess
.
PIPE
)
stdin
=
subprocess
.
PIPE
)
process_handler
=
subprocess
.
Popen
(
command
,
process_handler
=
subprocess
.
Popen
(
command
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
cwd
,
cwd
=
cwd
,
env
=
None
if
sys
.
platform
==
'cygwin'
else
{},
**
kw
)
env
=
None
if
sys
.
platform
==
'cygwin'
else
{},
**
kw
)
process_handler
.
stdin
.
flush
()
process_handler
.
stdin
.
flush
()
process_handler
.
stdin
.
close
()
process_handler
.
stdin
.
close
()
process_handler
.
stdin
=
None
process_handler
.
stdin
=
None
...
@@ -739,8 +738,7 @@ class Slapgrid(object):
...
@@ -739,8 +738,7 @@ class Slapgrid(object):
# Try to process it anyway, it may need to be deleted.
# Try to process it anyway, it may need to be deleted.
software_url
=
None
software_url
=
None
try
:
try
:
software_path
=
os
.
path
.
join
(
self
.
software_root
,
software_path
=
os
.
path
.
join
(
self
.
software_root
,
md5digest
(
software_url
))
md5digest
(
software_url
))
except
TypeError
:
except
TypeError
:
# Problem with instance: SR URI not set.
# Problem with instance: SR URI not set.
# Try to process it anyway, it may need to be deleted.
# Try to process it anyway, it may need to be deleted.
...
@@ -1107,14 +1105,14 @@ class Slapgrid(object):
...
@@ -1107,14 +1105,14 @@ class Slapgrid(object):
script_list_to_run
=
os
.
listdir
(
report_path
)
script_list_to_run
=
os
.
listdir
(
report_path
)
else
:
else
:
script_list_to_run
=
[]
script_list_to_run
=
[]
#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
()
name_xml
=
'%s.%s'
%
(
'slapreport'
,
os
.
path
.
basename
(
f
.
name
))
name_xml
=
'%s.%s'
%
(
'slapreport'
,
os
.
path
.
basename
(
f
.
name
))
path_to_slapreport
=
os
.
path
.
join
(
instance_path
,
'var'
,
'xml_report'
,
path_to_slapreport
=
os
.
path
.
join
(
instance_path
,
'var'
,
'xml_report'
,
name_xml
)
name_xml
)
failed_script_list
=
[]
failed_script_list
=
[]
for
script
in
script_list_to_run
:
for
script
in
script_list_to_run
:
invocation_list
=
[]
invocation_list
=
[]
...
@@ -1124,7 +1122,7 @@ class Slapgrid(object):
...
@@ -1124,7 +1122,7 @@ class Slapgrid(object):
#f = tempfile.NamedTemporaryFile()
#f = tempfile.NamedTemporaryFile()
#name_xml = '%s.%s' % ('slapreport', os.path.basename(f.name))
#name_xml = '%s.%s' % ('slapreport', os.path.basename(f.name))
#path_to_slapreport = os.path.join(instance_path, 'var', name_xml)
#path_to_slapreport = os.path.join(instance_path, 'var', name_xml)
invocation_list
.
append
(
path_to_slapreport
)
invocation_list
.
append
(
path_to_slapreport
)
#Dropping privileges
#Dropping privileges
uid
,
gid
=
None
,
None
uid
,
gid
=
None
,
None
...
@@ -1134,9 +1132,10 @@ class Slapgrid(object):
...
@@ -1134,9 +1132,10 @@ class Slapgrid(object):
gid
=
stat_info
.
st_gid
gid
=
stat_info
.
st_gid
kw
=
dict
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
kw
=
dict
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
process_handler
=
SlapPopen
(
invocation_list
,
process_handler
=
SlapPopen
(
invocation_list
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
),
cwd
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
),
env
=
None
,
**
kw
)
env
=
None
,
**
kw
)
if
process_handler
.
returncode
is
None
:
if
process_handler
.
returncode
is
None
:
process_handler
.
kill
()
process_handler
.
kill
()
if
process_handler
.
returncode
!=
0
:
if
process_handler
.
returncode
!=
0
:
...
@@ -1169,15 +1168,15 @@ class Slapgrid(object):
...
@@ -1169,15 +1168,15 @@ class Slapgrid(object):
filename_list
=
[]
filename_list
=
[]
#logger.debug('name List %s' % filename_list)
#logger.debug('name List %s' % filename_list)
usage
=
''
usage
=
''
for
filename
in
filename_list
:
for
filename
in
filename_list
:
file_path
=
os
.
path
.
join
(
dir_reports
,
filename
)
file_path
=
os
.
path
.
join
(
dir_reports
,
filename
)
if
os
.
path
.
exists
(
file_path
):
if
os
.
path
.
exists
(
file_path
):
usage_file
=
open
(
file_path
,
'r'
)
usage_file
=
open
(
file_path
,
'r'
)
usage
=
usage_file
.
read
()
usage
=
usage_file
.
read
()
usage_file
.
close
()
usage_file
.
close
()
#We check the validity of xml content of each reports
#We check the validity of xml content of each reports
if
not
self
.
validateXML
(
usage
,
partition_consumption_model
):
if
not
self
.
validateXML
(
usage
,
partition_consumption_model
):
logger
.
info
(
'WARNING: The XML file %s generated by slapreport is '
logger
.
info
(
'WARNING: The XML file %s generated by slapreport is '
...
@@ -1207,7 +1206,7 @@ class Slapgrid(object):
...
@@ -1207,7 +1206,7 @@ class Slapgrid(object):
logger
.
info
(
issue
)
logger
.
info
(
issue
)
for
computer_partition_usage
in
computer_partition_usage_list
:
for
computer_partition_usage
in
computer_partition_usage_list
:
logger
.
info
(
'computer_partition_usage_list
: %s - %s'
%
\
logger
.
info
(
'computer_partition_usage_list: %s - %s'
%
\
(
computer_partition_usage
.
usage
,
computer_partition_usage
.
getId
()))
(
computer_partition_usage
.
usage
,
computer_partition_usage
.
getId
()))
#If there is, at least, one report
#If there is, at least, one report
...
@@ -1216,7 +1215,7 @@ class Slapgrid(object):
...
@@ -1216,7 +1215,7 @@ class Slapgrid(object):
#We generate the final XML report with asXML method
#We generate the final XML report with asXML method
computer_consumption
=
self
.
asXML
(
computer_partition_usage_list
)
computer_consumption
=
self
.
asXML
(
computer_partition_usage_list
)
logger
.
info
(
'Final xml report
: %s'
%
computer_consumption
)
logger
.
info
(
'Final xml report: %s'
%
computer_consumption
)
#We test the XML report before sending it
#We test the XML report before sending it
if
self
.
validateXML
(
computer_consumption
,
computer_consumption_model
):
if
self
.
validateXML
(
computer_consumption
,
computer_consumption_model
):
...
@@ -1240,8 +1239,7 @@ class Slapgrid(object):
...
@@ -1240,8 +1239,7 @@ class Slapgrid(object):
computer_partition_id
=
computer_partition
.
getId
()
computer_partition_id
=
computer_partition
.
getId
()
try
:
try
:
software_url
=
computer_partition
.
getSoftwareRelease
().
getURI
()
software_url
=
computer_partition
.
getSoftwareRelease
().
getURI
()
software_path
=
os
.
path
.
join
(
self
.
software_root
,
software_path
=
os
.
path
.
join
(
self
.
software_root
,
md5digest
(
software_url
))
md5digest
(
software_url
))
except
(
NotFoundError
,
TypeError
):
except
(
NotFoundError
,
TypeError
):
software_url
=
None
software_url
=
None
software_path
=
None
software_path
=
None
...
@@ -1292,7 +1290,7 @@ class Slapgrid(object):
...
@@ -1292,7 +1290,7 @@ class Slapgrid(object):
computer_partition
.
getId
())
computer_partition
.
getId
())
except
ServerError
as
server_error
:
except
ServerError
as
server_error
:
logger
.
debug
(
'Ignored server error while trying to inform about '
logger
.
debug
(
'Ignored server error while trying to inform about '
'destroying Computer Partition %r. Error is
:
\
n
%r'
%
'destroying Computer Partition %r. Error is:
\
n
%r'
%
(
computer_partition
.
getId
(),
server_error
.
args
[
0
]))
(
computer_partition
.
getId
(),
server_error
.
args
[
0
]))
logger
.
info
(
"Finished usage reports."
)
logger
.
info
(
"Finished usage reports."
)
...
...
slapos/grid/utils.py
View file @
20e9ad51
...
@@ -209,12 +209,12 @@ def dropPrivileges(uid, gid):
...
@@ -209,12 +209,12 @@ def dropPrivileges(uid, gid):
uid
,
gid
,
group_list
)
uid
,
gid
,
group_list
)
new_uid
,
new_gid
,
new_group_list
=
os
.
getuid
(),
os
.
getgid
(),
os
.
getgroups
()
new_uid
,
new_gid
,
new_group_list
=
os
.
getuid
(),
os
.
getgid
(),
os
.
getgroups
()
if
not
(
new_uid
==
uid
and
new_gid
==
gid
and
set
(
new_group_list
)
==
group_list
):
if
not
(
new_uid
==
uid
and
new_gid
==
gid
and
set
(
new_group_list
)
==
group_list
):
raise
OSError
(
'%s new_uid = %r and new_gid = %r and '
\
raise
OSError
(
'%s new_uid = %r and new_gid = %r and '
'new_group_list = %r which is fatal.'
'new_group_list = %r which is fatal.'
%
(
message_pre
,
%
(
message_pre
,
new_uid
,
new_uid
,
new_gid
,
new_gid
,
new_group_list
))
new_group_list
))
# assert that it is not possible to go back to running one
# assert that it is not possible to go back to running one
try
:
try
:
...
@@ -276,8 +276,9 @@ def bootstrapBuildout(path, buildout=None,
...
@@ -276,8 +276,9 @@ def bootstrapBuildout(path, buildout=None,
path
))
path
))
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
process_handler
=
SlapPopen
(
invocation_list
,
process_handler
=
SlapPopen
(
invocation_list
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
path
,
**
kw
)
cwd
=
path
,
**
kw
)
if
process_handler
.
returncode
is
None
or
process_handler
.
returncode
!=
0
:
if
process_handler
.
returncode
is
None
or
process_handler
.
returncode
!=
0
:
message
=
'Failed to run buildout profile in directory %r'
%
(
path
)
message
=
'Failed to run buildout profile in directory %r'
%
(
path
)
logger
.
error
(
message
)
logger
.
error
(
message
)
...
...
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