2 Documentation Perform complex operations on netconf.
4 ... Copyright (c) 2015,2017 Cisco Systems, Inc. and others. All rights reserved.
6 ... This program and the accompanying materials are made available under the
7 ... terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ... and is available at http://www.eclipse.org/legal/epl-v10.html
11 ... This library encapsulates a bunch of somewhat complex and commonly used
12 ... netconf operations into reusable keywords to make writing netconf
13 ... test suites easier.
15 ... TODO: RemoteBash.robot contains logic which could be reused here.
19 Library RequestsLibrary
21 Resource NexusKeywords.robot
22 Resource Restconf.robot
23 Resource SSHKeywords.robot
24 Resource TemplatedRequests.robot
26 Resource RemoteBash.robot
31 ${TESTTOOL_DEFAULT_JAVA_OPTIONS} -Xmx${MAX_HEAP} -Djava.security.egd=file:/dev/./urandom
32 ${DIRECTORY_WITH_DEVICE_TEMPLATES} ${CURDIR}/../variables/netconf/device
33 ${FIRST_TESTTOOL_PORT} 17830
34 ${BASE_NETCONF_DEVICE_PORT} 17830
35 ${DEVICE_NAME_BASE} netconf-scaling-device
36 ${TESTTOOL_BOOT_TIMEOUT} 60s
37 ${ENABLE_NETCONF_TEST_TIMEOUT} ${ENABLE_GLOBAL_TEST_DEADLINES}
38 ${SSE_CFG_FILE} ${WORKSPACE}/${BUNDLEFOLDER}/etc/org.opendaylight.restconf.nb.rfc8040.cfg
43 [Documentation] Setup the environment for the other keywords of this Resource to work properly.
44 [Arguments] ${create_session_for_templated_requests}=True
45 ${tmp}= BuiltIn.Create_Dictionary
46 BuiltIn.Set_Suite_Variable ${NetconfKeywords__mounted_device_types} ${tmp}
47 IF ${create_session_for_templated_requests}
48 TemplatedRequests.Create_Default_Session timeout=2
50 NexusKeywords.Initialize_Artifact_Deployment_And_Usage
52 Configure_Device_In_Netconf
53 [Documentation] Tell Netconf about the specified device so it can add it into its configuration.
54 [Arguments] ${device_name} ${device_type}=default ${device_port}=${FIRST_TESTTOOL_PORT} ${device_address}=${TOOLS_SYSTEM_IP} ${device_user}=admin ${device_password}=topsecret
55 ... ${device_key}=device-key ${session}=default ${schema_directory}=/tmp/schema ${http_timeout}=${EMPTY} ${http_method}=put
56 ${mapping}= BuiltIn.Create_dictionary
57 ... DEVICE_IP=${device_address}
58 ... DEVICE_NAME=${device_name}
59 ... DEVICE_PORT=${device_port}
60 ... DEVICE_USER=${device_user}
61 ... DEVICE_PASSWORD=${device_password}
62 ... DEVICE_KEY=${device_key}
63 ... SCHEMA_DIRECTORY=${schema_directory}
64 # TODO: Is it possible to use &{kwargs} as a mapping directly?
65 IF '${http_method}'=='post'
66 TemplatedRequests.Post_As_Xml_Templated
67 ... folder=${DIRECTORY_WITH_DEVICE_TEMPLATES}${/}${device_type}
68 ... mapping=${mapping}
69 ... session=${session}
70 ... http_timeout=${http_timeout}
72 TemplatedRequests.Put_As_Xml_Templated
73 ... folder=${DIRECTORY_WITH_DEVICE_TEMPLATES}${/}${device_type}
74 ... mapping=${mapping}
75 ... session=${session}
76 ... http_timeout=${http_timeout}
78 Collections.Set_To_Dictionary ${NetconfKeywords__mounted_device_types} ${device_name} ${device_type}
81 [Documentation] Operation for configuring the device.
82 [Arguments] ${current_name} ${log_response}=True
83 KarafKeywords.Log_Message_To_Controller_Karaf Configuring device ${current_name} to Netconf
84 Configure_Device_In_Netconf ${current_name} device_type=${device_type} device_port=${current_port}
85 KarafKeywords.Log_Message_To_Controller_Karaf Device ${current_name} configured
87 Configure_Device_And_Verify
88 [Documentation] Operation for configuring the device in the Netconf subsystem and connecting to it.
89 [Arguments] ${current_name} ${log_response}=True
90 Configure_Device ${current_name} ${log_response}
91 KarafKeywords.Log_Message_To_Controller_Karaf Waiting for device ${current_name} to connect
92 Wait_Device_Connected ${current_name} period=0.5s log_response=${log_response}
93 KarafKeywords.Log_Message_To_Controller_Karaf Device ${current_name} connected
95 Count_Netconf_Connectors_For_Device
96 [Documentation] Count all instances of the specified device in the Netconf topology (usually 0 or 1).
97 [Arguments] ${device_name} ${session}=default
98 # FIXME: This no longer counts netconf connectors, it counts "device instances in Netconf topology".
99 # This keyword should be renamed but without an automatic keyword naming standards checker this is
100 # potentially destabilizing change so right now it is as FIXME. Proposed new name:
101 # Count_Device_Instances_In_Netconf_Topology
102 ${uri}= Restconf.Generate URI network-topology:network-topology operational
103 ${mounts}= TemplatedRequests.Get_As_Json_From_Uri ${uri} session=${session}
104 Builtin.Log ${mounts}
105 ${actual_count}= Builtin.Evaluate len('''${mounts}'''.split('"node-id": "${device_name}"'))-1
106 RETURN ${actual_count}
109 [Documentation] Operation for waiting until the device is connected.
110 [Arguments] ${current_name} ${log_response}=True
111 KarafKeywords.Log_Message_To_Controller_Karaf Waiting for device ${current_name} to connect
112 Wait_Device_Connected ${current_name} period=0.5s timeout=300s log_response=${log_response}
113 KarafKeywords.Log_Message_To_Controller_Karaf Device ${current_name} connected
115 Check_Device_Has_No_Netconf_Connector
116 [Documentation] Check that there are no instances of the specified device in the Netconf topology.
117 [Arguments] ${device_name} ${session}=default
118 # FIXME: Similarlt to "Count_Netconf_Connectors_For_Device", this does not check whether the device has
119 # no netconf connector but whether the device is present in the netconf topology or not. Rename, proposed
120 # new name: Check_Device_Not_Present_In_Netconf_Topology
121 ${count}= Count_Netconf_Connectors_For_Device ${device_name} session=${session}
122 Builtin.Should_Be_Equal_As_Strings ${count} 0
124 Check_Device_Completely_Gone
125 [Documentation] Check that the specified device has no Netconf connectors nor associated data.
126 [Arguments] ${device_name} ${session}=default ${log_response}=True
127 Check_Device_Has_No_Netconf_Connector ${device_name} session=${session}
128 ${uri}= Restconf.Generate URI
129 ... network-topology:network-topology
131 ... topology=topology-netconf
132 ... node=${device_name}
133 Utils.No Content From URI ${session} ${uri}
135 Check_Device_Connected
136 [Documentation] Check that the specified device is accessible from Netconf.
137 [Arguments] ${device_name} ${session}=default ${log_response}=True
138 ${uri}= Restconf.Generate URI
139 ... network-topology:network-topology
141 ... topology=topology-netconf
142 ... node=${device_name}
143 ${device_status}= TemplatedRequests.Get_As_Json_From_Uri
145 ... session=${session}
146 ... log_response=${log_response}
147 Builtin.Should_Contain ${device_status} "netconf-node-topology:connection-status": "connected"
149 Wait_Device_Connected
150 [Documentation] Wait for the device to become connected.
151 ... It is more readable to use this keyword in a test case than to put the whole WUKS below into it.
152 [Arguments] ${device_name} ${timeout}=20s ${period}=1s ${session}=default ${log_response}=True
153 BuiltIn.Wait_Until_Keyword_Succeeds
156 ... Check_Device_Connected
158 ... session=${session}
159 ... log_response=${log_response}
161 Remove_Device_From_Netconf
162 [Documentation] Tell Netconf to deconfigure the specified device
163 [Arguments] ${device_name} ${session}=default ${location}=location
164 ${device_type}= Collections.Pop_From_Dictionary ${NetconfKeywords__mounted_device_types} ${device_name}
165 ${template_as_string}= BuiltIn.Create_Dictionary DEVICE_NAME=${device_name}
166 TemplatedRequests.Delete_Templated
167 ... ${DIRECTORY_WITH_DEVICE_TEMPLATES}${/}${device_type}
168 ... ${template_as_string}
169 ... session=${session}
170 ... location=${location}
173 [Documentation] Operation for deconfiguring the device.
174 [Arguments] ${current_name} ${log_response}=True
175 KarafKeywords.Log_Message_To_Controller_Karaf Deconfiguring device ${current_name}
176 Remove_Device_From_Netconf ${current_name}
177 KarafKeywords.Log_Message_To_Controller_Karaf Device ${current_name} deconfigured
179 Deconfigure_Device_And_Verify
180 [Documentation] Operation for deconfiguring the device from Netconf.
181 [Arguments] ${current_name} ${log_response}=True
182 Deconfigure_Device ${current_name} ${log_response}
183 Check_Device_Deconfigured ${current_name}
185 Check_Device_Deconfigured
186 [Documentation] Operation for making sure the device is really deconfigured.
187 [Arguments] ${current_name} ${log_response}=True
188 KarafKeywords.Log_Message_To_Controller_Karaf Waiting for device ${current_name} to disappear
189 Wait_Device_Fully_Removed ${current_name} period=0.5s timeout=120s
190 KarafKeywords.Log_Message_To_Controller_Karaf Device ${current_name} removed
192 Wait_Device_Fully_Removed
193 [Documentation] Wait until all netconf connectors for the device with the given name disappear.
194 ... Call of Remove_Device_From_Netconf returns before netconf gets
195 ... around deleting the device's connector. To ensure the device is
196 ... really gone from netconf, use this keyword to make sure all
197 ... connectors disappear. If a call to Remove_Device_From_Netconf
198 ... is not made before using this keyword, the wait will fail.
199 ... Using this keyword is more readable than putting the WUKS below
200 ... into a test case.
201 [Arguments] ${device_name} ${timeout}=10s ${period}=1s ${session}=default ${log_response}=True
202 BuiltIn.Wait_Until_Keyword_Succeeds
205 ... Check_Device_Completely_Gone
207 ... session=${session}
208 ... log_response=${log_response}
210 NetconfKeywords__Deploy_Additional_Schemas
211 [Documentation] Internal keyword for Install_And_Start_TestTool
212 ... This deploys the additional schemas if any and returns a
213 ... command line argument to be added to the testtool commandline
214 ... to tell it to load them. While this code could be integrated
215 ... into its only user, I considered the resulting code to be too
216 ... unreadable as the actions are quite different in the two
217 ... possibilities (additional schemas present versus no additional
218 ... schemas present), therefore a separate keyword is used.
219 [Arguments] ${schemas}
220 # Make sure there is no schemas directory on the remote machine. A
221 # previous test suite might have left some debris there and that might
222 # lead to spurious failures, so it is better to make sure we start with a
223 # clean slate. Additionally when the caller did not specify any
224 # additional schemas for testtool, we want to make extra sure none are
226 ${response}= SSHLibrary.Execute_Command rm -rf schemas 2>&1
227 BuiltIn.Log ${response}
228 # Drop out of the keyword, returning no command line argument when there
229 # are no additional schemas to deploy.
230 IF '${schemas}' == 'none' RETURN ${EMPTY}
231 # Deploy the additional schemas into a standard directory on the remote
232 # machine and construct a command line argument pointing to that
233 # directory from the point of view of the process running on that
235 SSHLibrary.Put_Directory ${schemas} destination=./schemas
236 SSHLibrary.List_Directory ./schemas
237 RETURN --schemas-dir ./schemas
239 NetconfKeywords__Deploy_Custom_RPC
240 [Documentation] Internal keyword for Install_And_Start_TestTool
241 ... This deploys the optional custom rpc file.
242 ... Drop out of the keyword, returning no command line argument when there
243 ... is no rpc file to deploy.
244 [Arguments] ${rpc_config}
245 IF '${rpc_config}' == 'none' RETURN ${EMPTY}
246 SSHKeywords.Copy_File_To_Tools_System ${TOOLS_SYSTEM_1_IP} ${rpc_config} /tmp
247 RETURN --rpc-config /tmp/customaction.xml
249 NetconfKeywords__Check_Device_Is_Up
250 [Arguments] ${last-port}
251 ${count}= SSHKeywords.Count_Port_Occurences ${last-port} LISTEN java
252 BuiltIn.Should_Be_Equal_As_Integers ${count} 1
254 NetconfKeywords__Wait_Device_Is_Up_And_Running
255 [Arguments] ${device_name} ${log_response}=True
256 ${number}= BuiltIn.Evaluate '${device_name}'.split('-').pop()
257 BuiltIn.Wait_Until_Keyword_Succeeds ${TESTTOOL_BOOT_TIMEOUT} 1s Check_Device_Up_And_Running ${number}
259 Install_And_Start_Testtool
260 [Documentation] Install and run testtool.
261 [Arguments] ${device-count}=10 ${debug}=true ${schemas}=none ${rpc_config}=none ${tool_options}=${EMPTY} ${java_options}=${TESTTOOL_DEFAULT_JAVA_OPTIONS}
262 ... ${mdsal}=true ${log_response}=True
263 ${filename}= NexusKeywords.Deploy_Test_Tool netconf netconf-testtool
264 Start_Testtool ${filename} ${device-count} ${debug} ${schemas} ${rpc_config} ${tool_options}
265 ... ${java_options} ${mdsal} log_response=${log_response}
268 [Documentation] Arrange to collect tool's output into a log file.
269 ... Will use specific ${schemas} unless argument resolves to 'none',
270 ... which signifies that there are no additional schemas to be deployed.
271 ... If so the directory for the additional schemas is deleted on the
272 ... remote machine and the additional schemas argument is left out.
273 [Arguments] ${filename} ${device-count}=10 ${debug}=true ${schemas}=none ${rpc_config}=none ${tool_options}=${EMPTY}
274 ... ${java_options}=${TESTTOOL_DEFAULT_JAVA_OPTIONS} ${mdsal}=true ${log_response}=True
275 ${schemas_option}= NetconfKeywords__Deploy_Additional_Schemas ${schemas}
276 ${rpc_config_option}= NetconfKeywords__Deploy_Custom_RPC ${rpc_config}
277 ${command}= NexusKeywords.Compose_Full_Java_Command
278 ... ${java_options} -jar ${filename} ${tool_options} --device-count ${device-count} --debug ${debug} ${schemas_option} ${rpc_config_option} --md-sal ${mdsal}
279 BuiltIn.Log Running testtool: ${command}
280 ${logfile}= Utils.Get_Log_File_Name testtool
281 BuiltIn.Set_Suite_Variable ${testtool_log} ${logfile}
282 SSHLibrary.Write ${command} >${logfile} 2>&1
283 # Store information needed by other keywords.
284 BuiltIn.Set_Suite_Variable ${NetconfKeywords__testtool_device_count} ${device-count}
285 # Wait for the testtool to boot up.
286 Perform_Operation_On_Each_Device NetconfKeywords__Wait_Device_Is_Up_And_Running log_response=${log_response}
288 Check_Device_Up_And_Running
289 [Documentation] Query netstat on remote machine whether testtool device with the specified number has its port open and fail if not.
290 [Arguments] ${device-number}
291 ${device-port}= BuiltIn.Evaluate ${FIRST_TESTTOOL_PORT}+${device-number}-1
292 NetconfKeywords__Check_Device_Is_Up ${device-port}
295 [Documentation] Stop testtool and download its log.
296 RemoteBash.Write_Bare_Ctrl_C
297 SSHLibrary.Read_Until_Prompt
298 # TODO: Unify with play.py and pcc-mock handling.
299 # TODO: Maybe this keyword's content shall be moved into SSHUtils and named somewhat like
300 # "Interrupt_Program_And_Download_Its_Log" which will get an argument stating the name of
301 # the log file to get.
302 SSHLibrary.Get_File ${testtool_log}
304 NetconfKeywords__Check_Netconf_Test_Timeout_Not_Expired
305 [Arguments] ${deadline_Date}
306 IF not ${ENABLE_NETCONF_TEST_TIMEOUT} RETURN
307 ${current_Date}= DateTime.Get_Current_Date
308 ${ellapsed_seconds}= DateTime.Subtract_Date_From_Date ${deadline_Date} ${current_Date}
309 IF ${ellapsed_seconds}<0 Fail The global time out period expired
311 NetconfKeywords__Perform_Operation_With_Checking_On_Next_Device
312 [Arguments] ${operation} ${deadline_Date} ${log_response}=True
313 NetconfKeywords__Check_Netconf_Test_Timeout_Not_Expired ${deadline_Date}
314 ${number}= BuiltIn.Evaluate ${current_port}-${BASE_NETCONF_DEVICE_PORT}+1
315 BuiltIn.Run_Keyword ${operation} ${DEVICE_NAME_BASE}-${number} log_response=${log_response}
316 ${next}= BuiltIn.Evaluate ${current_port}+1
317 BuiltIn.Set_Suite_Variable ${current_port} ${next}
319 Perform_Operation_On_Each_Device
320 [Arguments] ${operation} ${count}=${NetconfKeywords__testtool_device_count} ${timeout}=45m ${log_response}=True
321 ${current_Date}= DateTime.Get_Current_Date
322 ${deadline_Date}= DateTime.Add_Time_To_Date ${current_Date} ${timeout}
323 BuiltIn.Set_Suite_Variable ${current_port} ${BASE_NETCONF_DEVICE_PORT}
324 BuiltIn.Repeat_Keyword
326 ... NetconfKeywords__Perform_Operation_With_Checking_On_Next_Device
329 ... log_response=${log_response}
331 Disable SSE On Controller
332 [Documentation] Sets the config for using SSE (Server Side Events) to false. Note that
333 ... this keyword only changes the config. A controller restart is needed for the config to
335 [Arguments] ${controller_ip}
336 SSHLibrary.Open Connection ${controller_ip}
337 Login With Public Key ${ODL_SYSTEM_USER} ${USER_HOME}/.ssh/${SSH_KEY} any
338 ${cmd}= Set Variable echo "use-sse=false" > ${SSE_CFG_FILE}
339 SSHLibrary.Execute Command ${cmd}
340 SSHLibrary.Close Connection
342 Enable SSE On Controller
343 [Documentation] Sets the config for using SSE (Server Side Events) to true. Note that
344 ... this keyword only changes the config. A controller restart is needed for the config to
346 [Arguments] ${controller_ip}
347 SSHLibrary.Open Connection ${controller_ip}
348 Login With Public Key ${ODL_SYSTEM_USER} ${USER_HOME}/.ssh/${SSH_KEY} any
349 ${cmd}= Set Variable echo "use-sse=true" > ${SSE_CFG_FILE}
350 SSHLibrary.Execute Command ${cmd}
351 SSHLibrary.Close Connection