Simplify Nexus 2 repo target regex 55/9855/4
authorThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 9 Apr 2018 18:14:47 +0000 (14:14 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 30 Apr 2018 21:11:05 +0000 (17:11 -0400)
Add unit test to check real world artifact paths against the regex
pattern.

Issue: RELENG-758
Change-Id: I580fef69ef03d9cf85c59da250fdfee66fcb7ad5
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
lftools/nexus/cmd.py
lftools/nexus/util.py [new file with mode: 0644]
tests/test_nexus.py [new file with mode: 0644]

index cddac66..cecc8be 100644 (file)
@@ -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 (file)
index 0000000..6938b6e
--- /dev/null
@@ -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 (file)
index 0000000..0101731
--- /dev/null
@@ -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')