Fix bgpcep-1node-throughpcep 42/102242/6
authorSangwook Ha <sangwook.ha@verizon.com>
Mon, 29 Aug 2022 16:19:26 +0000 (09:19 -0700)
committerSangwook Ha <sangwook.ha@verizon.com>
Mon, 29 Aug 2022 21:26:49 +0000 (14:26 -0700)
Update Python script 'updater.py' to make it compatible with Python 3,
and replace RESTCONF draft URLs & data with the ones for RFC8040.

Change-Id: I6863f5454149d23d5a21b349a1ecfde443eaf3e3
Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
csit/libraries/AuthStandalone.py
csit/suites/bgpcep/throughpcep/cases.robot
tools/pcep_updater/updater.py

index 5cb840a4f9054b38e7fc23a12d9cddac7140fd63..6e766a1e05ef6e68f1ce8dd4ab1e456a2d0ba70d 100644 (file)
@@ -87,7 +87,7 @@ class _BasicReusingSession(object):
 
     def __init__(self, ip, username="", password="", port="8181"):
         """Initialize session using hardcoded text data, remember credentials."""
-        self.rest_prefix = "http://" + ip + ":" + port + "/restconf/"
+        self.rest_prefix = "http://" + ip + ":" + port + "/rests/"
         self.session = requests.Session()
         if username:
             self.session.auth = (username, password)  # May work with non-string values
@@ -107,7 +107,7 @@ class _BasicClosingSession(object):
 
     def __init__(self, ip, username="", password="", port="8181"):
         """Prepare session initialization data using hardcoded text, remember credentials."""
-        self.rest_prefix = "http://" + ip + ":" + port + "/restconf/"
+        self.rest_prefix = "http://" + ip + ":" + port + "/rests/"
         if username:
             self.auth = (username, password)  # May work with non-string values
         else:
@@ -135,7 +135,7 @@ class _TokenReusingSession(object):
     def __init__(self, ip, username, password, scope, port="8181"):
         """Initialize session using hardcoded text data."""
         self.auth_url = "http://" + ip + ":" + port + "/oauth2/token"
-        self.rest_prefix = "http://" + ip + ":" + port + "/restconf/"
+        self.rest_prefix = "http://" + ip + ":" + port + "/rests/"
         self.auth_data = "grant_type=password&username=" + username
         self.auth_data += "&password=" + password + "&scope=" + scope
         self.auth_header = {"Content-Type": "application/x-www-form-urlencoded"}
@@ -184,7 +184,7 @@ class _TokenClosingSession(object):
     def __init__(self, ip, username, password, scope, port="8181"):
         """Prepare session initialization data using hardcoded text."""
         self.auth_url = "http://" + ip + ":" + port + "/oauth2/token"
-        self.rest_prefix = "http://" + ip + ":" + port + "/restconf/"
+        self.rest_prefix = "http://" + ip + ":" + port + "/rests/"
         self.auth_data = "grant_type=password&username=" + username
         self.auth_data += "&password=" + password + "&scope=" + scope
         self.auth_header = {"Content-Type": "application/x-www-form-urlencoded"}
index 4df50a7b1a6347f87e9bb8573d1970907f03b166..0ce72d0a01a68e9332c8f9bbd2fbedaa872c4a25 100644 (file)
@@ -460,7 +460,7 @@ Disconnect
 
 Get_Pcep_Topology_Data
     [Documentation]    Use session object to download PCEP topology JSON. Check status and return Response object.
-    ${resp} =    AuthStandalone.Get_Using_Session    ${rest_session}    operational/network-topology:network-topology/topology/pcep-topology
+    ${resp} =    AuthStandalone.Get_Using_Session    ${rest_session}    data/${TOPOLOGY_URL}\=pcep-topology?content\=nonconfig
     # Not Logging content, as it may be huge.
     BuiltIn.Should_Be_Equal    ${resp.status_code}    ${200}
     [Return]    ${resp}
@@ -479,7 +479,7 @@ Pcep_Off
     ${resp} =    Get_Pcep_Topology_Data
     # Used before topology had chance to grow huge. Be aware when creating a longevity suite from this.
     BuiltIn.Log    ${resp.text}
-    BuiltIn.Should_Be_Equal    ${resp.text}    {"topology":[{"topology-id":"pcep-topology","topology-types":{"network-topology-pcep:topology-pcep":{}}}]}
+    BuiltIn.Should_Be_Equal    ${resp.text}    {"network-topology:topology":[{"topology-id":"pcep-topology","topology-types":{"network-topology-pcep:topology-pcep":{}}}]}
 
 Pcep_On
     [Documentation]    Get topology count of current hop, assert the number of matches.
@@ -512,7 +512,7 @@ Updater
     # The previous line relies on a fact that Execute_Command spawns separate shels, so running pcc-mock is not affected.
     Set_Hop    ${iteration}
     SSHLibrary.Switch_Connection    updater
-    ${response} =    SSHLibrary.Execute_Command    bash -c "cd ${UPDATERVM_WORKSPACE}; taskset 0x00000001 python updater.py --workers '${workers}' --odladdress '${UPDATER_ODLADDRESS}' --user '${RESTCONF_USER}' --password '${RESTCONF_PASSWORD}' --scope '${RESTCONF_SCOPE}' --pccaddress '${mock-ip}' --pccs '${pccs}' --lsps '${lsps}' --hop '${hop}' --timeout '${UPDATER_TIMEOUT}' --refresh '${UPDATER_REFRESH}' --reuse '${RESTCONF_REUSE}' --delegate '${delegate}' --pccip '${pccip}' --tunnelnumber '${tunnel_no}' 2>&1"
+    ${response} =    SSHLibrary.Execute_Command    bash -c "cd ${UPDATERVM_WORKSPACE}; taskset 0x00000001 python3 updater.py --workers '${workers}' --odladdress '${UPDATER_ODLADDRESS}' --user '${RESTCONF_USER}' --password '${RESTCONF_PASSWORD}' --scope '${RESTCONF_SCOPE}' --pccaddress '${mock-ip}' --pccs '${pccs}' --lsps '${lsps}' --hop '${hop}' --timeout '${UPDATER_TIMEOUT}' --refresh '${UPDATER_REFRESH}' --reuse '${RESTCONF_REUSE}' --delegate '${delegate}' --pccip '${pccip}' --tunnelnumber '${tunnel_no}' 2>&1"
     Check Updater response    ${response}    ${parallel}
 
 Check Updater response
index aafed26b56982064aeab1834b9a6bba2ccd9c6a0..51af19be3093ab19f3fee6e3b301a5d366f3b3c6 100644 (file)
@@ -37,10 +37,7 @@ import ipaddr
 import threading
 import time
 
-try:
-    from collections import Counter
-except ImportError:  # Python 2.6 does not have Counter in collections.
-    from Counter import Counter  # Assumes that user copies Counter.py around.
+from collections import Counter
 import AuthStandalone
 
 
@@ -225,8 +222,8 @@ def queued_send(session, queue_messages, queue_responses):
         # The response perhaps points to some data stored in session,
         # and the session implementation may explicitly call close() to free that data.
         # To be sure, we clone information before further processing.
-        status = int(response.status_code)  # copy constructor
-        content = str(response.content)  # copy constructor
+        status = int(response.status_code)
+        content = response.content.decode()
         resp_tuple = (status, content)
         queue_responses.append(resp_tuple)
 
@@ -235,11 +232,11 @@ def classify(resp_tuple):
     """Return 'pass' or a reason what is wrong with response."""
     prepend = ""
     status = resp_tuple[0]
-    if (status != 200) and (status != 204):  # is it int?
-        prepend = "status: " + str(status) + " "
+    if (status != 200) and (status != 204):
+        prepend = f"status: {status}"
     content = resp_tuple[1]
     if prepend or (content != expected and content != ""):
-        return prepend + "content: " + str(content)
+        return f"{prepend} content: {content}"
     return "pass"