Merge pull request #1441 from coreos-inc/fastesttests

Make security scan testing much faster
This commit is contained in:
josephschorr 2016-05-05 13:57:05 -04:00
commit d572a45a57
4 changed files with 13 additions and 5 deletions

View file

@ -170,7 +170,7 @@ def _torrent_repo_verb(repo_image, tag, verb, **kwargs):
abort(406)
# Lookup an *existing* derived storage for the verb. If the verb's image storage doesn't exist,
# we cannot create it here, so we 404.
# we cannot create it here, so we 406.
derived = model.image.find_derived_storage_for_image(repo_image, verb)
if not derived:
abort(406)

View file

@ -56,6 +56,9 @@ class FakeStorage(BaseStorageV2):
_FAKE_STORAGE_MAP.pop(path, None)
def exists(self, path):
if _FAKE_STORAGE_MAP.get('all_files_exist', None):
return True
return path in _FAKE_STORAGE_MAP
def get_checksum(self, path):

View file

@ -10,6 +10,7 @@ from util.secscan.api import SecurityScannerAPI, AnalyzeLayerException
from util.secscan.analyzer import LayerAnalyzer
from util.secscan.notifier import process_notification_data
from data import model
from storage.basestorage import StoragePaths
from workers.security_notification_worker import SecurityNotificationWorker
from endpoints.v2 import v2_bp
@ -116,9 +117,11 @@ class TestSecurityScanner(unittest.TestCase):
# Enable direct download in fake storage.
storage.put_content(['local_us'], 'supports_direct_download', 'true')
# Have fake storage say all files exist for the duration of the test.
storage.put_content(['local_us'], 'all_files_exist', 'true')
# Setup the database with fake storage.
force_rebuild = os.environ.get('SKIP_REBUILD') != 'true'
setup_database_for_testing(self, with_storage=True, force_rebuild=force_rebuild)
setup_database_for_testing(self)
self.app = app.test_client()
self.ctx = app.test_request_context()
self.ctx.__enter__()
@ -126,7 +129,9 @@ class TestSecurityScanner(unittest.TestCase):
self.api = SecurityScannerAPI(app, app.config, storage)
def tearDown(self):
storage.put_content(['local_us'], 'supports_direct_download', 'false')
storage.remove(['local_us'], 'supports_direct_download')
storage.remove(['local_us'], 'all_files_exist')
finished_database_for_testing(self)
self.ctx.__exit__(True, None, None)
@ -256,6 +261,7 @@ class TestSecurityScanner(unittest.TestCase):
path = model.storage.get_layer_path(layer.storage)
locations = app.config['DISTRIBUTED_STORAGE_PREFERENCE']
storage.remove(locations, path)
storage.remove(locations, 'all_files_exist')
with HTTMock(analyze_layer_success_mock, response_content):
analyzer = LayerAnalyzer(app.config, self.api)

View file

@ -59,7 +59,6 @@ class SecurityScannerAPI(object):
if not self._storage.exists(locations, path):
locations = get_storage_locations(image.storage.uuid)
if not locations or not self._storage.exists(locations, path):
logger.warning('Could not find a valid location to download layer %s.%s out of %s',
image.docker_image_id, image.storage.uuid, locations)