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
0
Merge Requests
0
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
Rafael Monnerat
slapos.core
Commits
65622b9a
Commit
65622b9a
authored
Jun 14, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make pep8 happy
parent
c1058afd
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
89 deletions
+78
-89
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+27
-32
slapos/grid/distribution.py
slapos/grid/distribution.py
+0
-1
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+49
-53
slapos/grid/utils.py
slapos/grid/utils.py
+2
-3
No files found.
slapos/grid/SlapObject.py
View file @
65622b9a
...
@@ -306,10 +306,7 @@ class Partition(object):
...
@@ -306,10 +306,7 @@ class Partition(object):
uid
,
gid
=
self
.
getUserGroupId
()
uid
,
gid
=
self
.
getUserGroupId
()
for
name
,
path
in
[
for
name
,
path
in
[(
'certificate'
,
self
.
cert_file
),
(
'key'
,
self
.
key_file
)]:
(
'certificate'
,
self
.
cert_file
),
(
'key'
,
self
.
key_file
),
]:
new_content
=
partition_certificate
[
name
]
new_content
=
partition_certificate
[
name
]
old_content
=
None
old_content
=
None
if
os
.
path
.
exists
(
path
):
if
os
.
path
.
exists
(
path
):
...
@@ -325,7 +322,6 @@ class Partition(object):
...
@@ -325,7 +322,6 @@ class Partition(object):
fout
.
write
(
new_content
)
fout
.
write
(
new_content
)
os
.
chown
(
path
,
uid
,
gid
)
os
.
chown
(
path
,
uid
,
gid
)
def
getUserGroupId
(
self
):
def
getUserGroupId
(
self
):
"""Returns tuple of (uid, gid) of partition"""
"""Returns tuple of (uid, gid) of partition"""
stat_info
=
os
.
stat
(
self
.
instance_path
)
stat_info
=
os
.
stat
(
self
.
instance_path
)
...
@@ -482,7 +478,6 @@ class Partition(object):
...
@@ -482,7 +478,6 @@ class Partition(object):
logger
=
self
.
logger
)
logger
=
self
.
logger
)
self
.
generateSupervisorConfigurationFile
()
self
.
generateSupervisorConfigurationFile
()
def
generateSupervisorConfigurationFile
(
self
):
def
generateSupervisorConfigurationFile
(
self
):
"""
"""
Generates supervisord configuration file from template.
Generates supervisord configuration file from template.
...
...
slapos/grid/distribution.py
View file @
65622b9a
...
@@ -62,4 +62,3 @@ def patched_linux_distribution(distname='', version='', id='',
...
@@ -62,4 +62,3 @@ def patched_linux_distribution(distname='', version='', id='',
pass
pass
return
platform
.
linux_distribution
(
distname
,
version
,
id
,
supported_dists
,
full_distribution_name
)
return
platform
.
linux_distribution
(
distname
,
version
,
id
,
supported_dists
,
full_distribution_name
)
slapos/grid/slapgrid.py
View file @
65622b9a
...
@@ -149,8 +149,8 @@ def merged_options(args, configp):
...
@@ -149,8 +149,8 @@ def merged_options(args, configp):
# Parse cache / binary cache options
# Parse cache / binary cache options
# Backward compatibility about "binary-cache-url-blacklist" deprecated option
# Backward compatibility about "binary-cache-url-blacklist" deprecated option
if
options
.
get
(
"binary-cache-url-blacklist"
)
and
not
\
if
(
options
.
get
(
"binary-cache-url-blacklist"
)
and
not
options
.
get
(
"download-from-binary-cache-url-blacklist"
):
options
.
get
(
"download-from-binary-cache-url-blacklist"
)
):
options
[
"download-from-binary-cache-url-blacklist"
]
=
\
options
[
"download-from-binary-cache-url-blacklist"
]
=
\
options
[
"binary-cache-url-blacklist"
]
options
[
"binary-cache-url-blacklist"
]
options
[
"download-from-binary-cache-url-blacklist"
]
=
[
options
[
"download-from-binary-cache-url-blacklist"
]
=
[
...
@@ -175,8 +175,8 @@ def random_delay(options, logger):
...
@@ -175,8 +175,8 @@ def random_delay(options, logger):
maximal_delay
=
int
(
options
.
get
(
'maximal_delay'
,
'0'
))
maximal_delay
=
int
(
options
.
get
(
'maximal_delay'
,
'0'
))
if
maximal_delay
:
if
maximal_delay
:
duration
=
random
.
randint
(
1
,
maximal_delay
)
duration
=
random
.
randint
(
1
,
maximal_delay
)
logger
.
info
(
'Sleeping for %s seconds. To disable this feature, '
\
logger
.
info
(
'Sleeping for %s seconds. To disable this feature, '
'check --now parameter in slapgrid help.'
%
duration
)
'check --now parameter in slapgrid help.'
,
duration
)
time
.
sleep
(
duration
)
time
.
sleep
(
duration
)
...
@@ -199,17 +199,17 @@ def create_slapgrid_object(options, logger):
...
@@ -199,17 +199,17 @@ def create_slapgrid_object(options, logger):
supervisord_configuration_path
=
op
[
'supervisord_configuration_path'
],
supervisord_configuration_path
=
op
[
'supervisord_configuration_path'
],
buildout
=
op
.
get
(
'buildout'
),
buildout
=
op
.
get
(
'buildout'
),
logger
=
logger
,
logger
=
logger
,
force_periodicity
=
op
.
get
(
'force_periodicity'
,
False
),
force_periodicity
=
op
.
get
(
'force_periodicity'
,
False
),
maximum_periodicity
=
op
.
get
(
'maximum_periodicity'
,
86400
),
maximum_periodicity
=
op
.
get
(
'maximum_periodicity'
,
86400
),
key_file
=
op
.
get
(
'key_file'
),
key_file
=
op
.
get
(
'key_file'
),
cert_file
=
op
.
get
(
'cert_file'
),
cert_file
=
op
.
get
(
'cert_file'
),
signature_private_key_file
=
op
.
get
(
'signature_private_key_file'
),
signature_private_key_file
=
op
.
get
(
'signature_private_key_file'
),
signature_certificate_list
=
signature_certificate_list
,
signature_certificate_list
=
signature_certificate_list
,
download_binary_cache_url
=
op
.
get
(
'download-binary-cache-url'
),
download_binary_cache_url
=
op
.
get
(
'download-binary-cache-url'
),
upload_binary_cache_url
=
op
.
get
(
'upload-binary-cache-url'
),
upload_binary_cache_url
=
op
.
get
(
'upload-binary-cache-url'
),
download_from_binary_cache_url_blacklist
=
\
download_from_binary_cache_url_blacklist
=
op
.
get
(
'download-from-binary-cache-url-blacklist'
,
[]),
op
.
get
(
'download-from-binary-cache-url-blacklist'
,
[]),
upload_to_binary_cache_url_blacklist
=
\
upload_to_binary_cache_url_blacklist
=
op
.
get
(
'upload-to-binary-cache-url-blacklist'
,
[]),
op
.
get
(
'upload-to-binary-cache-url-blacklist'
,
[]),
upload_cache_url
=
op
.
get
(
'upload-cache-url'
),
upload_cache_url
=
op
.
get
(
'upload-cache-url'
),
download_binary_dir_url
=
op
.
get
(
'download-binary-dir-url'
),
download_binary_dir_url
=
op
.
get
(
'download-binary-dir-url'
),
...
@@ -232,7 +232,7 @@ def create_slapgrid_object(options, logger):
...
@@ -232,7 +232,7 @@ def create_slapgrid_object(options, logger):
def
check_required_only_partitions
(
existing
,
required
):
def
check_required_only_partitions
(
existing
,
required
):
missing
=
set
(
required
)
-
set
(
existing
)
missing
=
set
(
required
)
-
set
(
existing
)
if
missing
:
if
missing
:
plural
=
[
's'
,
''
][
len
(
missing
)
==
1
]
plural
=
[
's'
,
''
][
len
(
missing
)
==
1
]
raise
ValueError
(
'Unknown partition%s: %s'
%
(
plural
,
', '
.
join
(
sorted
(
missing
))))
raise
ValueError
(
'Unknown partition%s: %s'
%
(
plural
,
', '
.
join
(
sorted
(
missing
))))
...
@@ -334,8 +334,8 @@ class Slapgrid(object):
...
@@ -334,8 +334,8 @@ class Slapgrid(object):
invocation_list
=
[
WATCHDOG_PATH
]
invocation_list
=
[
WATCHDOG_PATH
]
invocation_list
.
append
(
"--master-url '%s' "
%
self
.
master_url
)
invocation_list
.
append
(
"--master-url '%s' "
%
self
.
master_url
)
if
self
.
certificate_repository_path
:
if
self
.
certificate_repository_path
:
invocation_list
.
append
(
"--certificate-repository-path '%s'"
\
invocation_list
.
append
(
"--certificate-repository-path '%s'"
%
%
self
.
certificate_repository_path
)
self
.
certificate_repository_path
)
invocation_list
.
append
(
"--computer-id '%s'"
%
self
.
computer_id
)
invocation_list
.
append
(
"--computer-id '%s'"
%
self
.
computer_id
)
return
' '
.
join
(
invocation_list
)
return
' '
.
join
(
invocation_list
)
...
@@ -371,7 +371,8 @@ class Slapgrid(object):
...
@@ -371,7 +371,8 @@ class Slapgrid(object):
'supervisord_pidfile'
:
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'run'
,
'supervisord.pid'
)),
'supervisord_pidfile'
:
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'run'
,
'supervisord.pid'
)),
'supervisord_logfile_backups'
:
'10'
,
'supervisord_logfile_backups'
:
'10'
,
'watchdog_command'
:
self
.
getWatchdogLine
(),
'watchdog_command'
:
self
.
getWatchdogLine
(),
})
}
)
def
getComputerPartitionList
(
self
):
def
getComputerPartitionList
(
self
):
try
:
try
:
...
@@ -401,9 +402,9 @@ class Slapgrid(object):
...
@@ -401,9 +402,9 @@ class Slapgrid(object):
signature_certificate_list
=
self
.
signature_certificate_list
,
signature_certificate_list
=
self
.
signature_certificate_list
,
download_binary_cache_url
=
self
.
download_binary_cache_url
,
download_binary_cache_url
=
self
.
download_binary_cache_url
,
upload_binary_cache_url
=
self
.
upload_binary_cache_url
,
upload_binary_cache_url
=
self
.
upload_binary_cache_url
,
download_from_binary_cache_url_blacklist
=
\
download_from_binary_cache_url_blacklist
=
self
.
download_from_binary_cache_url_blacklist
,
self
.
download_from_binary_cache_url_blacklist
,
upload_to_binary_cache_url_blacklist
=
\
upload_to_binary_cache_url_blacklist
=
self
.
upload_to_binary_cache_url_blacklist
,
self
.
upload_to_binary_cache_url_blacklist
,
upload_cache_url
=
self
.
upload_cache_url
,
upload_cache_url
=
self
.
upload_cache_url
,
download_binary_dir_url
=
self
.
download_binary_dir_url
,
download_binary_dir_url
=
self
.
download_binary_dir_url
,
...
@@ -415,10 +416,10 @@ class Slapgrid(object):
...
@@ -415,10 +416,10 @@ class Slapgrid(object):
shadir_key_file
=
self
.
shadir_key_file
)
shadir_key_file
=
self
.
shadir_key_file
)
if
state
==
'available'
:
if
state
==
'available'
:
completed_tag
=
os
.
path
.
join
(
software_path
,
'.completed'
)
completed_tag
=
os
.
path
.
join
(
software_path
,
'.completed'
)
if
self
.
develop
or
(
not
os
.
path
.
exists
(
completed_tag
)
and
\
if
(
self
.
develop
or
(
not
os
.
path
.
exists
(
completed_tag
)
and
len
(
self
.
software_release_filter_list
)
==
0
)
or
\
len
(
self
.
software_release_filter_list
)
==
0
)
or
url_hash
in
self
.
software_release_filter_list
or
\
url_hash
in
self
.
software_release_filter_list
or
url_hash
in
(
md5digest
(
uri
)
for
uri
in
self
.
software_release_filter_list
):
url_hash
in
(
md5digest
(
uri
)
for
uri
in
self
.
software_release_filter_list
)
)
:
try
:
try
:
software_release
.
building
()
software_release
.
building
()
except
NotFoundError
:
except
NotFoundError
:
...
@@ -471,7 +472,6 @@ class Slapgrid(object):
...
@@ -471,7 +472,6 @@ class Slapgrid(object):
return
SLAPGRID_FAIL
return
SLAPGRID_FAIL
return
SLAPGRID_SUCCESS
return
SLAPGRID_SUCCESS
def
_launchSupervisord
(
self
):
def
_launchSupervisord
(
self
):
launchSupervisord
(
self
.
supervisord_socket
,
launchSupervisord
(
self
.
supervisord_socket
,
self
.
supervisord_configuration_path
,
self
.
supervisord_configuration_path
,
...
@@ -592,8 +592,8 @@ class Slapgrid(object):
...
@@ -592,8 +592,8 @@ class Slapgrid(object):
# Check if timestamp from server is more recent than local one.
# Check if timestamp from server is more recent than local one.
# If not: it's not worth processing this partition (nothing has
# If not: it's not worth processing this partition (nothing has
# changed).
# changed).
if
computer_partition_id
not
in
self
.
computer_partition_filter_list
and
\
if
(
computer_partition_id
not
in
self
.
computer_partition_filter_list
and
(
not
self
.
develop
)
and
os
.
path
.
exists
(
timestamp_path
):
not
self
.
develop
and
os
.
path
.
exists
(
timestamp_path
)
):
old_timestamp
=
open
(
timestamp_path
).
read
()
old_timestamp
=
open
(
timestamp_path
).
read
()
last_runtime
=
int
(
os
.
path
.
getmtime
(
timestamp_path
))
last_runtime
=
int
(
os
.
path
.
getmtime
(
timestamp_path
))
if
timestamp
:
if
timestamp
:
...
@@ -808,7 +808,6 @@ class Slapgrid(object):
...
@@ -808,7 +808,6 @@ class Slapgrid(object):
return
SLAPGRID_PROMISE_FAIL
return
SLAPGRID_PROMISE_FAIL
return
SLAPGRID_SUCCESS
return
SLAPGRID_SUCCESS
def
validateXML
(
self
,
to_be_validated
,
xsd_model
):
def
validateXML
(
self
,
to_be_validated
,
xsd_model
):
"""Validates a given xml file"""
"""Validates a given xml file"""
#We retrieve the xsd model
#We retrieve the xsd model
...
@@ -819,7 +818,7 @@ class Slapgrid(object):
...
@@ -819,7 +818,7 @@ class Slapgrid(object):
try
:
try
:
document
=
etree
.
fromstring
(
to_be_validated
)
document
=
etree
.
fromstring
(
to_be_validated
)
except
(
etree
.
XMLSyntaxError
,
etree
.
DocumentInvalid
)
as
exc
:
except
(
etree
.
XMLSyntaxError
,
etree
.
DocumentInvalid
)
as
exc
:
self
.
logger
.
info
(
'Failed to parse this XML report : %s
\
n
%s'
%
\
self
.
logger
.
info
(
'Failed to parse this XML report : %s
\
n
%s'
%
(
to_be_validated
,
_formatXMLError
(
exc
)))
(
to_be_validated
,
_formatXMLError
(
exc
)))
self
.
logger
.
error
(
_formatXMLError
(
exc
))
self
.
logger
.
error
(
_formatXMLError
(
exc
))
return
False
return
False
...
@@ -967,9 +966,8 @@ class Slapgrid(object):
...
@@ -967,9 +966,8 @@ class Slapgrid(object):
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_list
),
logger
=
self
.
logger
)
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_list
),
logger
=
self
.
logger
)
# Whatever happens, don't stop processing other instances
# Whatever happens, don't stop processing other instances
except
Exception
:
except
Exception
:
self
.
logger
.
info
(
'Cannot run usage script(s) for %r: %s'
%
(
self
.
logger
.
info
(
'Cannot run usage script(s) for %r: %s'
%
computer_partition
.
getId
(),
(
computer_partition
.
getId
(),
traceback
.
format_exc
()))
traceback
.
format_exc
()))
#Now we loop through the different computer partitions to report
#Now we loop through the different computer partitions to report
report_usage_issue_cp_list
=
[]
report_usage_issue_cp_list
=
[]
...
@@ -1015,14 +1013,12 @@ class Slapgrid(object):
...
@@ -1015,14 +1013,12 @@ class Slapgrid(object):
# Whatever happens, don't stop processing other instances
# Whatever happens, don't stop processing other instances
except
Exception
:
except
Exception
:
self
.
logger
.
info
(
'Cannot run usage script(s) for %r: %s'
%
(
self
.
logger
.
info
(
'Cannot run usage script(s) for %r: %s'
%
computer_partition
.
getId
(),
(
computer_partition
.
getId
(),
traceback
.
format_exc
()))
traceback
.
format_exc
()))
for
computer_partition_usage
in
computer_partition_usage_list
:
for
computer_partition_usage
in
computer_partition_usage_list
:
self
.
logger
.
info
(
'computer_partition_usage_list: %s - %s'
%
(
self
.
logger
.
info
(
'computer_partition_usage_list: %s - %s'
%
computer_partition_usage
.
usage
,
(
computer_partition_usage
.
usage
,
computer_partition_usage
.
getId
()))
computer_partition_usage
.
getId
()))
#If there is, at least, one report
#If there is, at least, one report
if
computer_partition_usage_list
!=
[]:
if
computer_partition_usage_list
!=
[]:
...
...
slapos/grid/utils.py
View file @
65622b9a
...
@@ -197,8 +197,7 @@ def dropPrivileges(uid, gid, logger):
...
@@ -197,8 +197,7 @@ def dropPrivileges(uid, gid, logger):
# assert that privileges are dropped
# assert that privileges are dropped
message_pre
=
'After dropping to uid = %r and gid = %r '
\
message_pre
=
'After dropping to uid = %r and gid = %r '
\
'and group_list = %s'
%
(
'and group_list = %s'
%
(
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 '
...
...
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