Allow tox tests with Karaf to run in parallel 79/96779/5
authorGuillaume Lambert <guillaume.lambert@orange.com>
Fri, 2 Jul 2021 13:24:57 +0000 (15:24 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Tue, 17 Aug 2021 23:05:44 +0000 (01:05 +0200)
- rework tox depends parameter to allow 2 instances of Karaf to be run
  in parallel
- modify buildcontroller process to add specific Karaf build folders
  for each test suite. Karaf instances are tighly coupled to their build
  folder. Using a separate log file is not enough to allow concurrent
  accesses to work properly.
- create an environment variable and adapt tests script accordingly

JIRA: TRNSPRTPCE-482
Signed-off-by: Guillaume Lambert <guillaume.lambert@orange.com>
Change-Id: I7fb608546beaaa19f0b046809c451303bd64c097

tests/transportpce_tests/common/test_utils.py
tox.ini

index 3bcd83d18afe3cfeea5faaeeed125c6eb7284184..64fb893903a42db0a17bd3f9f4a32f91793f4258 100644 (file)
@@ -59,9 +59,6 @@ CODE_SHOULD_BE_200 = 'Http status code should be 200'
 CODE_SHOULD_BE_201 = 'Http status code should be 201'
 
 SIM_LOG_DIRECTORY = os.path.join(os.path.dirname(os.path.realpath(__file__)), "log")
-KARAF_LOG = os.path.join(
-    os.path.dirname(os.path.realpath(__file__)),
-    "..", "..", "..", "karaf", "target", "assembly", "data", "log", "karaf.log")
 
 process_list = []
 
@@ -71,6 +68,15 @@ if "USE_ODL_ALT_RESTCONF_PORT" in os.environ:
 else:
     RESTCONF_BASE_URL = "http://localhost:8181/restconf"
 
+if "USE_ODL_ALT_KARAF_INSTALL_DIR" in os.environ:
+    KARAF_INSTALLDIR = os.environ['USE_ODL_ALT_KARAF_INSTALL_DIR']
+else:
+    KARAF_INSTALLDIR = "karaf"
+
+KARAF_LOG = os.path.join(
+    os.path.dirname(os.path.realpath(__file__)),
+    "..", "..", "..", KARAF_INSTALLDIR, "target", "assembly", "data", "log", "karaf.log")
+
 if "USE_LIGHTY" in os.environ and os.environ['USE_LIGHTY'] == 'True':
     TPCE_LOG = 'odl-' + str(os.getpid()) + '.log'
 else:
@@ -118,7 +124,7 @@ def start_karaf():
     print("starting KARAF TransportPCE build...")
     executable = os.path.join(
         os.path.dirname(os.path.realpath(__file__)),
-        "..", "..", "..", "karaf", "target", "assembly", "bin", "karaf")
+        "..", "..", "..", KARAF_INSTALLDIR, "target", "assembly", "bin", "karaf")
     with open('odl.log', 'w') as outfile:
         return subprocess.Popen(
             ["sh", executable, "server"], stdout=outfile, stderr=outfile, stdin=None)
@@ -139,7 +145,7 @@ def install_karaf_feature(feature_name: str):
     print("installing feature " + feature_name)
     executable = os.path.join(
         os.path.dirname(os.path.realpath(__file__)),
-        "..", "..", "..", "karaf", "target", "assembly", "bin", "client")
+        "..", "..", "..", KARAF_INSTALLDIR, "target", "assembly", "bin", "client")
     return subprocess.run([executable],
                           input='feature:install ' + feature_name + '\n feature:list | grep '
                           + feature_name + ' \n logout \n',
diff --git a/tox.ini b/tox.ini
index 4b469529907a1bd8b91b3bcde3098e1d980dfd5b..eada9910096a6ca402f73f59950a38f17582f6d3 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -31,11 +31,13 @@ commands =
 #install honeynode 1.2.1 simulators
 #patch OLM constant to speed up tests, unnecessary for PCE tests
   sh -c "sed -i'_' 's@=.*//#FUNCTESTVAL=@=@g' ../olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java"
+  sh -c 'if [ "$USE_LIGHTY" != "True" ]; then (cd ../; for suffix in 121 221 71; do rm -rf "karaf$suffix"; cp -r karaf "karaf$suffix";done) ; fi'
 #build controller, source JDK_JAVA_OPTIONS to remove illegal reflective acces warnings introduced by Java11
   sh -c ". $PWD/reflectwarn.sh && cd .. && mvn clean install -B -q -s tests/odl_settings.xml -DskipTests -Dmaven.javadoc.skip=true -Dodlparent.spotbugs.skip -Dodlparent.checkstyle.skip"
   sh -c "mv  ../olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java_  ../olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java"
 #patch Karaf exec for the same reason at runtime and also to have the possibility to use alternative ports
   sh -c "../karaf/target/assembly/ressources/post_install_for_tests.sh"
+  sh -c 'if [ "$USE_LIGHTY" != "True" ]; then . $PWD/reflectwarn.sh && (for suffix in 121 221 71; do cd  ../"karaf$suffix"/; mvn clean install -B -q -s ../tests/odl_settings.xml -DskipTests -Dmaven.javadoc.skip=true; ./target/assembly/ressources/post_install_for_tests.sh;done) ; fi'
 #build Lighty if needed
   sh -c 'if [ "$USE_LIGHTY" = "True" ]; then (cd ../lighty && ./build.sh); fi'
 
@@ -80,6 +82,7 @@ setenv =
     USE_ODL_ALT_RMI_REGISTRY_PORT=1100
     USE_ODL_ALT_RMI_SERVER_PORT=44445
     USE_ODL_ALT_RESTCONF_PORT=8182
+    USE_ODL_ALT_KARAF_INSTALL_DIR=karaf121
 commands =
   ./launch_tests.sh 1.2.1 {posargs:}
 # By default, all tests in the folder transportpce_tests/1.2.1/ are run.
@@ -92,7 +95,7 @@ commands =
 # files attributes.
 
 [testenv:tests221]
-depends = buildcontroller,sims221,tests121
+depends = buildcontroller,sims221,tests71
 # tests71 dependency is only here to chain tests in the gate and avoid ressources starvation
 whitelist_externals = launch_tests.sh
 passenv = LAUNCHER
@@ -105,11 +108,12 @@ setenv =
     USE_ODL_ALT_RMI_REGISTRY_PORT=1101
     USE_ODL_ALT_RMI_SERVER_PORT=44446
     USE_ODL_ALT_RESTCONF_PORT=8183
+    USE_ODL_ALT_KARAF_INSTALL_DIR=karaf221
 commands =
   ./launch_tests.sh 2.2.1 {posargs:}
 
 [testenv:tests71]
-depends = buildcontroller,sims71,tests221
+depends = buildcontroller,sims71
 whitelist_externals = launch_tests.sh
 passenv = LAUNCHER
 setenv =
@@ -121,6 +125,7 @@ setenv =
     USE_ODL_ALT_RMI_REGISTRY_PORT=1102
     USE_ODL_ALT_RMI_SERVER_PORT=44447
     USE_ODL_ALT_RESTCONF_PORT=8184
+    USE_ODL_ALT_KARAF_INSTALL_DIR=karaf71
 commands =
   ./launch_tests.sh 7.1 {posargs:}