[SlapOS Core] Make sure periodicity behaves correctly on non-started instances.

Remove early optimization.
parent 625175ec
...@@ -592,11 +592,8 @@ class Slapgrid(object): ...@@ -592,11 +592,8 @@ class Slapgrid(object):
if periodicity == 0: if periodicity == 0:
os.remove(timestamp_path) os.remove(timestamp_path)
elif int(timestamp) <= int(old_timestamp): elif int(timestamp) <= int(old_timestamp):
if computer_partition.getState() != COMPUTER_PARTITION_STARTED_STATE:
return
# Check periodicity, i.e if periodicity is one day, partition # Check periodicity, i.e if periodicity is one day, partition
# should be processed at least every day. # should be processed at least every day.
# Only do it for "started" instances
if int(time.time()) <= (last_runtime + periodicity) or periodicity < 0: if int(time.time()) <= (last_runtime + periodicity) or periodicity < 0:
self.logger.info('Partition already up-to-date, skipping.') self.logger.info('Partition already up-to-date, skipping.')
return return
......
...@@ -1294,7 +1294,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase): ...@@ -1294,7 +1294,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
def test_one_partition_stopped_is_not_processed_after_periodicity(self): def test_one_partition_stopped_is_not_processed_after_periodicity(self):
""" """
Check that periodicity doesn't force processing a partition if it is not Check that periodicity forces processing a partition even if it is not
started. started.
""" """
computer = ComputerForTest(self.software_root, self.instance_root, 20, 20) computer = ComputerForTest(self.software_root, self.instance_root, 20, 20)
...@@ -1320,18 +1320,19 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase): ...@@ -1320,18 +1320,19 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
time.sleep(1) time.sleep(1)
self.launchSlapgrid() self.launchSlapgrid()
self.assertEqual(instance0.sequence, self.assertEqual(instance0.sequence,
['availableComputerPartition', 'stoppedComputerPartition']) ['availableComputerPartition', 'stoppedComputerPartition',
'availableComputerPartition', 'stoppedComputerPartition'])
for instance in computer.instance_list[1:]: for instance in computer.instance_list[1:]:
self.assertEqual(instance.sequence, self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition']) ['availableComputerPartition', 'stoppedComputerPartition'])
self.assertEqual(os.path.getmtime(os.path.join(instance0.partition_path, self.assertNotEqual(os.path.getmtime(os.path.join(instance0.partition_path,
'.timestamp')), '.timestamp')),
last_runtime) last_runtime)
self.assertNotEqual(wanted_periodicity, self.grid.maximum_periodicity) self.assertNotEqual(wanted_periodicity, self.grid.maximum_periodicity)
def test_one_partition_destroyed_is_not_processed_after_periodicity(self): def test_one_partition_destroyed_is_not_processed_after_periodicity(self):
""" """
Check that periodicity doesn't force processing a partition if it is not Check that periodicity forces processing a partition even if it is not
started. started.
""" """
computer = ComputerForTest(self.software_root, self.instance_root, 20, 20) computer = ComputerForTest(self.software_root, self.instance_root, 20, 20)
...@@ -1359,11 +1360,12 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase): ...@@ -1359,11 +1360,12 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
instance0.requested_state = 'destroyed' instance0.requested_state = 'destroyed'
self.launchSlapgrid() self.launchSlapgrid()
self.assertEqual(instance0.sequence, self.assertEqual(instance0.sequence,
['availableComputerPartition', 'stoppedComputerPartition']) ['availableComputerPartition', 'stoppedComputerPartition',
'stoppedComputerPartition'])
for instance in computer.instance_list[1:]: for instance in computer.instance_list[1:]:
self.assertEqual(instance.sequence, self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition']) ['availableComputerPartition', 'stoppedComputerPartition'])
self.assertEqual(os.path.getmtime(os.path.join(instance0.partition_path, self.assertNotEqual(os.path.getmtime(os.path.join(instance0.partition_path,
'.timestamp')), '.timestamp')),
last_runtime) last_runtime)
self.assertNotEqual(wanted_periodicity, self.grid.maximum_periodicity) self.assertNotEqual(wanted_periodicity, self.grid.maximum_periodicity)
......
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