Adapt CSIT for netconf-node state encapsulation 60/113560/14
authorSamuel Schneider <samuel.schneider@pantheon.tech>
Wed, 18 Sep 2024 14:53:23 +0000 (16:53 +0200)
committerSangwook Ha <sangwook.ha@verizon.com>
Wed, 9 Oct 2024 21:10:38 +0000 (14:10 -0700)
Adapt scripts used in scale test suites. Use payload with
node encapsulation if version is at least scandium.

JIRA: INTTEST-146
Change-Id: I4ebcc33b1c00d40bc74023f2f936406c72bb6b8b
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
csit/libraries/TopologyNetconfNodes.py
csit/suites/netconf/clusteringscale/topology_leader_ha.robot
csit/suites/netconf/clusteringscale/topology_owner_ha.robot
csit/suites/netconf/scale/max_devices.robot
tools/netconf_tools/configurer.py

index 0dd5fb78d2449151a2c756b06ce9cf603e1ca8a7..06e41cd5185839c7e669b0511ed8ec729a7d2337 100644 (file)
@@ -16,6 +16,7 @@ def configure_device_range(
     device_ipaddress,
     device_port,
     device_count,
+    use_node_encapsulation,
     first_device_id=1,
 ):
     """Generate device_count names in format "$device_name_prefix-$i" and configure them into NETCONF topology at specified RESTCONF URL.
@@ -70,29 +71,10 @@ def configure_device_range(
     for i in range(first_device_id, first_device_id + device_count):
         name = "{}-{}".format(device_name_prefix, i)
         device_names.append(name)
-        edits.append(
-            """
-            {
-              "edit-id" : "node-%s",
-              "operation" : "replace",
-              "target" : "/network-topology:node[network-topology:node-id='%s']",
-              "value" : {
-                "node" : [
-                  {
-                    "node-id" : "%s",
-                    "netconf-node-topology:host" : "%s",
-                    "netconf-node-topology:port" : %s,
-                    "netconf-node-topology:username" : "admin",
-                    "netconf-node-topology:password" : "topsecret",
-                    "netconf-node-topology:tcp-only" : false,
-                    "netconf-node-topology:keepalive-delay" : 0
-                  }
-                ]
-              }
-            }
-        """
-            % (name, name, name, device_ipaddress, device_port)
-        )
+        if use_node_encapsulation:
+            edits.append(get_encapsulated_payload(name, device_ipaddress, device_port))
+        else:
+            edits.append(get_legacy_payload(name, device_ipaddress, device_port))
 
     data = """
     {
@@ -171,6 +153,70 @@ def configure_device_range(
     return device_names
 
 
+def get_legacy_payload(name, device_ipaddress, device_port):
+    return """
+        {
+          "edit-id" : "node-%s",
+          "operation" : "replace",
+          "target": "/node=%s",
+          "value" : {
+            "node" : [
+              {
+                "node-id" : "%s",
+                "netconf-node-topology:host" : "%s",
+                "netconf-node-topology:port" : %s,
+                "netconf-node-topology:login-password-unencrypted": {
+                    "username": "admin",
+                    "password": "topsecret"
+                },
+                "netconf-node-topology:tcp-only" : false,
+                "netconf-node-topology:keepalive-delay" : 0
+              }
+            ]
+          }
+        }
+    """ % (
+        name,
+        name,
+        name,
+        device_ipaddress,
+        device_port,
+    )
+
+
+def get_encapsulated_payload(name, device_ipaddress, device_port):
+    return """
+        {
+          "edit-id" : "node-%s",
+          "operation" : "replace",
+          "target": "/node=%s",
+          "value" : {
+            "node" : [
+              {
+                "node-id" : "%s",
+                "netconf-node-topology:netconf-node":{
+                    "host" : "%s",
+                    "port" : %s,
+                    "login-password-unencrypted": {
+                        "username": "admin",
+                        "password": "topsecret"
+                    },
+                    "tcp-only" : false,
+                    "keepalive-delay" : 0
+                  }
+              }
+            ]
+          }
+        }
+    """ % (
+        name,
+        name,
+        name,
+        device_ipaddress,
+        device_port,
+    )
+
+
 def await_devices_connected(restconf_url, device_names, deadline_seconds):
     """Await all specified devices to become connected in NETCONF topology at specified RESTCONF URL."""
 
@@ -228,6 +274,7 @@ def main(args):
             device_ipaddress="127.0.0.1",
             device_port=17830,
             device_count=int(args[1]),
+            use_node_encapsulation=True,
         )
         print(names)
     elif args[0] == "await":
index f60809d83f52f0605ad88abef4be414f3e1cd6b8..b3da79866779ad579d224cd3e06377d9c14b81c1 100644 (file)
@@ -87,9 +87,10 @@ Start_Configurer
     [Documentation]    Launch Python utility (while copying output to log file) and verify it does not stop by itself.
     ${log_filename} =    Utils.Get_Log_File_Name    configurer
     BuiltIn.Set_Suite_Variable    \${log_filename}
+    ${use_node_encapsulation} =    CompareStream.Set_Variable_If_At_Least_Scandium    True    False
     # TODO: Should things like restconf port/user/password be set from Variables?
     ${command} =    BuiltIn.Set_Variable
-    ...    python configurer.py --odladdress ${entity_ownership_leader_ip} --deviceaddress ${TOOLS_SYSTEM_IP} --devices ${DEVICE_SET_SIZE} --disconndelay ${CONFIGURED_DEVICES_LIMIT} --basename ${DEVICE_BASE_NAME} --connsleep ${CONNECTION_SLEEP} &> "${log_filename}"
+    ...    python configurer.py --odladdress ${entity_ownership_leader_ip} --deviceaddress ${TOOLS_SYSTEM_IP} --devices ${DEVICE_SET_SIZE} --disconndelay ${CONFIGURED_DEVICES_LIMIT} --basename ${DEVICE_BASE_NAME} --connsleep ${CONNECTION_SLEEP} --encapsulation ${use_node_encapsulation}  &> "${log_filename}"
     SSHLibrary.Write    ${command}
     ${status}    ${text} =    BuiltIn.Run_Keyword_And_Ignore_Error    SSHLibrary.Read_Until_Prompt
     BuiltIn.Log    ${text}
index 77c4e8bc83d7f0a67d7ca7065dd115eeb77b9bdc..16cee8efc67ce43499742bce69a782134e170c68 100644 (file)
@@ -111,9 +111,10 @@ Start_Configurer
     [Documentation]    Launch Python utility (while copying output to log file) and verify it does not stop by itself.
     ${log_filename} =    Utils.Get_Log_File_Name    configurer
     BuiltIn.Set_Suite_Variable    \${log_filename}
+    ${use_node_encapsulation} =    CompareStream.Set_Variable_If_At_Least_Scandium    True    False
     # TODO: Should things like restconf port/user/password be set from Variables?
     ${command} =    BuiltIn.Set_Variable
-    ...    python configurer.py --odladdress ${topology_config_leader_ip} --deviceaddress ${TOOLS_SYSTEM_IP} --devices ${DEVICE_SET_SIZE} --disconndelay ${CONFIGURED_DEVICES_LIMIT} --basename ${DEVICE_BASE_NAME} --connsleep ${CONNECTION_SLEEP} &> "${log_filename}"
+    ...    python configurer.py --odladdress ${topology_config_leader_ip} --deviceaddress ${TOOLS_SYSTEM_IP} --devices ${DEVICE_SET_SIZE} --disconndelay ${CONFIGURED_DEVICES_LIMIT} --basename ${DEVICE_BASE_NAME} --connsleep ${CONNECTION_SLEEP} --encapsulation ${use_node_encapsulation} &> "${log_filename}"
     SSHLibrary.Write    ${command}
     ${status}    ${text} =    BuiltIn.Run_Keyword_And_Ignore_Error    SSHLibrary.Read_Until_Prompt
     BuiltIn.Log    ${text}
index ac29a77bb9ea2882043acc13f8ec2bb23c5408d3..4c15b2ff068459e551885be633a47136e1cb929c 100644 (file)
@@ -83,12 +83,14 @@ Find Max Netconf Devices
         END
         ${devices_to_configure} =    BuiltIn.Evaluate    ${devices} - len(${device_names})
         ${first_id} =    BuiltIn.Evaluate    len(${device_names}) + 1
+        ${use_node_encapsulation} =    CompareStream.Set_Variable_If_At_Least_Scandium    ${True}    ${False}
         ${device_names} =    TopologyNetconfNodes.Configure Device Range
         ...    restconf_url=${restconf_url}
         ...    device_name_prefix=${DEVICE_NAME_BASE}
         ...    device_ipaddress=${TOOLS_SYSTEM_IP}
         ...    device_port=17830
         ...    device_count=${devices_to_configure}
+        ...    use_node_encapsulation=${use_node_encapsulation}
         ...    first_device_id=${first_id}
         TopologyNetconfNodes.Await Devices Connected
         ...    restconf_url=${restconf_url}
index 98892c15b8c79f91d522ee1447ad8922dd697ac7..628277358cb12e3b3623b7644c824f62a8dabee1 100644 (file)
@@ -122,23 +122,49 @@ def parse_arguments():
         type=str2bool,
         help="Should single requests session be re-used",
     )
+    parser.add_argument(
+        "--encapsulation",
+        default="True",
+        type=str2bool,
+        help="If payload with node encapsulation should be used",
+    )
     return parser.parse_args()  # arguments are read
 
 
-DATA_TEMPLATE = string.Template(
+LEGACY_DATA_TEMPLATE = string.Template(
     """{
     "network-topology:node": {
         "node-id": "$DEVICE_NAME",
         "netconf-node-topology:host": "$DEVICE_IP",
         "netconf-node-topology:port": $DEVICE_PORT,
-        "netconf-node-topology:username": "$DEVICE_USER",
-        "netconf-node-topology:password": "$DEVICE_PASSWORD",
+        "netconf-node-topology:login-password-unencrypted": {
+            "username": "$DEVICE_USER",
+            "password": "$DEVICE_PASSWORD"
+        },
         "netconf-node-topology:tcp-only": "false",
         "netconf-node-topology:keepalive-delay": 0
     }
 }"""
 )
 
+ENCAPSULATION_DATA_TEMPLATE = string.Template(
+    """{
+    "network-topology:node": {
+        "node-id": "$DEVICE_NAME",
+        "netconf-node-topology:netconf-node":{
+            "host": "$DEVICE_IP",
+            "port": $DEVICE_PORT,
+            "login-password-unencrypted": {
+                "username": "$DEVICE_USER",
+                "password": "$DEVICE_PASSWORD"
+            },
+            "tcp-only": "false",
+            "keepalive-delay": 0
+        }
+    }
+}"""
+)
+
 
 def count_response(counter, response, method):
     """Add counter item built from response data and given method."""
@@ -211,7 +237,10 @@ def main():
             put_name = args.basename + "-" + str(port) + "-" + str(iteration)
             subst_dict["DEVICE_NAME"] = put_name
             subst_dict["DEVICE_PORT"] = str(port)
-            put_data = DATA_TEMPLATE.substitute(subst_dict)
+            if args.encapsulation:
+                put_data = ENCAPSULATION_DATA_TEMPLATE.substitute(subst_dict)
+            else:
+                put_data = LEGACY_DATA_TEMPLATE.substitute(subst_dict)
             uri = uri_part + put_name
             response = AuthStandalone.Put_Using_Session(
                 session, uri, data=put_data, headers=put_headers