Merge "Don't delete building DIB images"

This commit is contained in:
Jenkins
2016-08-23 15:12:24 +00:00
committed by Gerrit Code Review
2 changed files with 28 additions and 0 deletions

View File

@@ -2200,6 +2200,7 @@ class NodePool(threading.Thread):
if len(images) > 1:
previous = images[1]
if (image != current and image != previous and
image.state != nodedb.BUILDING and
(now - image.state_time) > IMAGE_CLEANUP):
self.log.info("Deleting image id: %s which is "
"%s hours old" %

View File

@@ -692,6 +692,33 @@ class TestNodepool(tests.DBTestCase):
node = session.getNode(2)
self.assertEqual(node, None)
def test_dont_delete_building_images(self):
"""Test we don't delete building dib images"""
# Get a valid image
configfile = self.setup_config('node_dib.yaml')
pool = self.useNodepool(configfile, watermark_sleep=1)
self._useBuilder(configfile)
pool.start()
self.waitForImage(pool, 'fake-dib-provider', 'fake-dib-image')
self.waitForNodes(pool)
timeout = nodepool.nodepool.IMAGE_CLEANUP
# Modify the image to be BUILDING and have a state time older
# than the cleanup time.
with pool.getDB().getSession() as session:
dib_image = session.getDibImage(1)
dib_image.state = nodedb.BUILDING
dib_image.state_time = time.time() - timeout - 1
session.commit()
# Run cleanup which should not delete the building image
pool.cleanupOneDibImage(session, dib_image)
# Check that the image is still present in a new session
with pool.getDB().getSession() as session:
dib_image = session.getDibImage(1)
self.assertEqual(dib_image.state, nodedb.BUILDING)
self.assertTrue(time.time() - dib_image.state_time > timeout)
class TestGearClient(tests.DBTestCase):
def test_wait_for_completion(self):