slapos.grid: Adapt retention_delay implementation to support retention_delay...

slapos.grid: Adapt retention_delay implementation to support retention_delay being specified in SLA.
parent 8c6ecfef
...@@ -292,7 +292,7 @@ class Partition(object): ...@@ -292,7 +292,7 @@ class Partition(object):
buildout, buildout,
logger, logger,
certificate_repository_path=None, certificate_repository_path=None,
retention_delay=0 retention_delay='0',
): ):
"""Initialisation of class parameters""" """Initialisation of class parameters"""
self.buildout = buildout self.buildout = buildout
...@@ -319,9 +319,9 @@ class Partition(object): ...@@ -319,9 +319,9 @@ class Partition(object):
self.partition_id + '.crt') self.partition_id + '.crt')
self._updateCertificate() self._updateCertificate()
self.retention_delay = retention_delay try:
if type(self.retention_delay) not in (int, float) \ self.retention_delay = float(retention_delay)
or self.retention_delay <= 0: except ValueError:
self.logger.warn('Retention delay value (%s) is not valid, ignoring.' \ self.logger.warn('Retention delay value (%s) is not valid, ignoring.' \
% self.retention_delay) % self.retention_delay)
self.retention_delay = 0 self.retention_delay = 0
......
...@@ -648,6 +648,12 @@ class Slapgrid(object): ...@@ -648,6 +648,12 @@ class Slapgrid(object):
self.logger.info(' Software path: %s' % software_path) self.logger.info(' Software path: %s' % software_path)
self.logger.info(' Instance path: %s' % instance_path) self.logger.info(' Instance path: %s' % instance_path)
filter_dict = getattr(computer_partition, '_filter_dict', None)
if filter_dict:
retention_delay = filter_dict.get('retention_delay', '0')
else:
retention_delay = '0'
local_partition = Partition( local_partition = Partition(
software_path=software_path, software_path=software_path,
instance_path=instance_path, instance_path=instance_path,
...@@ -663,7 +669,8 @@ class Slapgrid(object): ...@@ -663,7 +669,8 @@ class Slapgrid(object):
certificate_repository_path=self.certificate_repository_path, certificate_repository_path=self.certificate_repository_path,
buildout=self.buildout, buildout=self.buildout,
logger=self.logger, logger=self.logger,
retention_delay=getattr(computer_partition, '_retention_delay', 0)) retention_delay=retention_delay,
)
computer_partition_state = computer_partition.getState() computer_partition_state = computer_partition.getState()
# XXX this line breaks 37 tests # XXX this line breaks 37 tests
...@@ -1090,7 +1097,7 @@ class Slapgrid(object): ...@@ -1090,7 +1097,7 @@ class Slapgrid(object):
certificate_repository_path=self.certificate_repository_path, certificate_repository_path=self.certificate_repository_path,
buildout=self.buildout, buildout=self.buildout,
logger=self.logger, logger=self.logger,
retention_delay=getattr(computer_partition, '_retention_delay', 0)) )
local_partition.stop() local_partition.stop()
try: try:
computer_partition.stopped() computer_partition.stopped()
......
...@@ -437,8 +437,8 @@ class InstanceForTest: ...@@ -437,8 +437,8 @@ class InstanceForTest:
partition = slapos.slap.ComputerPartition(computer_id, self.name) partition = slapos.slap.ComputerPartition(computer_id, self.name)
partition._software_release_document = self.getSoftwareRelease() partition._software_release_document = self.getSoftwareRelease()
partition._requested_state = self.requested_state partition._requested_state = self.requested_state
if getattr(self, 'retention_delay', None): if getattr(self, 'filter_dict', None):
partition._retention_delay = self.retention_delay partition._filter_dict = self.filter_dict
if self.software is not None: if self.software is not None:
if self.timestamp is not None: if self.timestamp is not None:
partition._parameter_dict = {'timestamp': self.timestamp} partition._parameter_dict = {'timestamp': self.timestamp}
...@@ -1904,7 +1904,7 @@ class TestSlapgridDestructionLock(MasterMixin, unittest.TestCase): ...@@ -1904,7 +1904,7 @@ class TestSlapgridDestructionLock(MasterMixin, unittest.TestCase):
computer = ComputerForTest(self.software_root, self.instance_root) computer = ComputerForTest(self.software_root, self.instance_root)
instance = computer.instance_list[0] instance = computer.instance_list[0]
instance.requested_state = 'started' instance.requested_state = 'started'
instance.retention_delay = 1.0 / (3600 * 24) instance.filter_dict = {'retention_delay': 1.0 / (3600 * 24)}
self.grid.processComputerPartitionList() self.grid.processComputerPartitionList()
dummy_instance_file_path = os.path.join(instance.partition_path, 'dummy') dummy_instance_file_path = os.path.join(instance.partition_path, 'dummy')
with open(dummy_instance_file_path, 'w') as dummy_instance_file: with open(dummy_instance_file_path, 'w') as dummy_instance_file:
......
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