Move all partition logic in dedicated method, to be more readable.

parent 77bc6c75
...@@ -554,6 +554,7 @@ class Slapgrid(object): ...@@ -554,6 +554,7 @@ class Slapgrid(object):
logger.info("Finished software releases...") logger.info("Finished software releases...")
return clean_run return clean_run
def _launchSupervisord(self): def _launchSupervisord(self):
launchSupervisord(self.supervisord_socket, launchSupervisord(self.supervisord_socket,
self.supervisord_configuration_path) self.supervisord_configuration_path)
...@@ -610,33 +611,12 @@ class Slapgrid(object): ...@@ -610,33 +611,12 @@ class Slapgrid(object):
if not promise_present: if not promise_present:
self.logger.info("No promise.") self.logger.info("No promise.")
def processComputerPartitionList(self): def processComputerPartition(self, computer_partition):
""" """
Will start supervisord and process each Computer Partition. Process a Computer Partition, depending on its state
""" """
logger = logging.getLogger('ComputerPartitionProcessing') logger = logging.getLogger('ComputerPartitionProcessing')
logger.info('Processing computer partitions...')
# Prepares environment
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:
# If id or URL is not defined, then it is an empty partition.
try:
computer_partition.getId()
computer_partition.getSoftwareRelease().getURI()
# XXX should test status as well. But getState() returns default
# value.
except NotFoundError:
# No Software Release information: skip.
continue
# Process the partition itself
computer_partition_id = computer_partition.getId() computer_partition_id = computer_partition.getId()
software_url = computer_partition.getSoftwareRelease().getURI() software_url = computer_partition.getSoftwareRelease().getURI()
...@@ -653,7 +633,7 @@ class Slapgrid(object): ...@@ -653,7 +633,7 @@ class Slapgrid(object):
# If so, if current partition not in this list, skip. # If so, if current partition not in this list, skip.
if len(self.computer_partition_filter_list) > 0 and \ if len(self.computer_partition_filter_list) > 0 and \
(computer_partition_id not in self.computer_partition_filter_list): (computer_partition_id not in self.computer_partition_filter_list):
continue return
instance_path = os.path.join(self.instance_root, computer_partition_id) instance_path = os.path.join(self.instance_root, computer_partition_id)
...@@ -691,7 +671,7 @@ class Slapgrid(object): ...@@ -691,7 +671,7 @@ class Slapgrid(object):
if int(timestamp) <= int(old_timestamp): if int(timestamp) <= int(old_timestamp):
if int(time.time()) <= ( if int(time.time()) <= (
last_runtime + self.maximum_periodicity) : last_runtime + self.maximum_periodicity) :
continue return
except ValueError: except ValueError:
os.remove(timestamp_path) os.remove(timestamp_path)
exception = traceback.format_exc() exception = traceback.format_exc()
...@@ -699,6 +679,7 @@ class Slapgrid(object): ...@@ -699,6 +679,7 @@ class Slapgrid(object):
software_path = os.path.join(self.software_root, software_path = os.path.join(self.software_root,
getSoftwareUrlHash(software_url)) getSoftwareUrlHash(software_url))
local_partition = Partition( local_partition = Partition(
software_path=software_path, software_path=software_path,
instance_path=instance_path, instance_path=instance_path,
...@@ -741,11 +722,40 @@ class Slapgrid(object): ...@@ -741,11 +722,40 @@ class Slapgrid(object):
(computer_partition_id, computer_partition_state) (computer_partition_id, computer_partition_state)
computer_partition.error(error_string) computer_partition.error(error_string)
raise NotImplementedError(error_string) raise NotImplementedError(error_string)
# If partition has been successfully processed, write timestamp # If partition has been successfully processed, write timestamp
if timestamp: if timestamp:
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):
"""
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
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:
# If id or URL is not defined, then it is an empty partition.
try:
computer_partition.getId()
computer_partition.getSoftwareRelease().getURI()
# XXX should test status as well. But getState() returns default
# value.
except NotFoundError:
# No Software Release information: skip.
continue
# Process the partition itself
self.processComputerPartition(computer_partition)
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
exception = traceback.format_exc() exception = traceback.format_exc()
......
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