workers.securityworker: simplify min id

This commit is contained in:
Jimmy Zelinskie 2017-03-03 14:50:53 -05:00
parent 591e700892
commit b9ac2b7b3b
3 changed files with 8 additions and 10 deletions

View file

@ -495,13 +495,10 @@ def get_image_id():
return Image.id
def get_images_eligible_for_scan(clair_version, min_id=None):
def get_images_eligible_for_scan(clair_version):
""" Returns a query that gives all images eligible for a clair scan """
query = (get_image_with_storage_and_parent_base()
.where(Image.security_indexed_engine < clair_version))
if min_id is not None:
query = query.where(Image.id >= min_id)
return query
return (get_image_with_storage_and_parent_base()
.where(Image.security_indexed_engine < clair_version))
def get_image_with_storage_and_parent_base():

View file

@ -589,11 +589,11 @@ class TestSecurityScanner(unittest.TestCase):
# Ensure no images are available for scanning.
self.assertIsNone(model.image.get_min_id_for_sec_scan(expected_version))
self.assertTrue(len(model.image.get_images_eligible_for_scan(expected_version, None)) == 0)
self.assertTrue(len(model.image.get_images_eligible_for_scan(expected_version)) == 0)
# Check for a higher version.
self.assertIsNotNone(model.image.get_min_id_for_sec_scan(expected_version + 1))
self.assertTrue(len(model.image.get_images_eligible_for_scan(expected_version + 1, None)) > 0)
self.assertTrue(len(model.image.get_images_eligible_for_scan(expected_version + 1)) > 0)
def test_notification_worker(self):
layer1 = model.tag.get_tag_image(ADMIN_ACCESS_USER, SIMPLE_REPO, 'latest', include_storage=True)

View file

@ -33,7 +33,8 @@ class SecurityWorker(Worker):
self._analyzer = LayerAnalyzer(app.config, secscan_api)
# Get the ID of the first image we want to analyze.
self._min_id = get_min_id_for_sec_scan(self._target_version)
self._min_id = app.config.get('SECURITY_SCANNER_INDEXING_MIN_ID',
get_min_id_for_sec_scan(self._target_version))
interval = app.config.get('SECURITY_SCANNER_INDEXING_INTERVAL', DEFAULT_INDEXING_INTERVAL)
self.add_operation(self._index_images, interval)
@ -42,7 +43,7 @@ class SecurityWorker(Worker):
def _index_images(self):
def batch_query():
return get_images_eligible_for_scan(self._target_version, app.config.get('SECURITY_SCANNER_INDEXING_MIN_ID', None))
return get_images_eligible_for_scan(self._target_version)
# Get the ID of the last image we can analyze. Will be None if there are no images in the
# database.