Enables working only on one repo, compared to wildcards or all.
-e, --exact Only exact match repo name will be used.
If used, --repo parameter can not be empty
ISSUE: RELENG-2551
Signed-off-by: Bengt Thuree <bthuree@linuxfoundation.org>
Change-Id: I774d2b206305229af76d1e78570d09849b6c836f
'-r', '--repo', type=str, default='', required=False,
help='Only repos containing this string will be selected. '
'Default set to blank string, which is every repo.')
+@click.option(
+ '-e', '--exact', is_flag=True, required=False, default=False,
+ help='Match the exact repo name. '
+ 'If used, --repo parameter can not be empty.')
@click.option(
'-s', '--summary', is_flag=True, required=False,
help='Prints a summary of missing docker tags.')
'-v', '--verbose', is_flag=True, required=False,
help='Prints all collected repo/tag information.')
@click.option(
- '-c', '--copy', is_flag=True, required=False,
+ '-c', '--copy', is_flag=True, required=False, default=False,
help='Copy missing tags from Nexus3 repos to Docker Hub repos.')
@click.option(
'-p', '--progbar', is_flag=True, required=False, default=False,
help='Display a progress bar for the time consuming jobs.')
@click.pass_context
-def copy_from_nexus3_to_dockerhub(ctx, org, repo, summary, verbose, copy, progbar):
+def copy_from_nexus3_to_dockerhub(ctx, org, repo, exact, summary, verbose, copy, progbar):
"""Find missing repos in Docker Hub, Copy from Nexus3.
Will by default list all missing repos in Docker Hub, compared to Nexus3.
If -c (--copy) is provided, it will copy the repos from Nexus3 to Docker Hub.
"""
- rdh.start_point(org, repo, summary, verbose, copy, progbar)
+ rdh.start_point(org, repo, exact, summary, verbose, copy, progbar)
raise requests.HTTPError(retry_text)
-def get_nexus3_catalog(org_name='', find_pattern=''):
+def get_nexus3_catalog(org_name='', find_pattern='', exact_match=False):
"""Main function to collect all Nexus3 repositories.
This function will collect the Nexus catalog for all projects starting with
'org_name' as well as containing a pattern if specified.
+ If exact_match is specified, it will use the pattern as a unique repo name within the org_name.
If you do it manually, you give the following command.
curl -s https://nexus3.onap.org:10002/v2/_catalog
org_name : Organizational name, for instance 'onap'
find_pattern : A pattern, that if specified, needs to be part of the
repository name.
- for instance,
- '' : this pattern finds all repositories.
- 'eleo' : this pattern finds all repositories with 'eleo'
+ for instance,
+ '' : this pattern finds all repositories.
+ 'eleo' : this pattern finds all repositories with 'eleo'
in its name. --> chameleon
+ exact_match : If specified, find_pattern is a unique repo name
"""
global NexusCatalog
containing_str = ''
if len(find_pattern) > 0:
containing_str = ', and containing "{}"'.format(find_pattern)
+ if exact_match:
+ containing_str = ', and reponame = "{}"'.format(find_pattern)
info_str = "Collecting information from Nexus with projects with org = {}".format(org_name)
log.info("{}{}.".format(info_str, containing_str))
for word in TmpCatalog:
# Remove all projects that do not start with org_name
if word.startswith(org_name):
- # If a specific search string has been specified, searc = h for it
+ use_this_repo = False
+ # Remove org_name/ from word, so we only get repository left
+ project = (org_name, word[len(org_name)+1:])
+ # If a specific search string has been specified, search for it
# Empty string will match all words
- if word.find(find_pattern) >= 0:
- # Remove onap/ from word, so we only get repository left
- project = (org_name, word[len(org_name)+1:])
+ if word.find(find_pattern) >= 0 and not exact_match:
+ use_this_repo = True
+ if exact_match and project[1] == find_pattern:
+ use_this_repo = True
+ if use_this_repo:
NexusCatalog.append(project)
log.debug("Added project {} to my list".format(project[1]))
if len(project[1]) > project_max_len_chars:
log.info("Summary: {} tags that should be copied from Nexus3 to Docker Hub.".format(_tot_tags))
-def start_point(org_name, find_pattern='', summary=False,
+def start_point(org_name, find_pattern='', exact_match=False, summary=False,
verbose=False, copy=False, progbar=False):
"""Main function."""
+ # Verify find_pattern and specified_repo are not both used.
+ if len(find_pattern) == 0 and exact_match:
+ log.error("You need to provide a Pattern to go with the --exact flag")
+ return
initialize(org_name)
- if not get_nexus3_catalog(org_name, find_pattern):
+ if not get_nexus3_catalog(org_name, find_pattern, exact_match):
log.info("Could not get any catalog from Nexus3 with org = {}".format(org_name))
return
--- /dev/null
+---
+features:
+ - |
+ Added --exact to the releasedockerhub command. This enables
+ user to only work on a specific repo (specified by --repo)
rdh.get_nexus3_catalog ('onap', 'aaf')
assert len(rdh.NexusCatalog) == 18
+ def test_get_all_onap_and_specify_1_repo_1(self):
+ rdh.NexusCatalog = []
+ rdh.initialize ('onap')
+ responses.add(responses.GET, self.url, body=self.answer, status=200)
+ rdh.get_nexus3_catalog ('onap', 'clamp', True)
+ assert len(rdh.NexusCatalog) == 1
+ assert rdh.NexusCatalog[0][1] == 'clamp'
+
+ def test_get_all_onap_and_specify_1_repo_2(self):
+ rdh.NexusCatalog = []
+ rdh.initialize ('onap')
+ responses.add(responses.GET, self.url, body=self.answer, status=200)
+ rdh.get_nexus3_catalog ('onap', 'clamp-dashboard-logstash', True)
+ assert len(rdh.NexusCatalog) == 1
+ assert rdh.NexusCatalog[0][1] == 'clamp-dashboard-logstash'
+
class TestFetchAllTagsAndUpdate:
_test_image_long_id = 'sha256:3450464d68c9443dedc8bfe3272a23e6441c37f707c42d32fee0ebdbcd319d2c'
def test_start_no_copy(self, responses, mocker):
self.initiate_test_fetch(responses, mocker)
- rdh.start_point ('onap', '', False)
+ rdh.start_point ('onap', '', False, False)
assert self.counter.pull == 0
assert self.counter.tag == 0
assert self.counter.push == 0
def test_start_copy(self, responses, mocker):
self.initiate_test_fetch(responses, mocker)
- rdh.start_point ('onap', '', False, False, True)
+ rdh.start_point ('onap', '', False, False, False, True)
assert len(rdh.NexusCatalog) == 3
assert len(rdh.projects) == 3
assert len(rdh.projects[0].tags_2_copy.valid) == 1
def test_start_copy_repo(self, responses, mocker):
self.initiate_test_fetch(responses, mocker, 'sanity')
- rdh.start_point ('onap', 'sanity', False, False, True)
+ rdh.start_point ('onap', 'sanity', False, False, False, True)
assert len(rdh.NexusCatalog) == 1
assert len(rdh.projects) == 1
assert len(rdh.projects[0].tags_2_copy.valid) == 1