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