Merge "Don't delete building DIB images"
This commit is contained in:
@@ -2200,6 +2200,7 @@ class NodePool(threading.Thread):
|
|||||||
if len(images) > 1:
|
if len(images) > 1:
|
||||||
previous = images[1]
|
previous = images[1]
|
||||||
if (image != current and image != previous and
|
if (image != current and image != previous and
|
||||||
|
image.state != nodedb.BUILDING and
|
||||||
(now - image.state_time) > IMAGE_CLEANUP):
|
(now - image.state_time) > IMAGE_CLEANUP):
|
||||||
self.log.info("Deleting image id: %s which is "
|
self.log.info("Deleting image id: %s which is "
|
||||||
"%s hours old" %
|
"%s hours old" %
|
||||||
|
@@ -692,6 +692,33 @@ class TestNodepool(tests.DBTestCase):
|
|||||||
node = session.getNode(2)
|
node = session.getNode(2)
|
||||||
self.assertEqual(node, None)
|
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):
|
class TestGearClient(tests.DBTestCase):
|
||||||
def test_wait_for_completion(self):
|
def test_wait_for_completion(self):
|
||||||
|
Reference in New Issue
Block a user