This commit is contained in:
Joseph Schorr 2017-06-29 09:43:04 +03:00
parent 1ddb09ac11
commit 27ed3bedcc
5 changed files with 9 additions and 7 deletions

View file

@ -10,6 +10,7 @@ logger = logging.getLogger(__name__)
unscanned_images_gauge = prometheus.create_gauge('unscanned_images',
'Number of images that clair needs to scan.')
def index_images(target_version, analyzer, token=None):
""" Performs security indexing of all images in the database not scanned at the target version.
If a token is provided, scanning will begin where the token indicates it previously completed.

View file

@ -3,6 +3,7 @@ from collections import namedtuple
from six import add_metaclass
class ScanToken(namedtuple('NextScanToken', ['min_id'])):
"""
ScanToken represents an opaque token that can be passed between runs of the security worker
@ -11,6 +12,7 @@ class ScanToken(namedtuple('NextScanToken', ['min_id'])):
the token in any way.
"""
@add_metaclass(ABCMeta)
class SecurityWorkerDataInterface(object):
"""

View file

@ -5,10 +5,8 @@ from data.model.image import (get_images_eligible_for_scan, get_image_pk_field,
get_max_id_for_sec_scan, get_min_id_for_sec_scan)
from util.migrate.allocator import yield_random_entries
from workers.securityworker.models_interface import (
ScanToken,
SecurityWorkerDataInterface
)
from workers.securityworker.models_interface import (ScanToken, SecurityWorkerDataInterface)
class PreOCIModel(SecurityWorkerDataInterface):
def candidates_to_scan(self, target_version, start_token=None):
@ -43,8 +41,7 @@ class PreOCIModel(SecurityWorkerDataInterface):
get_image_pk_field(),
batch_size,
max_id,
min_id,
)
min_id,)
return (iterator, ScanToken(max_id + 1))

View file

@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
DEFAULT_INDEXING_INTERVAL = 30
class SecurityWorker(Worker):
def __init__(self):
super(SecurityWorker, self).__init__()

View file

@ -3,6 +3,7 @@ from mock import patch, Mock
from test.fixtures import *
from workers.securityworker import index_images
def test_securityworker_realdb(initialized_db):
mock_analyzer = Mock()
assert index_images(1, mock_analyzer) is not None