Merge pull request #2944 from coreos-inc/joseph.schorr/QS-91/v2-caching
V2 registry blob caching
This commit is contained in:
commit
024c183f67
14 changed files with 256 additions and 32 deletions
|
@ -15,6 +15,7 @@ from data.model.user import LoginWrappedDBUser
|
|||
from endpoints.api import api_bp
|
||||
from endpoints.appr import appr_bp
|
||||
from endpoints.web import web
|
||||
from endpoints.v2 import v2_bp
|
||||
from endpoints.verbs import verbs as verbs_bp
|
||||
|
||||
from initdb import initialize_database, populate_database
|
||||
|
@ -173,6 +174,7 @@ def app(appconfig, initialized_db):
|
|||
app.register_blueprint(appr_bp, url_prefix='/cnr')
|
||||
app.register_blueprint(web, url_prefix='/')
|
||||
app.register_blueprint(verbs_bp, url_prefix='/c1')
|
||||
app.register_blueprint(v2_bp, url_prefix='/v2')
|
||||
|
||||
app.config.update(appconfig)
|
||||
return app
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import binascii
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
|
@ -118,6 +119,19 @@ def addtoken():
|
|||
return 'OK'
|
||||
|
||||
|
||||
@testbp.route('/breakdatabase', methods=['POST'])
|
||||
def break_database():
|
||||
# Close any existing connection.
|
||||
close_db_filter(None)
|
||||
|
||||
# Reload the database config with an invalid connection.
|
||||
config = copy.copy(app.config)
|
||||
config['DB_URI'] = 'sqlite:///not/a/valid/database'
|
||||
configure(config)
|
||||
|
||||
return 'OK'
|
||||
|
||||
|
||||
@testbp.route('/reloadapp', methods=['POST'])
|
||||
def reload_app():
|
||||
# Close any existing connection.
|
||||
|
@ -1674,6 +1688,22 @@ class V2RegistryTests(V2RegistryPullMixin, V2RegistryPushMixin, RegistryTestsMix
|
|||
def test_cancel_push(self):
|
||||
self.do_push('devtable', 'newrepo', 'devtable', 'password', cancel=True)
|
||||
|
||||
def test_with_blob_caching(self):
|
||||
# Add a repository and do a pull, to prime the cache.
|
||||
_, manifests = self.do_push('devtable', 'newrepo', 'devtable', 'password')
|
||||
self.do_pull('devtable', 'newrepo', 'devtable', 'password')
|
||||
|
||||
# Purposefully break the database so that we can check if caching works.
|
||||
self.conduct('POST', '/__test/breakdatabase')
|
||||
|
||||
# Attempt to pull the blobs and ensure we get back a result. Since the database is broken,
|
||||
# this will only work if caching is working and no additional queries/connections are made.
|
||||
repo_name = 'devtable/newrepo'
|
||||
for tag_name in manifests:
|
||||
for layer in manifests[tag_name].layers:
|
||||
blob_id = str(layer.digest)
|
||||
self.conduct('GET', '/v2/%s/blobs/%s' % (repo_name, blob_id), expected_code=200, auth='jwt')
|
||||
|
||||
def test_pull_by_checksum(self):
|
||||
# Add a new repository under the user, so we have a real repository to pull.
|
||||
_, manifests = self.do_push('devtable', 'newrepo', 'devtable', 'password')
|
||||
|
|
Reference in a new issue