Merge pull request #917 from Quentin-M/fix_secwor

Fix security worker (again?)
This commit is contained in:
Quentin Machu 2015-11-18 19:45:36 -05:00
commit 04f2688944
2 changed files with 22 additions and 27 deletions

View file

@ -468,7 +468,7 @@ def get_secscan_candidates(engine_version, batch_size):
rimages = [] rimages = []
# Collect the images without parents # Collect the images without parents
candidates = (Image candidates = list(Image
.select(Image.id) .select(Image.id)
.join(ImageStorage) .join(ImageStorage)
.where(Image.security_indexed_engine < engine_version, .where(Image.security_indexed_engine < engine_version,
@ -483,11 +483,10 @@ def get_secscan_candidates(engine_version, batch_size):
.order_by(db_random_func()) .order_by(db_random_func())
.limit(batch_size)) .limit(batch_size))
for image in images: rimages.extend(images)
rimages.append(image)
# Collect the images with analyzed parents. # Collect the images with analyzed parents.
candidates = (Image candidates = list(Image
.select(Image.id) .select(Image.id)
.join(Parent, on=(Image.parent == Parent.id)) .join(Parent, on=(Image.parent == Parent.id))
.switch(Image) .switch(Image)
@ -508,8 +507,7 @@ def get_secscan_candidates(engine_version, batch_size):
.order_by(db_random_func()) .order_by(db_random_func())
.limit(batch_size)) .limit(batch_size))
for image in images: rimages.extend(images)
rimages.append(image)
# Shuffle the images, otherwise the images without parents will always be on the top # Shuffle the images, otherwise the images without parents will always be on the top
random.shuffle(rimages) random.shuffle(rimages)

View file

@ -13,7 +13,7 @@ from data import model
from data.model.tag import filter_tags_have_repository_event, get_tags_for_image from data.model.tag import filter_tags_have_repository_event, get_tags_for_image
from data.model.image import get_secscan_candidates, set_secscan_status from data.model.image import get_secscan_candidates, set_secscan_status
from data.model.storage import get_storage_locations from data.model.storage import get_storage_locations
from data.database import (Image, UseThenDisconnect, ExternalNotificationEvent) from data.database import (UseThenDisconnect, ExternalNotificationEvent)
from util.secscan.api import SecurityConfigValidator from util.secscan.api import SecurityConfigValidator
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -154,11 +154,8 @@ class SecurityWorker(Worker):
while True: while True:
# Lookup the images to index. # Lookup the images to index.
images = [] images = []
try:
logger.debug('Looking up images to index') logger.debug('Looking up images to index')
images = get_secscan_candidates(self._target_version, BATCH_SIZE) images = get_secscan_candidates(self._target_version, BATCH_SIZE)
except Image.DoesNotExist:
pass
if not images: if not images:
logger.debug('No more images left to analyze') logger.debug('No more images left to analyze')