Commit ec1481e8 authored by Guillaume Hervier's avatar Guillaume Hervier

slapgrid: Add tear down methods to IManager interface

parent edcb9762
...@@ -668,6 +668,9 @@ class Computer(object): ...@@ -668,6 +668,9 @@ class Computer(object):
except IndexError: except IndexError:
pass pass
for manager in self._manager_list:
manager.formatTearDown(self)
class Partition(object): class Partition(object):
"""Represent a computer partition.""" """Represent a computer partition."""
......
...@@ -580,6 +580,10 @@ stderr_logfile_backups=1 ...@@ -580,6 +580,10 @@ stderr_logfile_backups=1
self.logger.info('Destroying %r...' % software_release_uri) self.logger.info('Destroying %r...' % software_release_uri)
software.destroy() software.destroy()
self.logger.info('Destroyed %r.' % software_release_uri) self.logger.info('Destroyed %r.' % software_release_uri)
# call manager for every software release
for manager in self._manager_list:
manager.softwareTearDown(software)
# Send log before exiting # Send log before exiting
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
software_release.error(traceback.format_exc(), logger=self.logger) software_release.error(traceback.format_exc(), logger=self.logger)
...@@ -1037,6 +1041,11 @@ stderr_logfile_backups=1 ...@@ -1037,6 +1041,11 @@ stderr_logfile_backups=1
self._checkPromiseAnomaly(local_partition, computer_partition) self._checkPromiseAnomaly(local_partition, computer_partition)
else: else:
self.logger.debug('Partition already up-to-date. skipping.') self.logger.debug('Partition already up-to-date. skipping.')
# Run manager tear down
for manager in self._manager_list:
manager.instanceTearDown(local_partition)
return return
else: else:
# Periodicity forced processing this partition. Removing # Periodicity forced processing this partition. Removing
...@@ -1137,6 +1146,10 @@ stderr_logfile_backups=1 ...@@ -1137,6 +1146,10 @@ stderr_logfile_backups=1
else: else:
self.logger.removeHandler(partition_file_handler) self.logger.removeHandler(partition_file_handler)
# Run manager tear down
for manager in self._manager_list:
manager.instanceTearDown(local_partition)
# If partition has been successfully processed, write timestamp # If partition has been successfully processed, write timestamp
if timestamp: if timestamp:
open(timestamp_path, 'w').write(timestamp) open(timestamp_path, 'w').write(timestamp)
......
...@@ -36,6 +36,10 @@ class Manager(object): ...@@ -36,6 +36,10 @@ class Manager(object):
"""We don't need to mingle with software.""" """We don't need to mingle with software."""
pass pass
def softwareTearDown(self, software):
"""We don't need to mingle with software."""
pass
def format(self, computer): def format(self, computer):
"""Create cgroup folder per-CPU with exclusive access to the CPU. """Create cgroup folder per-CPU with exclusive access to the CPU.
...@@ -55,6 +59,9 @@ class Manager(object): ...@@ -55,6 +59,9 @@ class Manager(object):
with open(cpu_path + "/cpuset.mems", "wt") as fx: with open(cpu_path + "/cpuset.mems", "wt") as fx:
fx.write("0") # it doesn't work without that fx.write("0") # it doesn't work without that
def formatTearDown(self, computer):
pass
def instance(self, partition): def instance(self, partition):
"""Control runtime state of the computer.""" """Control runtime state of the computer."""
...@@ -135,6 +142,9 @@ class Manager(object): ...@@ -135,6 +142,9 @@ class Manager(object):
with open(request_file, "at") as fo: with open(request_file, "at") as fo:
fo.write(str(request_pid) + "\n") fo.write(str(request_pid) + "\n")
def instanceTearDown(self):
pass
def _cpu_folder_list(self): def _cpu_folder_list(self):
"""Return list of folders for exclusive cpu cores.""" """Return list of folders for exclusive cpu cores."""
return [os.path.join(self.cpuset_path, "cpu" + str(cpu_id)) return [os.path.join(self.cpuset_path, "cpu" + str(cpu_id))
......
...@@ -17,18 +17,36 @@ class IManager(Interface): ...@@ -17,18 +17,36 @@ class IManager(Interface):
:param computer: slapos.format.Computer, currently formatted computer :param computer: slapos.format.Computer, currently formatted computer
""" """
def formatTearDown(computer):
"""Method called after `slapos node format` phase.
:param computer: slapos.format.Computer, formatted computer
"""
def software(software): def software(software):
"""Method called at `slapos node software` phase. """Method called at `slapos node software` phase.
:param software: slapos.grid.SlapObject.Software, currently processed software :param software: slapos.grid.SlapObject.Software, currently processed software
""" """
def softwareTearDown(software):
"""Method called after `slapos node software` phase.
:param computer: slapos.grid.SlapObject.Software, processed software
"""
def instance(partition): def instance(partition):
"""Method called at `slapos node instance` phase. """Method called at `slapos node instance` phase.
:param partition: slapos.grid.SlapObject.Partition, currently processed partition :param partition: slapos.grid.SlapObject.Partition, currently processed partition
""" """
def instanceTearDown(partition):
"""Method called after `slapos node instance` phase.
:param partition: slapos.grid.SlapObject.Partition, processed partition
"""
def report(partition): def report(partition):
"""Method called at `slapos node report` phase. """Method called at `slapos node report` phase.
......
...@@ -25,16 +25,37 @@ class Manager(object): ...@@ -25,16 +25,37 @@ class Manager(object):
""" """
pass pass
def formatTearDown(self, computer):
"""Method called after `slapos node format` phase.
:param computer: slapos.format.Computer, formatted computer
"""
pass
def software(self, software): def software(self, software):
"""Method called at `slapos node software` phase. """Method called at `slapos node software` phase.
""" """
pass pass
def softwareTearDown(self, software):
"""Method called after `slapos node software` phase.
:param computer: slapos.grid.SlapObject.Software, processed software
"""
pass
def instance(self, partition): def instance(self, partition):
"""Method called at `slapos node instance` phase. """Method called at `slapos node instance` phase.
""" """
pass pass
def instanceTearDown(self, partition):
"""Method called after `slapos node instance` phase.
:param partition: slapos.grid.SlapObject.Partition, processed partition
"""
pass
def report(self, partition): def report(self, partition):
"""Method called at `slapos node report` phase.""" """Method called at `slapos node report` phase."""
......
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