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