From 70e7e92db781b5840a68491d497ddbb345d26403 Mon Sep 17 00:00:00 2001 From: Sangwook Ha Date: Mon, 29 Aug 2022 09:19:26 -0700 Subject: [PATCH 1/1] Fix bgpcep-1node-throughpcep 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 --- csit/libraries/AuthStandalone.py | 8 ++++---- csit/suites/bgpcep/throughpcep/cases.robot | 6 +++--- tools/pcep_updater/updater.py | 15 ++++++--------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/csit/libraries/AuthStandalone.py b/csit/libraries/AuthStandalone.py index 5cb840a4f9..6e766a1e05 100644 --- a/csit/libraries/AuthStandalone.py +++ b/csit/libraries/AuthStandalone.py @@ -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"} diff --git a/csit/suites/bgpcep/throughpcep/cases.robot b/csit/suites/bgpcep/throughpcep/cases.robot index 4df50a7b1a..0ce72d0a01 100644 --- a/csit/suites/bgpcep/throughpcep/cases.robot +++ b/csit/suites/bgpcep/throughpcep/cases.robot @@ -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 diff --git a/tools/pcep_updater/updater.py b/tools/pcep_updater/updater.py index aafed26b56..51af19be30 100644 --- a/tools/pcep_updater/updater.py +++ b/tools/pcep_updater/updater.py @@ -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" -- 2.36.6