Allow tox tests with Karaf to run in parallel 34/98234/2
authorGuillaume Lambert <guillaume.lambert@orange.com>
Fri, 2 Jul 2021 13:24:57 +0000 (15:24 +0200)
committerVachhani, Shweta (sv111y) <sv111y@att.com>
Sun, 31 Oct 2021 11:28:35 +0000 (07:28 -0400)
- 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 2b4c7f28cdceb3d82baec9259656b019bb518786..a525eb702f3d355a9e8298ae52b3c357ba9e98eb 100644 (file)
@@ -58,9 +58,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 = []
 
@@ -70,6 +67,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:
@@ -117,7 +123,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)
@@ -138,7 +144,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 9372d6b3b2e78bd45da83dda921f50ac2049a047..20feaf9ec37ec0a0b86153b7a12420a7d61f6cc7 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:}