Factor partition filter to use it as well in Usage Report.

Also change behavior to ignore cases defined in e93f690.
parent eef08f27
...@@ -786,21 +786,13 @@ class Slapgrid(object): ...@@ -786,21 +786,13 @@ class Slapgrid(object):
timestamp_path = os.path.join(instance_path, '.timestamp') timestamp_path = os.path.join(instance_path, '.timestamp')
open(timestamp_path, 'w').write(timestamp) open(timestamp_path, 'w').write(timestamp)
def processComputerPartitionList(self): def FilterComputerPartitionList(self, computer_partition_list):
""" """
Will start supervisord and process each Computer Partition. Try to filter valid partitions to be processed from free partitions.
""" """
logger = logging.getLogger('ComputerPartitionProcessing') logger = logging.getLogger('ComputerPartitionProcessing')
logger.info('Processing computer partitions...') filtered_computer_partition_list = []
# Prepares environment for computer_partition in computer_partition_list:
self.checkEnvironmentAndCreateStructure()
self._launchSupervisord()
# Process Computer Partitions
clean_run = True
for computer_partition in self.getComputerPartitionList():
# Nothing should raise outside of the current loop iteration, so that
# even if something is terribly wrong while processing an instance, it
# won't prevent processing other ones.
try: try:
computer_partition_path = os.path.join(self.instance_root, computer_partition_path = os.path.join(self.instance_root,
computer_partition.getId()) computer_partition.getId())
...@@ -817,6 +809,75 @@ class Slapgrid(object): ...@@ -817,6 +809,75 @@ class Slapgrid(object):
os.listdir(computer_partition_path) == []: os.listdir(computer_partition_path) == []:
continue continue
# If partition has no SR: skip it.
try:
software_url = computer_partition.getSoftwareRelease().getURI()
software_path = os.path.join(self.software_root,
getSoftwareUrlHash(software_url))
except (NotFoundError, TypeError):
# This is surely free partition. Check it...
if os.listdir(computer_partition_path) == []:
continue
# Everything seems fine
filtered_computer_partition_list.append(computer_partition)
# XXX-Cedric: factor all this error handling
# Send log before exiting
except (SystemExit, KeyboardInterrupt):
exception = traceback.format_exc()
computer_partition.error(exception)
raise
# Buildout failed: send log but don't print it to output (already done)
except BuildoutFailedError, exception:
clean_run = False
try:
computer_partition.error(exception)
except (SystemExit, KeyboardInterrupt):
raise
except Exception:
exception = traceback.format_exc()
logger.error('Problem during reporting error, continuing:\n' +
exception)
# For everything else: log it, send it, continue.
except Exception as exception:
clean_run = False
logger.error(traceback.format_exc())
try:
computer_partition.error(exception)
except (SystemExit, KeyboardInterrupt):
raise
except Exception:
exception = traceback.format_exc()
logger.error('Problem during reporting error, continuing:\n' +
exception)
return filtered_computer_partition_list
def processComputerPartitionList(self):
"""
Will start supervisord and process each Computer Partition.
"""
logger = logging.getLogger('ComputerPartitionProcessing')
logger.info('Processing computer partitions...')
# Prepares environment
self.checkEnvironmentAndCreateStructure()
self._launchSupervisord()
# Process Computer Partitions
clean_run = True
# Filter all dummy / empty partitions
computer_partition_list = self.FilterComputerPartitionList(
self.getComputerPartitionList())
for computer_partition in computer_partition_list:
# Nothing should raise outside of the current loop iteration, so that
# even if something is terribly wrong while processing an instance, it
# won't prevent processing other ones.
try:
# Process the partition itself # Process the partition itself
self.processComputerPartition(computer_partition) self.processComputerPartition(computer_partition)
...@@ -973,8 +1034,9 @@ class Slapgrid(object): ...@@ -973,8 +1034,9 @@ class Slapgrid(object):
'../../../../slapos/slap/doc/partition_consumption.xsd') '../../../../slapos/slap/doc/partition_consumption.xsd')
clean_run = True clean_run = True
#We loop on the different computer partitions # Loop on the different computer partitions
computer_partition_list = slap_computer_usage.getComputerPartitionList() computer_partition_list = self.FilterComputerPartitionList(
slap_computer_usage.getComputerPartitionList())
for computer_partition in computer_partition_list: for computer_partition in computer_partition_list:
try: try:
computer_partition_id = computer_partition.getId() computer_partition_id = computer_partition.getId()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment