Merge "Do not use RpcService in TPCE olm module"
authorChristophe BETOULE <christophe.betoule@orange.com>
Wed, 4 Oct 2023 07:11:17 +0000 (07:11 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 4 Oct 2023 07:11:17 +0000 (07:11 +0000)
tests/install_lightynode.sh
tests/requirements.txt
tests/transportpce_tests/common/test_utils.py
tests/transportpce_tests/tapi/test03_tapi_device_change_notifications.py
tox.ini

index 9634601095bcaeff41663369692170b7f59659e1..50102621db6348c9020576a6b03f675833c27dc8 100755 (executable)
@@ -13,7 +13,7 @@ if ! [ -x "$(command -v unzip)" ];then
     exit 1
 fi
 
-PLUGIN_VERSION=18.1.0.7
+PLUGIN_VERSION=18.1.0.8
 TARGET_DIR=$(dirname $0)/lightynode
 INSTALL_DIR=$TARGET_DIR/lightynode-openroadm-device
 ARTIFACT_ZIPFILE=$TARGET_DIR/artifact.zip
index 654a1fbbbccd4a350d2a6aa4d83698149186ba5b..a4e34096b842d548b82421bc3f3d37a973f7779b 100644 (file)
@@ -1,3 +1,5 @@
 psutil>=5.6.7 # 3-clause / New BSD License
 requests!=2.12.2,>=2.10.0 # Apache License 2.0
 netconf_client
+dict2xml
+
index 1b2b0179436da0ef46614fe574a10c782cc320dc..888a8e91fc228751b85ecd386c41bd49cd2f4537 100644 (file)
@@ -24,6 +24,10 @@ import psutil
 import requests
 import urllib.parse
 
+from dict2xml import dict2xml
+from netconf_client.connect import connect_ssh
+from netconf_client.ncclient import Manager
+
 # pylint: disable=import-error
 import simulators
 
@@ -86,6 +90,19 @@ if 'USE_LIGHTY' in os.environ and os.environ['USE_LIGHTY'] == 'True':
 else:
     TPCE_LOG = KARAF_LOG
 
+if 'USE_SIMS' not in os.environ:
+    SIMS_TO_USE = 'lightynode'
+    SIMS_TYPE = 'lightynode'
+else:
+    SIMS_TO_USE = os.environ['USE_SIMS']
+    print("Forcing to use SIMS " + SIMS_TO_USE)
+    if SIMS_TO_USE != 'None' or 'SIMS_TYPE' not in os.environ:
+        SIMS_TYPE = SIMS_TO_USE
+    else:
+        SIMS_TYPE = os.environ['SIMS_TYPE']
+        print("Forcing to use SIMS type" + SIMS_TYPE)
+
+
 #
 # Basic HTTP operations
 #
@@ -163,14 +180,9 @@ def start_lightynode(log_file: str, sim):
 
 
 def start_sims(sims_list):
-    if 'USE_SIMS' in os.environ:
-        sims_to_use = os.environ['USE_SIMS']
-        print("Using SIMS " + sims_to_use)
-    else:
-        sims_to_use = 'lightynode'
-    if sims_to_use == 'None':
+    if SIMS_TO_USE == 'None':
         return None
-    if sims_to_use == 'honeynode':
+    if SIMS_TO_USE == 'honeynode':
         start_msg = HONEYNODE_OK_START_MSG
         start_method = start_honeynode
     else:
@@ -261,34 +273,29 @@ def wait_until_log_contains(log_file, regexp, time_to_wait=60):
     # pylint: disable=lost-exception
     # pylint: disable=consider-using-with
     stringfound = False
-    filefound = False
     line = None
     try:
         with TimeOut(seconds=time_to_wait):
             while not os.path.exists(log_file):
                 time.sleep(0.2)
-            filelogs = open(log_file, 'r', encoding='utf-8')
-            filelogs.seek(0, 2)
-            filefound = True
-            print("Searching for pattern '" + regexp + "' in " + os.path.basename(log_file), end='... ', flush=True)
-            compiled_regexp = re.compile(regexp)
-            while True:
-                line = filelogs.readline()
-                if compiled_regexp.search(line):
-                    print('Pattern found!', end=' ')
-                    stringfound = True
-                    break
-                if not line:
-                    time.sleep(0.1)
+            with open(log_file, 'r', encoding='utf-8') as filelogs:
+                filelogs.seek(0, 2)
+                print("Searching for pattern '" + regexp + "' in " + os.path.basename(log_file), end='... ', flush=True)
+                compiled_regexp = re.compile(regexp)
+                while True:
+                    line = filelogs.readline()
+                    if compiled_regexp.search(line):
+                        print('Pattern found!', end=' ')
+                        stringfound = True
+                        break
+                    if not line:
+                        time.sleep(0.1)
+        return stringfound
     except TimeoutError:
         print('Pattern not found after ' + str(time_to_wait), end=' seconds! ', flush=True)
+        return stringfound
     except PermissionError:
         print('Permission Error when trying to access the log file', end=' ... ', flush=True)
-    finally:
-        if filefound:
-            filelogs.close()
-        else:
-            print('log file does not exist or is not accessible... ', flush=True)
         return stringfound
 
 
@@ -684,14 +691,20 @@ def transportpce_api_rpc_request(api_module: str, rpc: str, payload: dict):
 
 
 def sims_update_cp_port(sim: tuple, circuitpack: str, port: str, payload: dict):
+    if SIMS_TYPE == 'lightynode':
+        return sims_update_cp_port_ntcf(sim, circuitpack, payload)
+    if SIMS_TYPE == 'honeynode':
+        return sims_update_cp_port_rest(sim, circuitpack, port, payload)
+    return False
+
+
+def sims_update_cp_port_rest(sim: tuple, circuitpack: str, port: str, payload: dict):
     # pylint: disable=consider-using-f-string
     url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/{}/ports/{}".format(
         SIMS[sim]['restconf_baseurl'],
         urllib.parse.quote(circuitpack, safe=''),
         urllib.parse.quote(port, safe=''))
     body = {"ports": [payload]}
-    print(sim)
-    print(url)
     response = requests.request("PUT",
                                 url,
                                 data=json.dumps(body),
@@ -699,3 +712,19 @@ def sims_update_cp_port(sim: tuple, circuitpack: str, port: str, payload: dict):
                                 auth=(ODL_LOGIN, ODL_PWD),
                                 timeout=REQUEST_TIMEOUT)
     return response.status_code == requests.codes.ok
+
+
+def sims_update_cp_port_ntcf(sim: tuple, circuitpack: str, payload: dict):
+    body = {"circuit-packs": {"circuit-pack-name": circuitpack, "ports": payload}}
+    xml_body = '<config><org-openroadm-device xmlns="http://org/openroadm/device">'
+    xml_body += dict2xml(body, indent="  ")
+    xml_body += '</org-openroadm-device></config>'
+    with connect_ssh(host='127.0.0.1',
+                     port=int(SIMS[sim]['port']),
+                     username=NODES_LOGIN,
+                     password=NODES_PWD) as session:
+        mgr = Manager(session, timeout=120)
+        reply = mgr.edit_config(xml_body, target="candidate", default_operation="merge")
+    if "None" in str(reply):
+        return True
+    return False
index 8b589e0d8cb6aa496ea67d029e50646b9c690403..0e2626808a660d7d075dc75eaf37447295744ce2 100644 (file)
@@ -11,7 +11,6 @@
 # pylint: disable=no-member
 # pylint: disable=too-many-public-methods
 import os
-import json
 import unittest
 import time
 import requests
@@ -278,17 +277,13 @@ class TransportPCEFulltesting(unittest.TestCase):
         self.assertEqual(response['output']['service']['lifecycle-state'], 'INSTALLED')
 
     def test_14_change_status_line_port_xpdrc(self):
-        url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/1%2F0%2F1-PLUG-NET/ports/1"
-        body = {"ports": [{
+        self.assertTrue(test_utils.sims_update_cp_port(('xpdrc', self.NODE_VERSION_221), '1/0/1-PLUG-NET', '1',
+                                                       {
             "port-name": "1",
             "port-type": "CFP2",
             "administrative-state": "outOfService",
-            "port-qual": "xpdr-network"}]}
-        response = requests.request("PUT", url.format("http://127.0.0.1:8144/restconf"),
-                                    data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON,
-                                    auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD),
-                                    timeout=test_utils.REQUEST_TIMEOUT)
-        self.assertEqual(response.status_code, requests.codes.ok)
+            "port-qual": "xpdr-network"
+        }))
         time.sleep(2)
 
     def test_15_check_update_portmapping(self):
@@ -418,17 +413,13 @@ class TransportPCEFulltesting(unittest.TestCase):
         time.sleep(1)
 
     def test_21_restore_status_line_port_xpdrc(self):
-        url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/1%2F0%2F1-PLUG-NET/ports/1"
-        body = {"ports": [{
+        self.assertTrue(test_utils.sims_update_cp_port(('xpdrc', self.NODE_VERSION_221), '1/0/1-PLUG-NET', '1',
+                                                       {
             "port-name": "1",
             "port-type": "CFP2",
             "administrative-state": "inService",
-            "port-qual": "xpdr-network"}]}
-        response = requests.request("PUT", url.format("http://127.0.0.1:8144/restconf"),
-                                    data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON,
-                                    auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD),
-                                    timeout=test_utils.REQUEST_TIMEOUT)
-        self.assertEqual(response.status_code, requests.codes.ok)
+            "port-qual": "xpdr-network"
+        }))
         time.sleep(2)
 
     def test_22_check_update_portmapping_ok(self):
diff --git a/tox.ini b/tox.ini
index b515f85052eeef0184087ff6d3ded034ddbe79b8..1c3d9abf60064b2383c4f818b7bf81267b86bf3e 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -250,16 +250,16 @@ commands =
 
 [testenv:tests_tapi]
 depends = buildcontroller,build_karaf_tests221,sims221
-allowlist_externals = launch_tests.sh install_honeynode.sh
+allowlist_externals = launch_tests.sh
 #                      add_tapi_feature_to_tests221.sh
 passenv = LAUNCHER
     USE_LIGHTY
+    USE_SIMS
     NO_ODL_STARTUP
     OLM_TIMER1
     OLM_TIMER2
     USE_ODL_RESTCONF_VERSION
 setenv =
-    USE_SIMS=honeynode
 #    USE_LIGHTY=True
 #    USE_ODL_RESTCONF_VERSION=draft-bierman02
     USE_ODL_ALT_KARAF_ENV=./karaf221.env
@@ -269,7 +269,6 @@ setenv =
     OLM_TIMER2=2000
 
 commands =
-  ./install_honeynode.sh 2.2.1
 #  ./add_tapi_feature_to_tests221.sh
   ./launch_tests.sh tapi {posargs:}