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
18
Merge Requests
18
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
nexedi
slapos.core
Commits
d34a193e
Commit
d34a193e
authored
Apr 25, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exception handling cleanup: 'as' syntax, removed useless catch
parent
fec3622f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
32 deletions
+28
-32
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+3
-3
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+25
-29
No files found.
slapos/grid/SlapObject.py
View file @
d34a193e
...
@@ -368,7 +368,7 @@ class Partition(object):
...
@@ -368,7 +368,7 @@ class Partition(object):
self
.
logger
.
debug
(
"Copying %r to %r"
%
(
template_location
,
config_location
))
self
.
logger
.
debug
(
"Copying %r to %r"
%
(
template_location
,
config_location
))
try
:
try
:
shutil
.
copy
(
template_location
,
config_location
)
shutil
.
copy
(
template_location
,
config_location
)
except
IOError
,
e
:
except
IOError
as
e
:
# Template not found on SR, we notify user.
# Template not found on SR, we notify user.
raise
IOError
(
'Software Release %s is not correctly installed.
\
n
'
raise
IOError
(
'Software Release %s is not correctly installed.
\
n
'
'%s'
%
(
self
.
software_release_url
,
e
))
'%s'
%
(
self
.
software_release_url
,
e
))
...
@@ -480,7 +480,7 @@ class Partition(object):
...
@@ -480,7 +480,7 @@ class Partition(object):
partition_id
=
self
.
computer_partition
.
getId
()
partition_id
=
self
.
computer_partition
.
getId
()
try
:
try
:
supervisor
.
startProcessGroup
(
partition_id
,
False
)
supervisor
.
startProcessGroup
(
partition_id
,
False
)
except
xmlrpclib
.
Fault
,
e
:
except
xmlrpclib
.
Fault
as
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
())
...
@@ -493,7 +493,7 @@ class Partition(object):
...
@@ -493,7 +493,7 @@ class Partition(object):
try
:
try
:
supervisor
=
self
.
getSupervisorRPC
()
supervisor
=
self
.
getSupervisorRPC
()
supervisor
.
stopProcessGroup
(
partition_id
,
False
)
supervisor
.
stopProcessGroup
(
partition_id
,
False
)
except
xmlrpclib
.
Fault
,
e
:
except
xmlrpclib
.
Fault
as
e
:
if
e
.
faultString
.
startswith
(
'BAD_NAME:'
):
if
e
.
faultString
.
startswith
(
'BAD_NAME:'
):
self
.
logger
.
info
(
'Partition %s not known in supervisord, ignoring'
%
partition_id
)
self
.
logger
.
info
(
'Partition %s not known in supervisord, ignoring'
%
partition_id
)
else
:
else
:
...
...
slapos/grid/slapgrid.py
View file @
d34a193e
...
@@ -51,8 +51,7 @@ from lxml import etree
...
@@ -51,8 +51,7 @@ from lxml import etree
from
slapos.slap.slap
import
NotFoundError
from
slapos.slap.slap
import
NotFoundError
from
slapos.slap.slap
import
ServerError
from
slapos.slap.slap
import
ServerError
from
slapos.grid.exception
import
BuildoutFailedError
from
slapos.grid.exception
import
BuildoutFailedError
from
slapos.grid.SlapObject
import
Software
,
Partition
,
WrongPermissionError
,
\
from
slapos.grid.SlapObject
import
Software
,
Partition
PathDoesNotExistError
from
slapos.grid.svcbackend
import
launchSupervisord
from
slapos.grid.svcbackend
import
launchSupervisord
from
slapos.grid.utils
import
(
md5digest
,
createPrivateDirectory
,
dropPrivileges
,
from
slapos.grid.utils
import
(
md5digest
,
createPrivateDirectory
,
dropPrivileges
,
setRunning
,
setFinished
,
SlapPopen
,
updateFile
)
setRunning
,
setFinished
,
SlapPopen
,
updateFile
)
...
@@ -504,29 +503,26 @@ class Slapgrid(object):
...
@@ -504,29 +503,26 @@ class Slapgrid(object):
error
=
"%s does not exist."
%
self
.
instance_root
error
=
"%s does not exist."
%
self
.
instance_root
raise
OSError
(
error
)
raise
OSError
(
error
)
# Creates everything needed
# Creates everything needed
try
:
# Creates instance_root structure
# Creates instance_root structure
createPrivateDirectory
(
self
.
instance_etc_directory
)
createPrivateDirectory
(
self
.
instance_etc_directory
)
createPrivateDirectory
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
))
createPrivateDirectory
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
))
createPrivateDirectory
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'log'
))
createPrivateDirectory
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'log'
))
createPrivateDirectory
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'run'
))
createPrivateDirectory
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'run'
))
createPrivateDirectory
(
self
.
supervisord_configuration_directory
)
createPrivateDirectory
(
self
.
supervisord_configuration_directory
)
# Creates supervisord configuration
# Creates supervisord configuration
updateFile
(
self
.
supervisord_configuration_path
,
updateFile
(
self
.
supervisord_configuration_path
,
pkg_resources
.
resource_stream
(
__name__
,
pkg_resources
.
resource_stream
(
__name__
,
'templates/supervisord.conf.in'
).
read
()
%
{
'templates/supervisord.conf.in'
).
read
()
%
{
'supervisord_configuration_directory'
:
self
.
supervisord_configuration_directory
,
'supervisord_configuration_directory'
:
self
.
supervisord_configuration_directory
,
'supervisord_socket'
:
os
.
path
.
abspath
(
self
.
supervisord_socket
),
'supervisord_socket'
:
os
.
path
.
abspath
(
self
.
supervisord_socket
),
'supervisord_loglevel'
:
'info'
,
'supervisord_loglevel'
:
'info'
,
'supervisord_logfile'
:
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'log'
,
'supervisord.log'
)),
'supervisord_logfile'
:
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
instance_root
,
'var'
,
'log'
,
'supervisord.log'
)),
'supervisord_logfile_maxbytes'
:
'50MB'
,
'supervisord_logfile_maxbytes'
:
'50MB'
,
'supervisord_nodaemon'
:
'false'
,
'supervisord_nodaemon'
:
'false'
,
'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
(),
})
})
except
(
WrongPermissionError
,
PathDoesNotExistError
)
as
error
:
raise
error
def
getComputerPartitionList
(
self
):
def
getComputerPartitionList
(
self
):
try
:
try
:
...
@@ -872,7 +868,7 @@ class Slapgrid(object):
...
@@ -872,7 +868,7 @@ class Slapgrid(object):
raise
raise
# Buildout failed: send log but don't print it to output (already done)
# Buildout failed: send log but don't print it to output (already done)
except
BuildoutFailedError
,
exception
:
except
BuildoutFailedError
as
exception
:
try
:
try
:
computer_partition
.
error
(
exception
)
computer_partition
.
error
(
exception
)
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
...
@@ -942,7 +938,7 @@ class Slapgrid(object):
...
@@ -942,7 +938,7 @@ class Slapgrid(object):
exception
)
exception
)
# Buildout failed: send log but don't print it to output (already done)
# Buildout failed: send log but don't print it to output (already done)
except
BuildoutFailedError
,
exception
:
except
BuildoutFailedError
as
exception
:
clean_run
=
False
clean_run
=
False
try
:
try
:
computer_partition
.
error
(
exception
)
computer_partition
.
error
(
exception
)
...
@@ -1020,7 +1016,7 @@ class Slapgrid(object):
...
@@ -1020,7 +1016,7 @@ class Slapgrid(object):
for
computer_partition_usage
in
computer_partition_usage_list
:
for
computer_partition_usage
in
computer_partition_usage_list
:
try
:
try
:
root
=
etree
.
fromstring
(
computer_partition_usage
.
usage
)
root
=
etree
.
fromstring
(
computer_partition_usage
.
usage
)
except
UnicodeError
,
e
:
except
UnicodeError
as
e
:
self
.
logger
.
info
(
"Failed to read %s."
%
(
self
.
logger
.
info
(
"Failed to read %s."
%
(
computer_partition_usage
.
usage
))
computer_partition_usage
.
usage
))
self
.
logger
.
error
(
UnicodeError
)
self
.
logger
.
error
(
UnicodeError
)
...
@@ -1029,7 +1025,7 @@ class Slapgrid(object):
...
@@ -1029,7 +1025,7 @@ class Slapgrid(object):
self
.
logger
.
info
(
"Failed to parse %s."
%
(
computer_partition_usage
.
usage
))
self
.
logger
.
info
(
"Failed to parse %s."
%
(
computer_partition_usage
.
usage
))
self
.
logger
.
error
(
e
)
self
.
logger
.
error
(
e
)
raise
_formatXMLError
(
e
)
raise
_formatXMLError
(
e
)
except
Exception
,
e
:
except
Exception
as
e
:
raise
Exception
(
"Failed to generate XML report: %s"
%
e
)
raise
Exception
(
"Failed to generate XML report: %s"
%
e
)
for
movement
in
root
.
findall
(
'movement'
):
for
movement
in
root
.
findall
(
'movement'
):
...
...
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