From 27ed3bedcca92419f580bf9909bf9b4e53627eae Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 29 Jun 2017 09:43:04 +0300 Subject: [PATCH] yapf --- workers/securityworker/__init__.py | 1 + workers/securityworker/models_interface.py | 2 ++ workers/securityworker/models_pre_oci.py | 11 ++++------- workers/securityworker/securityworker.py | 1 + workers/securityworker/test/test_securityworker.py | 1 + 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/workers/securityworker/__init__.py b/workers/securityworker/__init__.py index a101f6795..8c2bc44a7 100644 --- a/workers/securityworker/__init__.py +++ b/workers/securityworker/__init__.py @@ -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. diff --git a/workers/securityworker/models_interface.py b/workers/securityworker/models_interface.py index 6d872ca4e..76295a427 100644 --- a/workers/securityworker/models_interface.py +++ b/workers/securityworker/models_interface.py @@ -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): """ diff --git a/workers/securityworker/models_pre_oci.py b/workers/securityworker/models_pre_oci.py index a665cac17..0115be908 100644 --- a/workers/securityworker/models_pre_oci.py +++ b/workers/securityworker/models_pre_oci.py @@ -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): @@ -34,7 +32,7 @@ class PreOCIModel(SecurityWorkerDataInterface): return (None, None) # 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 # rather than the database Image itself. @@ -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)) diff --git a/workers/securityworker/securityworker.py b/workers/securityworker/securityworker.py index 732631e3a..1038e7a04 100644 --- a/workers/securityworker/securityworker.py +++ b/workers/securityworker/securityworker.py @@ -15,6 +15,7 @@ logger = logging.getLogger(__name__) DEFAULT_INDEXING_INTERVAL = 30 + class SecurityWorker(Worker): def __init__(self): super(SecurityWorker, self).__init__() diff --git a/workers/securityworker/test/test_securityworker.py b/workers/securityworker/test/test_securityworker.py index 4b52f8def..dfa9ff490 100644 --- a/workers/securityworker/test/test_securityworker.py +++ b/workers/securityworker/test/test_securityworker.py @@ -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