Migrate Tests/Scripts to Python3 27/90527/14
authorVenkatrangan Govindarajan <vgovindarajan@luminanetworks.com>
Sat, 20 Jun 2020 18:28:50 +0000 (23:58 +0530)
committerLuis Gomez <ecelgp@gmail.com>
Sun, 21 Jun 2020 21:47:01 +0000 (14:47 -0700)
- Used 2to3 to migrate scripts to python3
- Fixed some issues due to robot 3.2.1

JIRA: INTTEST-105
Signed-off-by: Venkatrangan Govindarajan <vgovindarajan@luminanetworks.com>
Change-Id: I1028a2090ae616b192119d0eff8d27c7f95bfddd

csit/libraries/BgpRpcClient.py
csit/libraries/CompareStream.robot
csit/libraries/Utils.robot
csit/libraries/norm_json.py
csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot
csit/variables/Variables.robot
csit/variables/pcepuser/variables.py
csit/variables/tcpmd5user/variables.py
docs/requirements.txt

index 55dba2b35f52f6b50cf69f3f9ddf660085fd3999..817d8f7f1f9dede661989f6ff5507080bf71adf9 100644 (file)
@@ -7,7 +7,7 @@ play_ methods apply to test/tool/fastbgp/play.py  (only with --evpn used)
 """
 
 import re
-import xmlrpclib
+import xmlrpc.client
 
 
 class BgpRpcClient(object):
@@ -15,7 +15,7 @@ class BgpRpcClient(object):
 
     def __init__(self, peer_addr, port=8000):
         """Setup destination point of the rpc server"""
-        self.proxy = xmlrpclib.ServerProxy("http://{}:{}".format(peer_addr, port))
+        self.proxy = xmlrpc.client.ServerProxy("http://{}:{}".format(peer_addr, port))
 
     def exa_announce(self, full_exabgp_cmd):
         """The full command to be passed to exabgp."""
@@ -100,4 +100,4 @@ class BgpRpcClient(object):
     def sum_hex_message(self, hex_string):
         """Verifies two hex messages are equal even in case, their arguments are misplaced.
         Converts hex message arguments to integers and sums them up and returns the sum."""
-        return sum(map(lambda x: int(x, 16), re.compile('[a-f\d]{2}').findall(hex_string[32:])))
+        return sum([int(x, 16) for x in re.compile('[a-f\d]{2}').findall(hex_string[32:])])
index fa008ebea26701c1039b31eadc8fc5b7a8927565..4da6f4dc7a181d369740cd56b42bae71bafdae4d 100644 (file)
@@ -15,13 +15,13 @@ Set_Variable_If_At_Least
     [Arguments]    ${lower_bound}    ${value_if_true}    ${value_if_false}
     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at least ${lower_bound},
     ...    return ${value_if_false} otherwise.
-    BuiltIn.Run_Keyword_And_Return    BuiltIn.Set_Variable_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    ${value_if_true}    ${value_if_false}
+    BuiltIn.Run_Keyword_And_Return    BuiltIn.Set_Variable_If    ${Stream_dict}[${ODL_STREAM}] >= ${Stream_dict}[${lower_bound}]    ${value_if_true}    ${value_if_false}
 
 Set_Variable_If_At_Most
     [Arguments]    ${upper_bound}    ${value_if_true}    ${value_if_false}
     [Documentation]    Compare ${upper_bound} to ${ODL_STREAM} and return ${value_if_true} if ${ODL_STREAM} is at most ${upper_bound},
     ...    return ${value_if_false} otherwise.
-    BuiltIn.Run_Keyword_And_Return    BuiltIn.Set_Variable_If    &{Stream_dict}[${ODL_STREAM}] <= &{Stream_dict}[${upper_bound}]    ${value_if_true}    ${value_if_false}
+    BuiltIn.Run_Keyword_And_Return    BuiltIn.Set_Variable_If    ${Stream_dict}[${ODL_STREAM}] <= ${Stream_dict}[${upper_bound}]    ${value_if_true}    ${value_if_false}
 
 Set_Variable_If_At_Least_Carbon
     [Arguments]    ${value_if_true}    ${value_if_false}
@@ -143,7 +143,7 @@ Run_Keyword_If_At_Least
     [Arguments]    ${lower_bound}    ${kw_name}    @{varargs}    &{kwargs}
     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is at least ${lower_bound},
     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
-    BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
+    BuiltIn.Run_Keyword_And_Return_If    ${Stream_dict}[${ODL_STREAM}] >= ${Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
 
 Run_Keyword_If_At_Least_Else
     [Arguments]    ${lower_bound}    @{varargs}
@@ -155,7 +155,7 @@ Run_Keyword_If_At_Least_Else
     ${varargs_else}    Collections.Get_Slice_From_List    ${varargs}    ${position+1}
     ${args_if}    ${kwargs_if}    CompareStream__Convert_Input    @{varargs_if}
     ${args_else}    ${kwargs_else}    CompareStream__Convert_Input    @{varargs_else}
-    ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    @{args_if}    &{kwargs_if}
+    ${resp}    BuiltIn.Run_Keyword_If    ${Stream_dict}[${ODL_STREAM}] >= ${Stream_dict}[${lower_bound}]    @{args_if}    &{kwargs_if}
     ...    ELSE    @{args_else}    &{kwargs_else}
     [Return]    ${resp}
 
@@ -163,7 +163,7 @@ Run_Keyword_If_At_Most
     [Arguments]    ${upper_bound}    ${kw_name}    @{varargs}    &{kwargs}
     [Documentation]    Compare ${upper_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is at most ${upper_bound},
     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
-    BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] <= &{Stream_dict}[${upper_bound}]    ${kw_name}    @{varargs}    &{kwargs}
+    BuiltIn.Run_Keyword_And_Return_If    ${Stream_dict}[${ODL_STREAM}] <= ${Stream_dict}[${upper_bound}]    ${kw_name}    @{varargs}    &{kwargs}
 
 Run_Keyword_If_At_Most_Else
     [Arguments]    ${upper_bound}    @{varargs}
@@ -175,7 +175,7 @@ Run_Keyword_If_At_Most_Else
     ${varargs_else}    Collections.Get_Slice_From_List    ${varargs}    ${position+1}
     ${args_if}    ${kwargs_if}    CompareStream__Convert_Input    @{varargs_if}
     ${args_else}    ${kwargs_else}    CompareStream__Convert_Input    @{varargs_else}
-    ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    @{args_if}    &{kwargs_if}
+    ${resp}    BuiltIn.Run_Keyword_If    ${Stream_dict}[${ODL_STREAM}] >= ${Stream_dict}[${lower_bound}]    @{args_if}    &{kwargs_if}
     ...    ELSE    @{args_else}    &{kwargs_else}
     [Return]    ${resp}
 
@@ -183,13 +183,13 @@ Run_Keyword_If_More_Than
     [Arguments]    ${lower_bound}    ${kw_name}    @{varargs}    &{kwargs}
     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is more than ${lower_bound},
     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
-    BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] > &{Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
+    BuiltIn.Run_Keyword_And_Return_If    ${Stream_dict}[${ODL_STREAM}] > ${Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
 
 Run_Keyword_If_Equals
     [Arguments]    ${stream}    ${kw_name}    @{varargs}    &{kwargs}
     [Documentation]    Compare ${stream} to ${ODL_STREAM} and in case ${ODL_STREAM} equals ${stream},
     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
-    BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] == &{Stream_dict}[${stream}]    ${kw_name}    @{varargs}    &{kwargs}
+    BuiltIn.Run_Keyword_And_Return_If    ${Stream_dict}[${ODL_STREAM}] == ${Stream_dict}[${stream}]    ${kw_name}    @{varargs}    &{kwargs}
 
 Run_Keyword_If_Equals_Else
     [Arguments]    ${stream}    @{varargs}
@@ -201,7 +201,7 @@ Run_Keyword_If_Equals_Else
     ${varargs_else}    Collections.Get_Slice_From_List    ${varargs}    ${position+1}
     ${args_if}    ${kwargs_if}    CompareStream__Convert_Input    @{varargs_if}
     ${args_else}    ${kwargs_else}    CompareStream__Convert_Input    @{varargs_else}
-    ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] == &{Stream_dict}[${stream}]    @{args_if}    &{kwargs_if}
+    ${resp}    BuiltIn.Run_Keyword_If    ${Stream_dict}[${ODL_STREAM}] == ${Stream_dict}[${stream}]    @{args_if}    &{kwargs_if}
     ...    ELSE    @{args_else}    &{kwargs_else}
     [Return]    ${resp}
 
@@ -209,7 +209,7 @@ Run_Keyword_If_Less_Than
     [Arguments]    ${lower_bound}    ${kw_name}    @{varargs}    &{kwargs}
     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is less than ${lower_bound},
     ...    run ${kw_name} @{varargs} &{kwargs} and return its value.
-    BuiltIn.Run_Keyword_And_Return_If    &{Stream_dict}[${ODL_STREAM}] < &{Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
+    BuiltIn.Run_Keyword_And_Return_If    ${Stream_dict}[${ODL_STREAM}] < ${Stream_dict}[${lower_bound}]    ${kw_name}    @{varargs}    &{kwargs}
 
 Run_Keyword_If_At_Least_Carbon
     [Arguments]    ${kw_name}    @{varargs}    &{kwargs}
index 34d711750a80feff0f1516c287a4480b1dd1dcad..8d4caf2d7a00beb096a134bccee91e9abacafdd8 100644 (file)
@@ -1,7 +1,6 @@
 *** Settings ***
 Documentation     General Utils library. This library has broad scope, it can be used by any robot system tests.
 Library           SSHLibrary
-Library           HttpLibrary.HTTP
 Library           String
 Library           DateTime
 Library           Process
index cc208277d8e15dd4853cbd160f131c0174510e0f..62b9ef0d33ceb7cf228f1e69ab2c54ba74452b37 100644 (file)
@@ -58,11 +58,11 @@ class _Hsfod(_collections.OrderedDict):
     def __init__(self, *args, **kwargs):
         """Put arguments to OrderedDict, sort, pass to super, cache values."""
         self_unsorted = _collections.OrderedDict(*args, **kwargs)
-        items_sorted = sorted(self_unsorted.items(), key=repr)
+        items_sorted = sorted(list(self_unsorted.items()), key=repr)
         sup = super(_Hsfod, self)  # possibly something else than OrderedDict
         sup.__init__(items_sorted)
         # Repr string is used for sorting, keys are more important than values.
-        self.__repr = '{' + repr(self.keys()) + ':' + repr(self.values()) + '}'
+        self.__repr = '{' + repr(list(self.keys())) + ':' + repr(list(self.values())) + '}'
         self.__hash = hash(self.__repr)
 
     def __repr__(self):
@@ -139,11 +139,11 @@ def sort_bits(obj, keys_with_bits=[]):
     TODO: Should this docstring include links to support dict and OrderedDict safety?
     """
     if isinstance(obj, dict):
-        for key, value in obj.iteritems():
+        for key, value in obj.items():
             # Unicode is not str and vice versa, isinstance has to check for both.
             # Luckily, "in" recognizes equivalent strings in different encodings.
             # Type "bytes" is added for Python 3 compatibility.
-            if key in keys_with_bits and isinstance(value, (unicode, str, bytes)):
+            if key in keys_with_bits and isinstance(value, (str, bytes)):
                 obj[key] = " ".join(sorted(value.split(" ")))
             else:
                 sort_bits(value, keys_with_bits)
@@ -163,11 +163,11 @@ def hide_volatile(obj, keys_with_volatiles=[]):
     :return: corrected
     """
     if isinstance(obj, dict):
-        for key, value in obj.iteritems():
+        for key, value in obj.items():
             # Unicode is not str and vice versa, isinstance has to check for both.
             # Luckily, "in" recognizes equivalent strings in different encodings.
             # Type "bytes" is added for Python 3 compatibility.
-            if key in keys_with_volatiles and isinstance(value, (unicode, str, bytes, int, bool)):
+            if key in keys_with_volatiles and isinstance(value, (str, bytes, int, bool)):
                 obj[key] = "*"
             else:
                 hide_volatile(value, keys_with_volatiles)
index 8bb76d70ca6354128dbceb013930edc64badc50e..320ca02dc996b2dff95d28d59cae666c2c06cb72 100644 (file)
@@ -35,6 +35,7 @@ Resource          ../../../libraries/TemplatedRequests.robot
 Resource          ../../../libraries/RemoteBash.robot
 Resource          ../../../libraries/WaitForFailure.robot
 Resource          ../../../variables/Variables.robot
+Variables         ../../../variables/tcpmd5user/variables.py    ${TOOLS_SYSTEM_IP}
 
 *** Variables ***
 ${DIR_WITH_TEMPLATES}    ${CURDIR}/../../../variables/tcpmd5user/
@@ -172,9 +173,6 @@ Set_It_Up
     ${name}=    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
     BuiltIn.Set_Suite_Variable    ${filename}    ${name}
     #Setting Pcc Name and its code for mapping for templates
-    BuiltIn.Set_Suite_Variable    ${pcc_name}    pcc_${TOOLS_SYSTEM_IP}_tunnel_1
-    ${code}=    Evaluate    binascii.b2a_base64('${pcc_name}')[:-1]    modules=binascii
-    BuiltIn.Set_Suite_Variable    ${pcc_name_code}    ${code}
     FailFast.Do_Not_Fail_Fast_From_Now_On
     ${ERROR_ARGS} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_ERROR_ARGS}    ${OLD_ERROR_ARGS}
     BuiltIn.Set_Suite_Variable    ${ERROR_ARGS}
index b02836c201edcddc5560211b60ed25cd5a6bc4c7..8e4ddd3f822598a3380656aecf9ac724d8b44226 100644 (file)
@@ -96,7 +96,7 @@ ${GET_INTENTS_URI}    /retconf/config/intent:intents    # FIXME: Move to a separ
 &{HEADERS_XML}    Content-Type=application/xml    # Content type for XML data. TODO: Hide into more specific Resource if possible.
 ${KARAF_PROMPT_LOGIN}    opendaylight-user    # This is used for karaf console login.
 ${ICMP_TYPE}      135
-${KARAF_DETAILED_PROMPT}    @${ESCAPE_CHARACTER}[0m${ESCAPE_CHARACTER}[34mroot${ESCAPE_CHARACTER}[0m>    # Larger substring of Karaf prompt, shorter ones may result in false positives.
+${KARAF_DETAILED_PROMPT}    @${ESCAPE_CHARACTER}\[0m${ESCAPE_CHARACTER}\[34mroot${ESCAPE_CHARACTER}\[0m>    # Larger substring of Karaf prompt, shorter ones may result in false positives.
 ${KARAF_HOME}     ${WORKSPACE}${/}${BUNDLEFOLDER}    # Karaf home directory path.
 ${KARAF_LOG}      ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log    # location of karaf.log in standard CSIT jobs
 ${KARAF_PASSWORD}    karaf    # Plaintext password to authenticate to Karaf console.
index 2a8f03a9c016f937066f81a5970612fac0b01fc1..7d9e8ad47adb93a1303503e07431eb5148bbcb88 100644 (file)
@@ -12,7 +12,7 @@ than do manipulation in Robot file."""
 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
 # and is available at http://www.eclipse.org/legal/epl-v10.html
 
-import binascii
+import base64
 from string import Template
 
 
@@ -26,7 +26,7 @@ def get_variables(mininet_ip):
     """Return dict of variables for the given IP address of Mininet VM."""
     variables = {}
     # 'V' style of explanation.
-    # Comments analyze from high level, to low level, then code builds from low level back to high level.
+    # Comments a nalyze from high level, to low level, then code builds from low level back to high level.
     # ### Pcep-topology JSON responses.
     # Some testcases see only the tunnel created by pcc-mock start: "delegated tunnel" (ID 1).
     # Other testcases see also tunnel created on ODL demand: "instatntiated tunnel" (ID 2).
@@ -121,8 +121,13 @@ def get_variables(mininet_ip):
     # But as we need to plug the name to XML, let us try something more friendly:
     instantiated_name = 'Instantiated tunnel'  # the space is only somewhat evil character :)
     # What is CODE? The NAME in base64 encoding (without endline):
-    delegated_code = binascii.b2a_base64(delegated_name)[:-1]  # remove endline added by the library function
-    instantiated_code = binascii.b2a_base64(instantiated_name)[:-1]
+    delegated_name_bytes = delegated_name.encode('ascii')
+    delegated_code_encoded = base64.b64encode(delegated_name_bytes)
+    delegated_code = delegated_code_encoded.decode('ascii')
+    instantiated_name_bytes = instantiated_name.encode('ascii')
+    instantiated_code_encoded = base64.b64encode(instantiated_name_bytes)
+    instantiated_code = instantiated_code_encoded.decode('ascii')
+
     # The remaining segment is HOPS, and that is the place where default and updated states differ.
     # Once again, there is a template for a single hop:
     hop_templ = Template('''
index 8ccff4f02218c72bfac9b739b9c1e2ba6cb6c7a2..6d0ce2fa91365ecda167a8bd35e7d9bfd4946296 100644 (file)
@@ -14,7 +14,7 @@ than do manipulation in Robot file.
 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
 # and is available at http://www.eclipse.org/legal/epl-v10.html
 
-import binascii
+import base64
 from string import Template
 
 
@@ -34,7 +34,11 @@ def get_variables(mininet_ip):
     # Given mininet_ip, this will be the sympolic name uf tunnel under test.
     tunnelname = 'pcc_' + mininet_ip + '_tunnel_1'
     # Base64 code for the symbolic name, as that is present in datastore.
-    pathcode = binascii.b2a_base64(tunnelname)[:-1]  # remove endline
+    tunnelname_bytes = tunnelname.encode('ascii')
+    pathcode_encoded = base64.b64encode(tunnelname_bytes)
+    pathcode = pathcode_encoded.decode('ascii')
+    variables['pcc_name'] = tunnelname
+    variables['pcc_name_code'] = pathcode
     # JSON response when pcep-topology is ready but no PCC is connected.
     variables['offjson'] = '''{
  "topology": [
index 082014c5a13f98516cec7faf1ef3b624adde77fe..81ba744e2e525c25968807fb646df26c9d8632d0 100644 (file)
@@ -1,2 +1,5 @@
+elasticsearch
+elasticsearch_dsl
 lfdocs-conf
+matplotlib
 robotframework