Remove the timestamp after periodicity.

Otherwise, periodicity may force processing the instance, but it will fail, BUT the timestamp file is still present, so it won't be processed thereafter.
parent a229061a
......@@ -768,14 +768,18 @@ class Slapgrid(object):
if timestamp:
try:
if int(timestamp) <= int(old_timestamp):
if computer_partition.getState() != COMPUTER_PARTITION_STARTED_STATE:
return
# Check periodicity, i.e if periodicity is one day, partition
# should be processed at least every day.
# Only do it for "started" instances
if computer_partition.getState() != COMPUTER_PARTITION_STARTED_STATE:
return
if int(time.time()) <= (last_runtime + periodicity):
self.logger.info('Partition already up-to-date, skipping.')
return
else:
# Periodicity forced processing this partition. Removing
# the timestamp file in case it fails.
os.remove(timestamp_path)
except ValueError:
os.remove(timestamp_path)
exception = traceback.format_exc()
......
......@@ -1022,6 +1022,37 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
'availableComputerPartition','stoppedComputerPartition',])
def test_partition_periodicity_remove_timestamp(self):
"""
Check that if periodicity forces run of buildout for a partition, it
removes the .timestamp file.
"""
computer = ComputerForTest(self.software_root,self.instance_root)
instance = computer.instance_list[0]
timestamp = str(int(time.time()))
instance.timestamp = timestamp
instance.requested_state = 'started'
instance.software.setPeriodicity(1)
self.grid.force_periodicity = True
self.launchSlapgrid()
partition = os.path.join(self.instance_root, '0')
self.assertSortedListEqual(
os.listdir(partition),
['.timestamp', 'buildout.cfg', 'software_release', 'worked'])
time.sleep(2)
# dummify install() so that it doesn't actually do anything so that it
# doesn't recreate .timestamp.
instance.install = lambda: None
self.launchSlapgrid()
self.assertSortedListEqual(
os.listdir(partition),
['.timestamp', 'buildout.cfg', 'software_release', 'worked'])
def test_partition_periodicity_is_not_overloaded_if_forced(self):
"""
If periodicity file in software directory but periodicity is forced
......
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