From f881931f8a8b2fb45179312ba05cf97b788770ff Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Mon, 9 Apr 2018 14:14:47 -0400 Subject: [PATCH] Simplify Nexus 2 repo target regex Add unit test to check real world artifact paths against the regex pattern. Issue: RELENG-758 Change-Id: I580fef69ef03d9cf85c59da250fdfee66fcb7ad5 Signed-off-by: Thanh Ha --- lftools/nexus/cmd.py | 8 ++++---- lftools/nexus/util.py | 22 ++++++++++++++++++++++ tests/test_nexus.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 lftools/nexus/util.py create mode 100644 tests/test_nexus.py diff --git a/lftools/nexus/cmd.py b/lftools/nexus/cmd.py index cddac66a..cecc8be0 100644 --- a/lftools/nexus/cmd.py +++ b/lftools/nexus/cmd.py @@ -16,6 +16,7 @@ import sys import yaml from lftools.nexus import Nexus +from lftools.nexus import util log = logging.getLogger(__name__) @@ -115,9 +116,8 @@ def create_repos(config_file, settings_file): def build_repo(repo, repoId, config, base_groupId): log.info('-> Building for {}.{} in Nexus'.format(base_groupId, repo)) - groupId = '%s.%s' % (base_groupId, repo) - target1 = '^/%s/.*' % groupId.replace('.', '[/\.]') - target2 = '^/%s[\.].*' % groupId.replace('.', '[/\.]') + groupId = '{}.{}'.format(base_groupId, repo) + target = util.create_repo_target_regex(groupId) if 'extra_privs' in config: extra_privs = config['extra_privs'] @@ -127,7 +127,7 @@ def create_repos(config_file, settings_file): create_nexus_perms( repoId, - [target1, target2], + [target], settings['email_domain'], config['password'], extra_privs) diff --git a/lftools/nexus/util.py b/lftools/nexus/util.py new file mode 100644 index 00000000..6938b6ec --- /dev/null +++ b/lftools/nexus/util.py @@ -0,0 +1,22 @@ +# -*- code: utf-8 -*- +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2018 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## +"""Utility functions for Nexus.""" + +__author__ = 'Thanh Ha' + +import logging + +log = logging.getLogger(__name__) + + +def create_repo_target_regex(group_id): + """Create a repo_target for Nexus use.""" + return '^/{}/.*'.format(group_id.replace('.', '[/\.]')) diff --git a/tests/test_nexus.py b/tests/test_nexus.py new file mode 100644 index 00000000..0101731f --- /dev/null +++ b/tests/test_nexus.py @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2018 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## +"""Test nexus command.""" + +import re + +import pytest + +from lftools.nexus import util + + +def test_create_repo_target_regex(): + """Test create_repo_target_regex() command.""" + + odlparent = util.create_repo_target_regex('org.opendaylight.odlparent') + odlparent_regex = re.compile(odlparent) + assert odlparent_regex.match( + '/org/opendaylight/odlparent/odlparent' + '/4.0.0-SNAPSHOT/odlparent-4.0.0-20180424.132124-69.pom' + ) + + honeycomb = util.create_repo_target_regex('org.opendaylight.honeycomb.vbd') + honeycomb_regex = re.compile(honeycomb) + assert honeycomb_regex.match( + '/org/opendaylight/honeycomb/vbd/odl-vbd' + '/1.4.0-SNAPSHOT/odl-vbd-1.4.0-20180422.024456-12-features.xml' + ) + + mso = util.create_repo_target_regex('org.openecomp.mso') + mso_regex = re.compile(mso) + assert mso_regex.match( + '/org/openecomp/mso/' + '1.1.0-SNAPSHOT/mso-1.1.0-20170606.171056-26.pom' + ) + + dcaegen2 = util.create_repo_target_regex('org.onap.dcaegen2') + dcaegen2_regex = re.compile(dcaegen2) + assert dcaegen2_regex.match( + '/org/onap/dcaegen2/' + '1.2.0-SNAPSHOT/dcaegen2-1.2.0-20180403.182529-10.pom' + ) + + vpp = util.create_repo_target_regex('io.fd.vpp') + vpp_regex = re.compile(vpp) + assert vpp_regex.match('/io/fd/vpp/jvpp/16.06/jvpp-16.06.jar') -- 2.16.6