Add lightynode support to testutils.py 10/107710/6
authorguillaume.lambert <guillaume.lambert@orange.com>
Tue, 5 Sep 2023 10:10:57 +0000 (12:10 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Wed, 6 Sep 2023 12:14:09 +0000 (14:14 +0200)
- add netconf_client dependency necessary for several tests
- add an installation shell script for lighty_node
- use sed in lightynode and hondenynoe install scripts to deal
  with 1.2.1 sample configs typo issue
- add an environment variable to configure a choice
  among lighty / honeycomb / no simulator
- update tox.ini consequently

JIRA: TRNSPRTPCE-754
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Co-authored-by: Christophe Betoule <christophe.betoule@orange.com>
Change-Id: I167b40dd3a1d9bd89cc472fa80899ba730f99c6a

tests/install_honeynode.sh
tests/install_lightynode.sh [new file with mode: 0755]
tests/lightynode/.gitkeep [new file with mode: 0644]
tests/requirements.txt
tests/transportpce_tests/common/test_utils.py
tox.ini

index 7b7c0b5d80741a5eda5a6f7c0a77f9712c0fae0f..a4c21ba1b1fef4761d2f3325fff5618c1a2daeff 100755 (executable)
@@ -19,6 +19,9 @@ for VERSION in $VERSIONS_LIST
 do
     case "$VERSION" in
         "1.2.1") PLUGIN_VERSION=1.0.9
+        #update 1.2.1 openroadm device configuration samples to be compliant with honeynode
+        #device models ("multi-wavelegnth" instead of "multi-wavelength" whose typo has been solved with 2.2.1 device models)
+        sed -i_ 's/multi-wavelegnth/multi-wavelength/g' $(dirname $0)/sample_configs/openroadm/1.2.1/oper-ROADM*.xml
         ;;
         "2.2.1") PLUGIN_VERSION=2.0.10
         ;;
diff --git a/tests/install_lightynode.sh b/tests/install_lightynode.sh
new file mode 100755 (executable)
index 0000000..9634601
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+#set -x
+
+#check if curl exists
+if ! [ -x "$(command -v curl)" ];then
+    echo "curl is not installed." >&2
+    exit 1
+fi
+#check if unzip exists
+if ! [ -x "$(command -v unzip)" ];then
+    echo "unzip is not installed." >&2
+    exit 1
+fi
+
+PLUGIN_VERSION=18.1.0.7
+TARGET_DIR=$(dirname $0)/lightynode
+INSTALL_DIR=$TARGET_DIR/lightynode-openroadm-device
+ARTIFACT_ZIPFILE=$TARGET_DIR/artifact.zip
+TARGET_URL="https://gitlab.com/api/v4/projects/36076125/packages/maven/io/lighty/transportpce/netconf/device/lighty-openroadm-device/$PLUGIN_VERSION/lighty-openroadm-device-$PLUGIN_VERSION-bin.zip"
+
+#clean lightynode install directory
+if [ -d "$INSTALL_DIR" ];then
+    echo "Removing $INSTALL_DIR directory"
+    rm -rf $INSTALL_DIR
+fi
+
+#download lightynode  and install it
+#complete source code can be found at https://gitlab.com/Orange-OpenSource/lfn/odl/lightynode-simulator.git
+echo "Installing lightynode device to $INSTALL_DIR directory "
+curl --retry-delay 10 --retry 3 -sS --location --request GET $TARGET_URL -o $ARTIFACT_ZIPFILE || exit 2
+unzip -q $ARTIFACT_ZIPFILE -d $TARGET_DIR
+rm -f $ARTIFACT_ZIPFILE
+mv $TARGET_DIR/lighty-openroadm-device-$PLUGIN_VERSION $INSTALL_DIR
+
+#update 1.2.1 openroadm device configuration samples to be compliant with 1.2.1
+#device models ("multi-wavelegnth" instead of "multi-wavelength" whose typo has been solved with 2.2.1 device models)
+sed -i_ 's/multi-wavelength/multi-wavelegnth/g' $(dirname $0)/sample_configs/openroadm/1.2.1/oper-ROADM*.xml
diff --git a/tests/lightynode/.gitkeep b/tests/lightynode/.gitkeep
new file mode 100644 (file)
index 0000000..e69de29
index 5ebd5e2e7e5284c53e9b5ce37a494f002859846c..654a1fbbbccd4a350d2a6aa4d83698149186ba5b 100644 (file)
@@ -1,2 +1,3 @@
 psutil>=5.6.7 # 3-clause / New BSD License
 requests!=2.12.2,>=2.10.0 # Apache License 2.0
+netconf_client
index 4911c2a3ff9d10595d78548afb5742ec2aaf65dc..0ee48c2587e6f8a94b3efea998496dc29a539737 100644 (file)
@@ -29,6 +29,7 @@ import simulators
 SIMS = simulators.SIMS
 
 HONEYNODE_OK_START_MSG = 'Netconf SSH endpoint started successfully at 0.0.0.0'
+LIGHTYNODE_OK_START_MSG = 'Data tree change listeners registered'
 KARAF_OK_START_MSG = "Transportpce controller started"
 LIGHTY_OK_START_MSG = re.escape("lighty.io and RESTCONF-NETCONF started")
 
@@ -133,12 +134,53 @@ def post_request(url, data):
 #
 
 
+def start_honeynode(log_file: str, sim):
+    executable = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                              '..', '..', 'honeynode', sim[1], 'honeynode-simulator', 'honeycomb-tpce')
+    sample_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                                    '..', '..', 'sample_configs', 'openroadm', sim[1])
+    if os.path.isfile(executable):
+        with open(log_file, 'w', encoding='utf-8') as outfile:
+            return subprocess.Popen(
+                [executable, SIMS[sim]['port'], os.path.join(sample_directory, SIMS[sim]['configfile'])],
+                stdout=outfile, stderr=outfile)
+    return None
+
+
+def start_lightynode(log_file: str, sim):
+    executable = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                              '..', '..', 'lightynode', 'lightynode-openroadm-device', 'start-device.sh')
+    sample_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                                    '..', '..', 'sample_configs', 'openroadm', sim[1])
+    if os.path.isfile(executable):
+        with open(log_file, 'w', encoding='utf-8') as outfile:
+            return subprocess.Popen(
+                [executable, "-v" + sim[1], "-p" + SIMS[sim]['port'], "-f" + os.path.join(sample_directory,
+                                                                                          SIMS[sim]['configfile'])],
+                stdout=outfile, stderr=outfile)
+    return None
+
+
 def start_sims(sims_list):
+    if 'USE_SIMS' in os.environ:
+        sims_to_use = os.environ['USE_SIMS']
+        print(os.environ['USE_SIMS'] + ' ' + sims_to_use)
+    else:
+        sims_to_use = 'honeynode'
+    if sims_to_use == 'None':
+        return None
+    if sims_to_use == 'lightynode':
+        start_msg = LIGHTYNODE_OK_START_MSG
+        start_method = start_lightynode
+        print("lightynode used")
+    else:
+        start_msg = HONEYNODE_OK_START_MSG
+        start_method = start_honeynode
     for sim in sims_list:
         print('starting simulator ' + sim[0] + ' in OpenROADM device version ' + sim[1] + '...')
         log_file = os.path.join(SIM_LOG_DIRECTORY, SIMS[sim]['logfile'])
-        process = start_honeynode(log_file, sim)
-        if wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 100):
+        process = start_method(log_file, sim)
+        if wait_until_log_contains(log_file, start_msg, 100):
             print('simulator for ' + sim[0] + ' started')
         else:
             print('simulator for ' + sim[0] + ' failed to start')
@@ -215,19 +257,6 @@ def shutdown_process(process):
         process.send_signal(signal.SIGINT)
 
 
-def start_honeynode(log_file: str, sim):
-    executable = os.path.join(os.path.dirname(os.path.realpath(__file__)),
-                              '..', '..', 'honeynode', sim[1], 'honeynode-simulator', 'honeycomb-tpce')
-    sample_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),
-                                    '..', '..', 'sample_configs', 'openroadm', sim[1])
-    if os.path.isfile(executable):
-        with open(log_file, 'w', encoding='utf-8') as outfile:
-            return subprocess.Popen(
-                [executable, SIMS[sim]['port'], os.path.join(sample_directory, SIMS[sim]['configfile'])],
-                stdout=outfile, stderr=outfile)
-    return None
-
-
 def wait_until_log_contains(log_file, regexp, time_to_wait=60):
     # pylint: disable=lost-exception
     # pylint: disable=consider-using-with
diff --git a/tox.ini b/tox.ini
index 98bde2aef98add84001c88d0825a485a7a88686e..df7ce3b8ac6fd3f3c3a2e01877862aeed0dad409 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -26,6 +26,7 @@ setupdir = tests/
 [testenv]
 passenv = LAUNCHER
      USE_LIGHTY
+     USE_SIMS
      NO_ODL_STARTUP
      http_proxy
      HTTP_PROXY
@@ -120,7 +121,7 @@ depends = buildcontroller,build_karaf_tests121,sims121,testsPCE
 allowlist_externals = launch_tests.sh
 passenv = LAUNCHER
     USE_LIGHTY
-    NO_ODL_STARTUP
+    USE_SIMS
     USE_ODL_RESTCONF_VERSION
 setenv =
 #    USE_LIGHTY=True
@@ -173,6 +174,7 @@ depends = buildcontroller,build_karaf_tests221,sims221,tests71
 allowlist_externals = launch_tests.sh
 passenv = LAUNCHER
     USE_LIGHTY
+    USE_SIMS
     NO_ODL_STARTUP
     USE_ODL_RESTCONF_VERSION
 setenv =
@@ -200,6 +202,7 @@ depends = buildcontroller,build_karaf_tests71,sims71,tests_tapi
 allowlist_externals = launch_tests.sh
 passenv = LAUNCHER
     USE_LIGHTY
+    USE_SIMS
     NO_ODL_STARTUP
     USE_ODL_RESTCONF_VERSION
 setenv =
@@ -227,6 +230,7 @@ depends = buildcontroller,build_karaf_tests_hybrid,sims121,sims221,sims71,tests1
 allowlist_externals = launch_tests.sh
 passenv = LAUNCHER
     USE_LIGHTY
+    USE_SIMS
     NO_ODL_STARTUP
     USE_ODL_RESTCONF_VERSION
 setenv =
@@ -243,6 +247,7 @@ depends = buildcontroller,build_karaf_tests221,sims221
 allowlist_externals = launch_tests.sh add_tapi_feature_to_tests221.sh
 passenv = LAUNCHER
     USE_LIGHTY
+    USE_SIMS
     NO_ODL_STARTUP
     OLM_TIMER1
     OLM_TIMER2
@@ -266,6 +271,7 @@ allowlist_externals = launch_tests.sh
                       dockercmd.sh
 passenv = LAUNCHER
     USE_LIGHTY
+    USE_SIMS
     NO_ODL_STARTUP
     USE_ODL_RESTCONF_VERSION
 #    OLM_TIMER1