Switch V2 pagination back to using IDs, which should be much faster and easier on the DB
Also adds a test for the tags endpoint
This commit is contained in:
parent
b8b2c75822
commit
3161b60522
7 changed files with 105 additions and 31 deletions
|
@ -347,6 +347,48 @@ class V2Protocol(RegistryProtocol):
|
|||
return PullResult(manifests=manifests, image_ids=image_ids)
|
||||
|
||||
|
||||
def tags(self, session, namespace, repo_name, page_size=2, credentials=None, options=None,
|
||||
expected_failure=None):
|
||||
options = options or ProtocolOptions()
|
||||
scopes = options.scopes or ['repository:%s:pull' % self.repo_name(namespace, repo_name)]
|
||||
|
||||
# Ping!
|
||||
self.ping(session)
|
||||
|
||||
# Perform auth and retrieve a token.
|
||||
headers = {}
|
||||
if credentials is not None:
|
||||
token, _ = self.auth(session, credentials, namespace, repo_name, scopes=scopes,
|
||||
expected_failure=expected_failure)
|
||||
if token is None:
|
||||
return None
|
||||
|
||||
headers = {
|
||||
'Authorization': 'Bearer ' + token,
|
||||
}
|
||||
|
||||
results = []
|
||||
url = '/v2/%s/tags/list' % (self.repo_name(namespace, repo_name))
|
||||
params = {}
|
||||
if page_size is not None:
|
||||
params['n'] = page_size
|
||||
|
||||
while True:
|
||||
response = self.conduct(session, 'GET', url, headers=headers, params=params)
|
||||
data = response.json()
|
||||
|
||||
assert len(data['tags']) <= page_size
|
||||
results.extend(data['tags'])
|
||||
|
||||
if not response.headers.get('Link'):
|
||||
return results
|
||||
|
||||
link_url = response.headers['Link']
|
||||
v2_index = link_url.find('/v2/')
|
||||
url = link_url[v2_index:]
|
||||
|
||||
return results
|
||||
|
||||
def catalog(self, session, page_size=2, credentials=None, options=None, expected_failure=None,
|
||||
namespace=None, repo_name=None):
|
||||
options = options or ProtocolOptions()
|
||||
|
|
|
@ -16,6 +16,7 @@ from test.registry.protocol_fixtures import *
|
|||
from test.registry.protocols import Failures, Image, layer_bytes_for_contents, ProtocolOptions
|
||||
|
||||
from app import instance_keys
|
||||
from data.model.tag import list_repository_tags
|
||||
from util.security.registry_jwt import decode_bearer_header
|
||||
from util.timedeltastring import convert_to_timedelta
|
||||
|
||||
|
@ -718,6 +719,31 @@ def test_catalog(public_catalog, credentials, expected_repos, page_size, v2_prot
|
|||
assert set(expected_repos).issubset(set(results))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('username, namespace, repository', [
|
||||
('devtable', 'devtable', 'simple'),
|
||||
('devtable', 'devtable', 'gargantuan'),
|
||||
('public', 'public', 'publicrepo'),
|
||||
('devtable', 'buynlarge', 'orgrepo'),
|
||||
])
|
||||
@pytest.mark.parametrize('page_size', [
|
||||
1,
|
||||
2,
|
||||
10,
|
||||
50,
|
||||
100,
|
||||
])
|
||||
def test_tags(username, namespace, repository, page_size, v2_protocol, liveserver_session,
|
||||
app_reloader, liveserver, registry_server_executor):
|
||||
""" Test: Retrieving results from the V2 catalog. """
|
||||
credentials = (username, 'password')
|
||||
results = v2_protocol.tags(liveserver_session, page_size=page_size, credentials=credentials,
|
||||
namespace=namespace, repo_name=repository)
|
||||
|
||||
expected_tags = [tag.name for tag in list_repository_tags(namespace, repository)]
|
||||
assert len(results) == len(expected_tags)
|
||||
assert set([r for r in results]) == set(expected_tags)
|
||||
|
||||
|
||||
def test_pull_torrent(pusher, basic_images, liveserver_session, liveserver,
|
||||
registry_server_executor, app_reloader):
|
||||
""" Test: Retrieve a torrent for pulling the image via the Quay CLI. """
|
||||
|
|
Reference in a new issue