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', unscanned_images_gauge = prometheus.create_gauge('unscanned_images',
'Number of images that clair needs to scan.') 'Number of images that clair needs to scan.')
def index_images(target_version, analyzer, token=None): def index_images(target_version, analyzer, token=None):
""" Performs security indexing of all images in the database not scanned at the target version. """ 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. 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 from six import add_metaclass
class ScanToken(namedtuple('NextScanToken', ['min_id'])): class ScanToken(namedtuple('NextScanToken', ['min_id'])):
""" """
ScanToken represents an opaque token that can be passed between runs of the security worker 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. the token in any way.
""" """
@add_metaclass(ABCMeta) @add_metaclass(ABCMeta)
class SecurityWorkerDataInterface(object): 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) get_max_id_for_sec_scan, get_min_id_for_sec_scan)
from util.migrate.allocator import yield_random_entries from util.migrate.allocator import yield_random_entries
from workers.securityworker.models_interface import ( from workers.securityworker.models_interface import (ScanToken, SecurityWorkerDataInterface)
ScanToken,
SecurityWorkerDataInterface
)
class PreOCIModel(SecurityWorkerDataInterface): class PreOCIModel(SecurityWorkerDataInterface):
def candidates_to_scan(self, target_version, start_token=None): def candidates_to_scan(self, target_version, start_token=None):
@ -34,7 +32,7 @@ class PreOCIModel(SecurityWorkerDataInterface):
return (None, None) return (None, None)
# 4^log10(total) gives us a scalable batch size into the billions. # 4^log10(total) gives us a scalable batch size into the billions.
batch_size = int(4 ** log10(max(10, max_id - min_id))) batch_size = int(4**log10(max(10, max_id - min_id)))
# TODO: Once we have a clean shared NamedTuple for Images, send that to the secscan analyzer # TODO: Once we have a clean shared NamedTuple for Images, send that to the secscan analyzer
# rather than the database Image itself. # rather than the database Image itself.
@ -43,8 +41,7 @@ class PreOCIModel(SecurityWorkerDataInterface):
get_image_pk_field(), get_image_pk_field(),
batch_size, batch_size,
max_id, max_id,
min_id, min_id,)
)
return (iterator, ScanToken(max_id + 1)) return (iterator, ScanToken(max_id + 1))

View file

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

View file

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