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
b48b0161
Commit
b48b0161
authored
Apr 25, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
got rid of some short lived variables
parent
d34a193e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
61 deletions
+41
-61
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+41
-61
No files found.
slapos/grid/slapgrid.py
View file @
b48b0161
...
@@ -42,6 +42,7 @@ import tempfile
...
@@ -42,6 +42,7 @@ import tempfile
import
time
import
time
import
traceback
import
traceback
import
warnings
import
warnings
if
sys
.
version_info
<
(
2
,
6
):
if
sys
.
version_info
<
(
2
,
6
):
warnings
.
warn
(
'Used python version (%s) is old and has problems with'
warnings
.
warn
(
'Used python version (%s) is old and has problems with'
' IPv6 connections'
%
sys
.
version
.
split
(
'
\
n
'
)[
0
])
' IPv6 connections'
%
sys
.
version
.
split
(
'
\
n
'
)[
0
])
...
@@ -497,11 +498,9 @@ class Slapgrid(object):
...
@@ -497,11 +498,9 @@ class Slapgrid(object):
"""
"""
# Checks for software_root and instance_root existence
# Checks for software_root and instance_root existence
if
not
os
.
path
.
isdir
(
self
.
software_root
):
if
not
os
.
path
.
isdir
(
self
.
software_root
):
error
=
"%s does not exist."
%
self
.
software_root
raise
OSError
(
'%s does not exist.'
%
self
.
software_root
)
raise
OSError
(
error
)
if
not
os
.
path
.
isdir
(
self
.
instance_root
):
if
not
os
.
path
.
isdir
(
self
.
instance_root
):
error
=
"%s does not exist."
%
self
.
instance_root
raise
OSError
(
'%s does not exist.'
%
self
.
instance_root
)
raise
OSError
(
error
)
# Creates everything needed
# Creates everything needed
# Creates instance_root structure
# Creates instance_root structure
createPrivateDirectory
(
self
.
instance_etc_directory
)
createPrivateDirectory
(
self
.
instance_etc_directory
)
...
@@ -509,6 +508,7 @@ class Slapgrid(object):
...
@@ -509,6 +508,7 @@ class Slapgrid(object):
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__
,
...
@@ -526,11 +526,10 @@ class Slapgrid(object):
...
@@ -526,11 +526,10 @@ class Slapgrid(object):
def
getComputerPartitionList
(
self
):
def
getComputerPartitionList
(
self
):
try
:
try
:
computer_partition_list
=
self
.
computer
.
getComputerPartitionList
()
return
self
.
computer
.
getComputerPartitionList
()
except
socket
.
error
as
error
:
except
socket
.
error
as
error
:
self
.
logger
.
fatal
(
error
)
self
.
logger
.
fatal
(
error
)
raise
raise
return
computer_partition_list
def
processSoftwareReleaseList
(
self
):
def
processSoftwareReleaseList
(
self
):
"""Will process each Software Release.
"""Will process each Software Release.
...
@@ -585,8 +584,7 @@ class Slapgrid(object):
...
@@ -585,8 +584,7 @@ class Slapgrid(object):
logger
.
info
(
'Destroyed %r.'
%
software_release_uri
)
logger
.
info
(
'Destroyed %r.'
%
software_release_uri
)
# Send log before exiting
# Send log before exiting
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
exception
=
traceback
.
format_exc
()
software_release
.
error
(
traceback
.
format_exc
())
software_release
.
error
(
exception
)
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)
...
@@ -597,9 +595,8 @@ class Slapgrid(object):
...
@@ -597,9 +595,8 @@ class Slapgrid(object):
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
Exception
:
except
Exception
:
exception
=
traceback
.
format_exc
()
logger
.
error
(
'Problem while reporting error, continuing:
\
n
%s'
%
logger
.
error
(
'Problem during reporting error, continuing:
\
n
'
+
traceback
.
format_exc
())
exception
)
# For everything else: log it, send it, continue.
# For everything else: log it, send it, continue.
except
Exception
:
except
Exception
:
...
@@ -742,8 +739,7 @@ class Slapgrid(object):
...
@@ -742,8 +739,7 @@ class Slapgrid(object):
periodicity
=
int
(
open
(
periodicity_path
).
read
())
periodicity
=
int
(
open
(
periodicity_path
).
read
())
except
ValueError
:
except
ValueError
:
os
.
remove
(
periodicity_path
)
os
.
remove
(
periodicity_path
)
exception
=
traceback
.
format_exc
()
logger
.
error
(
traceback
.
format_exc
())
logger
.
error
(
exception
)
# 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
...
@@ -769,8 +765,7 @@ class Slapgrid(object):
...
@@ -769,8 +765,7 @@ class Slapgrid(object):
os
.
remove
(
timestamp_path
)
os
.
remove
(
timestamp_path
)
except
ValueError
:
except
ValueError
:
os
.
remove
(
timestamp_path
)
os
.
remove
(
timestamp_path
)
exception
=
traceback
.
format_exc
()
logger
.
error
(
traceback
.
format_exc
())
logger
.
error
(
exception
)
local_partition
=
Partition
(
local_partition
=
Partition
(
software_path
=
software_path
,
software_path
=
software_path
,
...
@@ -809,8 +804,7 @@ class Slapgrid(object):
...
@@ -809,8 +804,7 @@ class Slapgrid(object):
try
:
try
:
computer_partition
.
stopped
()
computer_partition
.
stopped
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
exception
=
traceback
.
format_exc
()
computer_partition
.
error
(
traceback
.
format_exc
())
computer_partition
.
error
(
exception
)
raise
raise
except
Exception
:
except
Exception
:
pass
pass
...
@@ -863,8 +857,7 @@ class Slapgrid(object):
...
@@ -863,8 +857,7 @@ class Slapgrid(object):
# Send log before exiting
# Send log before exiting
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
exception
=
traceback
.
format_exc
()
computer_partition
.
error
(
traceback
.
format_exc
())
computer_partition
.
error
(
exception
)
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)
...
@@ -874,9 +867,8 @@ class Slapgrid(object):
...
@@ -874,9 +867,8 @@ class Slapgrid(object):
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
Exception
:
except
Exception
:
exception
=
traceback
.
format_exc
()
logger
.
error
(
'Problem during reporting error, continuing:
\
n
%s'
%
logger
.
error
(
'Problem during reporting error, continuing:
\
n
'
+
traceback
.
format_exc
())
exception
)
# For everything else: log it, send it, continue.
# For everything else: log it, send it, continue.
except
Exception
as
exception
:
except
Exception
as
exception
:
...
@@ -886,9 +878,8 @@ class Slapgrid(object):
...
@@ -886,9 +878,8 @@ class Slapgrid(object):
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
Exception
:
except
Exception
:
exception
=
traceback
.
format_exc
()
logger
.
error
(
'Problem during reporting error, continuing:
\
n
%s'
%
logger
.
error
(
'Problem during reporting error, continuing:
\
n
'
+
traceback
.
format_exc
())
exception
)
return
filtered_computer_partition_list
return
filtered_computer_partition_list
...
@@ -921,8 +912,7 @@ class Slapgrid(object):
...
@@ -921,8 +912,7 @@ class Slapgrid(object):
# Send log before exiting
# Send log before exiting
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
exception
=
traceback
.
format_exc
()
computer_partition
.
error
(
traceback
.
format_exc
())
computer_partition
.
error
(
exception
)
raise
raise
except
Slapgrid
.
PromiseError
as
exception
:
except
Slapgrid
.
PromiseError
as
exception
:
...
@@ -933,9 +923,8 @@ class Slapgrid(object):
...
@@ -933,9 +923,8 @@ class Slapgrid(object):
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
Exception
:
except
Exception
:
exception
=
traceback
.
format_exc
()
logger
.
error
(
'Problem during reporting error, continuing:
\
n
%s'
%
logger
.
error
(
'Problem during reporting error, continuing:
\
n
'
+
traceback
.
format_exc
())
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
as
exception
:
except
BuildoutFailedError
as
exception
:
...
@@ -945,9 +934,8 @@ class Slapgrid(object):
...
@@ -945,9 +934,8 @@ class Slapgrid(object):
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
Exception
:
except
Exception
:
exception
=
traceback
.
format_exc
()
logger
.
error
(
'Problem during reporting error, continuing:
\
n
%s'
%
logger
.
error
(
'Problem during reporting error, continuing:
\
n
'
+
traceback
.
format_exc
())
exception
)
# For everything else: log it, send it, continue.
# For everything else: log it, send it, continue.
except
Exception
as
exception
:
except
Exception
as
exception
:
...
@@ -958,9 +946,8 @@ class Slapgrid(object):
...
@@ -958,9 +946,8 @@ class Slapgrid(object):
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
raise
raise
except
Exception
:
except
Exception
:
exception
=
traceback
.
format_exc
()
logger
.
error
(
'Problem during reporting error, continuing:
\
n
%s'
%
logger
.
error
(
'Problem during reporting error, continuing:
\
n
'
+
traceback
.
format_exc
())
exception
)
logger
.
info
(
"Finished computer partitions."
)
logger
.
info
(
"Finished computer partitions."
)
...
@@ -1017,8 +1004,7 @@ class Slapgrid(object):
...
@@ -1017,8 +1004,7 @@ class Slapgrid(object):
try
:
try
:
root
=
etree
.
fromstring
(
computer_partition_usage
.
usage
)
root
=
etree
.
fromstring
(
computer_partition_usage
.
usage
)
except
UnicodeError
as
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
)
raise
UnicodeError
(
"Failed to read %s: %s"
%
(
computer_partition_usage
.
usage
,
e
))
raise
UnicodeError
(
"Failed to read %s: %s"
%
(
computer_partition_usage
.
usage
,
e
))
except
(
etree
.
XMLSyntaxError
,
etree
.
DocumentInvalid
)
as
e
:
except
(
etree
.
XMLSyntaxError
,
etree
.
DocumentInvalid
)
as
e
:
...
@@ -1134,11 +1120,9 @@ class Slapgrid(object):
...
@@ -1134,11 +1120,9 @@ class Slapgrid(object):
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_list
))
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_list
))
# Whatever happens, don't stop processing other instances
# Whatever happens, don't stop processing other instances
except
Exception
:
except
Exception
:
computer_partition_id
=
computer_partition
.
getId
()
logger
.
info
(
'Cannot run usage script(s) for %r: %s'
%
(
exception
=
traceback
.
format_exc
()
computer_partition
.
getId
(),
issue
=
"Cannot run usage script(s) for %r: %s"
%
(
traceback
.
format_exc
()))
computer_partition_id
,
exception
)
logger
.
info
(
issue
)
#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
=
[]
...
@@ -1155,7 +1139,6 @@ class Slapgrid(object):
...
@@ -1155,7 +1139,6 @@ class Slapgrid(object):
else
:
else
:
filename_list
=
[]
filename_list
=
[]
#logger.debug('name List %s' % filename_list)
#logger.debug('name List %s' % filename_list)
usage
=
''
for
filename
in
filename_list
:
for
filename
in
filename_list
:
...
@@ -1185,15 +1168,14 @@ class Slapgrid(object):
...
@@ -1185,15 +1168,14 @@ class Slapgrid(object):
# Whatever happens, don't stop processing other instances
# Whatever happens, don't stop processing other instances
except
Exception
:
except
Exception
:
computer_partition_id
=
computer_partition
.
getId
()
logger
.
info
(
'Cannot run usage script(s) for %r: %s'
%
(
exception
=
traceback
.
format_exc
()
computer_partition
.
getId
(),
issue
=
"Cannot run usage script(s) for %r: %s"
%
(
traceback
.
format_exc
()))
computer_partition_id
,
exception
)
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
if
computer_partition_usage_list
!=
[]:
if
computer_partition_usage_list
!=
[]:
...
@@ -1211,10 +1193,9 @@ class Slapgrid(object):
...
@@ -1211,10 +1193,9 @@ class Slapgrid(object):
logger
.
info
(
'XML file generated by asXML is not valid !'
)
logger
.
info
(
'XML file generated by asXML is not valid !'
)
raise
ValueError
(
'XML file generated by asXML is not valid !'
)
raise
ValueError
(
'XML file generated by asXML is not valid !'
)
except
Exception
:
except
Exception
:
computer_partition_id
=
computer_partition
.
getId
()
issue
=
"Cannot report usage for %r: %s"
%
(
exception
=
traceback
.
format_exc
()
computer_partition
.
getId
(),
issue
=
"Cannot report usage for %r: %s"
%
(
computer_partition_id
,
traceback
.
format_exc
())
exception
)
logger
.
info
(
issue
)
logger
.
info
(
issue
)
computer_partition
.
error
(
issue
)
computer_partition
.
error
(
issue
)
report_usage_issue_cp_list
.
append
(
computer_partition_id
)
report_usage_issue_cp_list
.
append
(
computer_partition_id
)
...
@@ -1229,6 +1210,7 @@ class Slapgrid(object):
...
@@ -1229,6 +1210,7 @@ class Slapgrid(object):
except
(
NotFoundError
,
TypeError
):
except
(
NotFoundError
,
TypeError
):
software_url
=
None
software_url
=
None
software_path
=
None
software_path
=
None
local_partition
=
Partition
(
local_partition
=
Partition
(
software_path
=
software_path
,
software_path
=
software_path
,
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
instance_path
=
os
.
path
.
join
(
self
.
instance_root
,
...
@@ -1249,19 +1231,17 @@ class Slapgrid(object):
...
@@ -1249,19 +1231,17 @@ class Slapgrid(object):
try
:
try
:
computer_partition
.
stopped
()
computer_partition
.
stopped
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
exception
=
traceback
.
format_exc
()
computer_partition
.
error
(
traceback
.
format_exc
())
computer_partition
.
error
(
exception
)
raise
raise
except
Exception
:
except
Exception
:
pass
pass
if
computer_partition
.
getId
()
in
report_usage_issue_cp_list
:
if
computer_partition
.
getId
()
in
report_usage_issue_cp_list
:
logger
.
info
(
'Ignoring destruction of %r, as no
t report usage was '
logger
.
info
(
'Ignoring destruction of %r, as no
report usage was sent'
%
'sent'
%
computer_partition
.
getId
())
computer_partition
.
getId
())
continue
continue
local_partition
.
destroy
()
local_partition
.
destroy
()
except
(
SystemExit
,
KeyboardInterrupt
):
except
(
SystemExit
,
KeyboardInterrupt
):
exception
=
traceback
.
format_exc
()
computer_partition
.
error
(
traceback
.
format_exc
())
computer_partition
.
error
(
exception
)
raise
raise
except
Exception
:
except
Exception
:
clean_run
=
False
clean_run
=
False
...
...
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