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.
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 = """
{
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."""
device_ipaddress="127.0.0.1",
device_port=17830,
device_count=int(args[1]),
+ use_node_encapsulation=True,
)
print(names)
elif args[0] == "await":
[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}
[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}
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}
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."""
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