Fix tox errors
[integration/test.git] / csit / suites / bgpcep / throughpcep / cases.robot
1 *** Settings ***
2 Documentation     PCEP performance suite, uses restconf with configurable authentication.
3 ...
4 ...               Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 ...
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
9 ...
10 ...
11 ...               General Overview:
12 ...
13 ...               This is a suite which has both scale and performance aspects.
14 ...               Given scale target, suite reports failures if functional error
15 ...               is detected, or if various time limits expire.
16 ...               For passing test cases, their duration is the performance metric.
17 ...
18 ...               ODL acts as a translation layer between PCEP capable devices
19 ...               and users employing RESTCONF.
20 ...               Performance measurement focuses on two different workflows.
21 ...
22 ...               The first workflow is initial synchronization, when ODL learns
23 ...               the state of PCEP topology as devices connect to it,
24 ...               while restconf user reads the state repeatedly.
25 ...               The second workflow is mass update, when restconf users issue RPCs
26 ...               to updale Layer Switched Paths on Path Computation Clients.
27 ...
28 ...               This suite uses pcc-mock (downloaded from Nexus) to simulate PCCs.
29 ...               It needs segment of bindable IP addresses,
30 ...               one for each simulated PCC; so running pcc-mock from remote machine
31 ...               is only viable when just single PCC is simulated.
32 ...               Testing with multiple PCCs works best when pcc-mock
33 ...               runs on the same VM as ODL, so 127.0.0.0/8 subnet can be used.
34 ...
35 ...               Library AuthStandalone is used directly for restconf reads
36 ...               in the first workflow. That library transparently handles several
37 ...               http authentication methods, based on credentials and pybot arguments.
38 ...
39 ...               In the second workflow, updater.py utility is used for issuing
40 ...               rapid restconf requests. It can use multiple worker threads,
41 ...               as http requests are blocking.
42 ...               Due to CPython interpreter itself being single threaded,
43 ...               amounts of threads above 8-16 are actually slightly slower
44 ...               (which may roughly correspond to network traffic
45 ...               being more limiting factor than CPU).
46 ...               This suite starts updater utility bound to single CPU,
47 ...               as this setup was the most performant in other tests.
48 ...
49 ...               In case of failed test case, other tests are skipped (unless
50 ...               this is overriden by [Setup]) to finish test run sooner.
51 ...
52 ...               Variables and test case names refer to Controller(ODL_SYSTEM) and Mininet
53 ...               (TOOLS_SYSTEM), those are assumed to be separate remote VMs, one to host ODL,
54 ...               other to host tools.
55 ...               In case updater and pcc-mock are desired to run
56 ...               from separate machines, their parameters use Mininet(TOOLS_SYSTEM)
57 ...               values as default.
58 ...               If both updater VM and pcc-mock VM parameters are specified,
59 ...               Mininet(TOOLS_SYSTEM) parameters may be skipped.
60 ...               Variable ${USE_TOOLS_SYSTEM} decides the pcc-mock running machine.
61 ...
62 ...               Some launch scripts put restrictions on how pybot options
63 ...               can be specified, so there are utility variables to help with
64 ...               copying Controller related value to apply fo updater of pccmock.
65 ...               Having a tool co-located with ODL reduces network latency,
66 ...               but puts more pressure on CPU and memory on Controller VM.
67 ...
68 ...               In some environments, issues with TIME-WAIT prevent high restconf rates,
69 ...               so TCP reuse is temporarily allowed during the suite run, if possible
70 ...               (and if not disabled by UPDATERVM_ENABLE_TCP_RW_REUSE option value).
71 ...               See http://vincent.bernat.im/en/blog/2014-tcp-time-wait-state-linux.html
72 ...               This suite ignores possible failures when changing reuse.
73 ...
74 ...               Similarly, in some environments, handling of requests.Session object matters
75 ...               try changing RESTCONF_REUSE value to see if it helps.
76 ...
77 ...               Variables to override (only if needed) in pybot command:
78 ...               (Look into Variables table to see the default values.)
79 ...
80 ...               FIRST_PCC_IP: Set in case bind address is different from public pcc-mock VM address.
81 ...               LOG_NAME: Filename (without path) to save pcc-mock output into.
82 ...               LOG_PATH: Override if not the same as pccmock VM workspace.
83 ...               LSPS: Number of LSPs per PCC to simulate and test.
84 ...               MOCK_FILE: Filename to use for mock-pcc executable instead of the timestamped one.
85 ...               ODL_SYSTEM_IP: Numeric IP address of VM where ODL runs.
86 ...               ODL_SYSTEM_USER: Username for ssh login to ODL VM.
87 ...               ODL_SYSTEM_PASSWORD: Ssh password, empty means public keys are used instead.
88 ...               ODL_SYSTEM_PROMPT: Substring to identify Linux prompt on ODL VM.
89 ...               ODL_SYSTEM_WORKSPACE: Path to where files can be written on ODL VM.
90 ...               PCCDOWNLOAD_HOSTHEADER: Download server may check checks this header before showing content.
91 ...               PCCDOWNLOAD_URLBASE: URL to pcep-pcc-mock folder in Nexus (use numberic IP if DNS has problems).
92 ...               PCCMOCK_COLOCATED: If True, set PCCMOCKVM* to mirror ODL_SYSTEM*
93 ...               PCCMOCKVM_IP: Override TOOLS_SYSTEM for pcc-mock usage.
94 ...               PCCMOCKVM_*: Override corresponding TOOLS_SYSTEM_* for pcc-mock usage.
95 ...               PCCS: Number of PCCs to simulate and test.
96 ...               PCEP_READY_VERIFY_TIMEOUT: Grace period for pcep-topology to appear. Lower if ODL is ready.
97 ...               RESTCONF_*: USER, PASSWORD and SCOPE to authenticate with, REUSE session.
98 ...               (Note: If SCOPE is not empty, token-based authentication is used.)
99 ...               TOOLS_SYSTEM_IP: Numeric IP address of VM to run pcc-mock and updater from by default.
100 ...               TOOLS_SYSTEM_PASSWORD: Linux password to go with the username (empty means keys).
101 ...               TOOLS_SYSTEM_PROMPT: Substring to identify Linux prompt on TOOLS_SYSTEM VM.
102 ...               TOOLS_SYSTEM_USER: Linux username to SSH to on TOOLS_SYSTEM VM.
103 ...               TOOLS_SYSTEM_WORKSPACE: Path to where files may be created on TOOLS_SYSTEM VM.
104 ...               UPDATER_COLOCATED: If True, overrides UPDATERVM_* parameters to point at ODL_SYSTEM
105 ...               (The purpose is to provide an option without ability to unpack ODL_SYSTEM value.)
106 ...               UPDATER_ODLADDRESS: Override if public ODL_SYSTEM address is not best fit.
107 ...               UPDATER_REFRESH: Main updater thread may sleep this long. Balance precision with overhead.
108 ...               UPDATER_TIMEOUT: If updater stops itself if running more than this time.
109 ...               (Set this limit according to your performance target.)
110 ...               UPDATERVM_ENABLE_TCP_RW_REUSE: Set to false if changing Linux configuration is not desired.
111 ...               UPDATERVM_IP: Override TOOLS_SYSTEM for updater.py usage.
112 ...               UPDATERVM_*: Override corresponding TOOLS_SYSTEM_* for updater.py usage.
113 Suite Setup       FailFast.Do_Not_Fail_Fast_From_Now_On
114 Suite Teardown    Disconnect
115 Test Setup        FailFast.Fail_This_Fast_On_Previous_Error
116 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
117 Library           SSHLibrary    timeout=10s
118 Library           RequestsLibrary
119 Library           ${CURDIR}/../../../libraries/AuthStandalone.py
120 Resource          ${CURDIR}/../../../variables/Variables.robot
121 Resource          ${CURDIR}/../../../libraries/BGPcliKeywords.robot
122 Resource          ${CURDIR}/../../../libraries/FailFast.robot
123 Resource          ${CURDIR}/../../../libraries/NexusKeywords.robot    # for Deploy_Artifact
124 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot    # for Require_* and Assure_*, Flexible_SSH_Login
125
126 *** Variables ***
127 # This Variable decides the pcc mock to run in ODL system or tools system.
128 ${USE_TOOLS_SYSTEM}    False
129 # This table acts as an exhaustive list of variables users can modify on pybot invocation.
130 # It also contains commented-out lines for variables defined elswhere.
131 # Keep this list in alphabetical order.
132 ${BLOCKING-THREAD}    1
133 ${DELAY_TIME}     10
134 ${FIRST_PCC_IP}    ${PCCMOCKVM_IP}
135 # ${LOG_FILE} is reserved for location of pybot-created log.html
136 ${INIT_PCC_DEVICE_COUNT}    ${100}
137 ${LOG_NAME}       throughpcep.log
138 ${LOG_PATH}       ${PCCMOCKVM_WORKSPACE}
139 ${LSPS}           65535
140 #Reduced max pcc device count to 100 for BGPCEP-901
141 ${MAX_PCC_DEVICE_COUNT}    ${100}
142 ${ODL_SYSTEM_WORKSPACE}    /tmp
143 ${PARALLEL_ITERATION}    10
144 ${PCC_DEVICE_INCREMENT}    ${50}
145 ${PCCDOWNLOAD_HOSTHEADER}    nexus.opendaylight.org
146 ${PCCDOWNLOAD_URLBASE}    http://${PCCDOWNLOAD_HOSTHEADER}/content/repositories/opendaylight.snapshot/org/opendaylight/bgpcep/pcep-pcc-mock/
147 ${PCCMOCK_COLOCATED}    False
148 ${PCCMOCKVM_IP}    ${TOOLS_SYSTEM_IP}
149 ${PCCMOCKVM_PASSWORD}    ${TOOLS_SYSTEM_PASSWORD}
150 ${PCCMOCKVM_PROMPT}    ${TOOLS_SYSTEM_PROMPT}
151 ${PCCMOCKVM_USER}    ${TOOLS_SYSTEM_USER}
152 ${PCCMOCKVM_WORKSPACE}    ${TOOLS_SYSTEM_WORKSPACE}
153 ${PCCS}           1
154 ${PCEP_READY_VERIFY_TIMEOUT}    300s
155 # Yes, the default timeout is 5 minutes, as this suite might be started eagerly just after ODL starts booting up.
156 ${RESTCONF_PASSWORD}    ${PWD}    # from Variables.robot
157 ${RESTCONF_REUSE}    True
158 ${RESTCONF_SCOPE}    ${EMPTY}
159 ${RESTCONF_USER}    ${USER}    # from Variables.robot
160 ${SEQUENTIAL_ITERATION}    15
161 ${TOOLS_SYSTEM_WORKSPACE}    /tmp
162 ${UPDATER_COLOCATED}    False
163 ${UPDATER_ODLADDRESS}    ${ODL_SYSTEM_IP}
164 ${UPDATER_REFRESH}    0.1
165 # Updater timeout is overwritten in releng/builder
166 ${UPDATER_TIMEOUT}    300
167 ${UPDATERVM_ENABLE_TCP_RW_REUSE}    True
168 ${UPDATERVM_IP}    ${TOOLS_SYSTEM_IP}
169 ${UPDATERVM_PASSWORD}    ${TOOLS_SYSTEM_PASSWORD}
170 ${UPDATERVM_PROMPT}    ${TOOLS_SYSTEM_PROMPT}
171 ${UPDATERVM_USER}    ${TOOLS_SYSTEM_USER}
172 ${UPDATERVM_WORKSPACE}    ${TOOLS_SYSTEM_WORKSPACE}
173
174 *** Test Cases ***
175 Download_Pcc_Mock
176     [Documentation]    SSH login to pcc-mock VM, download latest pcc-mock executable from Nexus.
177     [Setup]    Select_MOCK_Machine
178     BuiltIn.Run_Keyword_If    ${PCCMOCK_COLOCATED}    Pccmock_From_Controller
179     NexusKeywords.Initialize_Artifact_Deployment_And_Usage    tools_system_connect=False
180     SSHLibrary.Open_Connection    ${PCCMOCKVM_IP}    alias=pccmock
181     SSHLibrary.Set_Client_Configuration    timeout=10s
182     SSHLibrary.Set_Client_Configuration    prompt=${PCCMOCKVM_PROMPT}
183     SSHKeywords.Flexible_SSH_Login    ${PCCMOCKVM_USER}    ${PCCMOCKVM_PASSWORD}    delay=4s
184     ${file_name} =    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
185     BuiltIn.Set_Suite_Variable    ${mock_location}    ${file_name}
186
187 Put_Updater
188     [Documentation]    Open SSH session to updater VM, copy the utility there, including dependencies, also prepare direct http session.
189     BuiltIn.Run_Keyword_If    ${UPDATER_COLOCATED}    Updater_From_Controller
190     SSHLibrary.Open_Connection    ${UPDATERVM_IP}    alias=updater
191     SSHLibrary.Set_Client_Configuration    timeout=20s
192     SSHLibrary.Set_Client_Configuration    prompt=${UPDATERVM_PROMPT}
193     SSHKeywords.Flexible_SSH_Login    ${UPDATERVM_USER}    ${UPDATERVM_PASSWORD}    delay=4s
194     SSHKeywords.Require_Python
195     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/pcep_updater/updater.py    ${UPDATERVM_WORKSPACE}/
196     SSHLibrary.Put_File    ${CURDIR}/../../../libraries/AuthStandalone.py    ${UPDATERVM_WORKSPACE}/
197     SSHKeywords.Assure_Library_Counter    target_dir=${UPDATERVM_WORKSPACE}
198     SSHKeywords.Assure_Library_Ipaddr    target_dir=${UPDATERVM_WORKSPACE}
199     # Done preparation of Updater VM, now use AuthStandalone to create session from robot VM too.
200     BuiltIn.Log_Many    ${RESTCONF_USER}    ${RESTCONF_PASSWORD}    ${RESTCONF_SCOPE}    ${ODL_SYSTEM_IP}
201     ${session} =    AuthStandalone.Init_Session    ${ODL_SYSTEM_IP}    ${RESTCONF_USER}    ${RESTCONF_PASSWORD}    ${RESTCONF_SCOPE}
202     BuiltIn.Set_Suite_Variable    ${rest_session}    ${session}
203     # TODO: Define http timeouts.
204
205 Save_And_Enable_Tcp_Rw_Reuse
206     [Documentation]    If requested, temporarily enable TCP port reuse on Updater VM to allow for high rate of TCP connections. Do not start failing fast.
207     BuiltIn.Pass_Execution_If    not ${UPDATERVM_ENABLE_TCP_RW_REUSE}    Manipulation of tcp_rw_reuse is not requested.
208     ${old_value} =    SSHLibrary.Execute_Command    cat /proc/sys/net/ipv4/tcp_tw_reuse
209     # The next line may be skipped if the previous line failed.
210     BuiltIn.Set_Suite_Variable    ${tcp_rw_reuse}    ${old_value}
211     ${out}    ${rc} =    SSHLibrary.Execute_Command    sudo bash -c "echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse"    return_rc=True
212     BuiltIn.Should_Be_Equal    ${rc}    ${0}
213     # Lack of sudo access should not prevent the rest of suite from trying without TCP reuse.
214     [Teardown]    Do_Not_Start_Failing_If_This_Failed
215
216 Topology_Precondition
217     [Documentation]    Verify that within timeout, PCEP topology is present, with no PCC connected.
218     [Tags]    critical
219     Set_Hop    0
220     Builtin.Wait_Until_Keyword_Succeeds    ${PCEP_READY_VERIFY_TIMEOUT}    1s    Pcep_Off
221     # Yes, timeout is 5 minutes, as this suite might be started eagerly just after ODL starts booting up.
222
223 Topology_Intercondition
224     [Documentation]    Verify that within timeout, PCEP topology contains correct numbers of LSPs.
225     [Tags]    critical
226     [Setup]    Start_Pcc_Mock
227     ${localsize} =    Evaluate    int(${PCCS})*int(${LSPS})
228     Builtin.Set_Suite_Variable    ${size}    ${localsize}
229     BuiltIn.Log    ${size}
230     Builtin.Wait_Until_Keyword_Succeeds    120s    1s    Pcep_On
231     # TODO: Make timeout value scale with ${size}?
232
233 Updater_1
234     [Documentation]    Run updater tool to change hops, using 1 blocking http thread.
235     [Tags]    critical
236     Updater    1    1
237     [Teardown]    Do_Not_Start_Failing_If_This_Failed
238
239 Verify_1
240     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
241     [Tags]    critical
242     Verify    1
243
244 Updater_2
245     [Documentation]    Run updater tool to change hops again, using 2 blocking http threads.
246     [Tags]    critical
247     Updater    2    1
248     [Teardown]    Do_Not_Start_Failing_If_This_Failed
249
250 Verify_2
251     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
252     [Tags]    critical
253     Verify    2
254
255 Updater_3
256     [Documentation]    Run updater tool to change hops again, using 4 blocking http threads.
257     [Tags]    critical
258     Updater    3    4
259     [Teardown]    Do_Not_Start_Failing_If_This_Failed
260
261 Verify_3
262     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
263     [Tags]    critical
264     Verify    3
265
266 Updater_4
267     [Documentation]    Run updater tool to change hops again, using 8 blocking http threads.
268     [Tags]    critical
269     Updater    4    8
270     [Teardown]    Do_Not_Start_Failing_If_This_Failed
271
272 Verify_4
273     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
274     [Tags]    critical
275     Verify    4
276
277 Updater_5
278     [Documentation]    Run updater tool to change hops again, using 16 blocking http threads.
279     [Tags]    critical
280     Updater    5    16
281     [Teardown]    Do_Not_Start_Failing_If_This_Failed
282
283 Verify_5
284     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
285     [Tags]    critical
286     Verify    5
287
288 Updater_6
289     [Documentation]    Run updater tool to change hops again, using 32 blocking http threads.
290     [Tags]    critical
291     Updater    6    32
292     [Teardown]    Do_Not_Start_Failing_If_This_Failed
293
294 Verify_6
295     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
296     [Tags]    critical
297     Verify    6
298
299 Updater_7
300     [Documentation]    Run updater tool to change hops again, using 64 blocking http threads.
301     [Tags]    critical
302     Updater    7    64
303     [Teardown]    Do_Not_Start_Failing_If_This_Failed
304
305 Verify_7
306     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
307     [Tags]    critical
308     Verify    7
309
310 Updater_8
311     [Documentation]    Run updater tool to change hops again, using 128 blocking http threads.
312     [Tags]    critical
313     Updater    8    128
314     [Teardown]    Do_Not_Start_Failing_If_This_Failed
315
316 Verify_8
317     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
318     [Tags]    critical
319     Verify    8
320
321 Updater_9
322     [Documentation]    Run updater tool to change hops again, using 256 blocking http threads.
323     [Tags]    critical
324     Updater    9    256
325     [Teardown]    Do_Not_Start_Failing_If_This_Failed
326
327 Verify_9
328     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
329     [Tags]    critical
330     Verify    9
331
332 Updater_10
333     [Documentation]    Run updater tool to change hops again, using 512 blocking http threads.
334     [Tags]    critical
335     Updater    10    512
336     [Teardown]    Do_Not_Start_Failing_If_This_Failed
337
338 Verify_10
339     [Documentation]    Verify that within timeout, the correct number of new hops is in PCEP topology.
340     [Tags]    critical
341     Verify    10
342
343 Updater_with delegate
344     [Documentation]    Run updater tool to revoke the delegate for the given hop, using 1 blocking http thread.
345     [Tags]    critical
346     Updater    10    1    127.1.0.0    ${PCCS}    ${LSPS}    True    false    127.1.0.1    2
347     Verify    10
348     [Teardown]    Do_Not_Start_Failing_If_This_Failed
349
350 Stop_Pcc_Mock
351     [Documentation]    Send ctrl+c to pcc-mock, see prompt again within timeout.
352     [Setup]    Run_Even_When_Failing_Fast
353     SSHLibrary.Switch_Connection    pccmock
354     BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
355     [Teardown]    Run Keywords    Kill all pcc mock simulator processes    AND    Builtin.Wait_Until_Keyword_Succeeds    ${PCEP_READY_VERIFY_TIMEOUT}    5s    Pcep_Off
356
357 PCEP Sessions Flapped with LSP updates
358     [Documentation]    Flapping PCEP sessions and perform LSP updates within flapping
359     Run Keyword If    '${USE_TOOLS_SYSTEM}' == 'True'    BuiltIn.Pass Execution    Pcc Mock should not run in ODL System
360     FOR    ${devices}    IN RANGE    ${INIT_PCC_DEVICE_COUNT}    ${MAX_PCC_DEVICE_COUNT+1}    ${PCC_DEVICE_INCREMENT}
361         Flap Pcc Mock sessions continuously with LSP updates    127.1.0.0    ${devices}    150
362     END
363     [Teardown]    Run Keywords    Kill all pcc mock simulator processes    AND    BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
364
365 PCEP Sessions Flapped alongside LSP updates
366     [Documentation]    Flapping PCEP sessions and perform LSP updates alongside flapping
367     Run Keyword If    '${USE_TOOLS_SYSTEM}' == 'True'    BuiltIn.Pass Execution    Pcc Mock should not run in ODL System
368     FOR    ${devices}    IN RANGE    ${INIT_PCC_DEVICE_COUNT}    ${MAX_PCC_DEVICE_COUNT+1}    ${PCC_DEVICE_INCREMENT}
369         Flap Pcc Mock sessions parallelly with LSP updates    127.1.0.0    ${devices}    150
370         BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
371     END
372     [Teardown]    Run Keywords    Kill all pcc mock simulator processes    AND    BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
373
374 Download_Pccmock_Log
375     [Documentation]    Transfer pcc-mock output from pcc-mock VM to robot VM.
376     [Setup]    Run_Even_When_Failing_Fast
377     SSHLibrary.Execute Command    zip ${LOG_PATH}/mock_log.zip /tmp/throughpcep*
378     SSHLibrary.Get_File    ${LOG_PATH}/mock_log.zip    mock_log.zip
379
380 Topology_Postcondition
381     [Documentation]    Verify that within timeout, PCEP topology contains no PCCs again.
382     [Tags]    critical
383     [Setup]    Run_Even_When_Failing_Fast
384     Builtin.Wait_Until_Keyword_Succeeds    90s    5s    Pcep_Off_Again
385
386 Restore_Tcp_Rw_Reuse
387     [Documentation]    If requested, restore the old value if enabling TCP reuse was successful on Updater VM.
388     [Setup]    Run_Even_When_Failing_Fast
389     BuiltIn.Pass_Execution_If    not ${UPDATERVM_ENABLE_TCP_RW_REUSE}    Manipulation of tcp_rw_reuse is not requested.
390     SSHLibrary.Switch_Connection    updater
391     BuiltIn.Variable_Should_Exist    ${tcp_rw_reuse}
392     ${out}    ${rc} =    SSHLibrary.Execute_Command    sudo bash -c "echo ${tcp_rw_reuse} > /proc/sys/net/ipv4/tcp_tw_reuse"    return_rc=True
393     BuiltIn.Should_Be_Equal    ${rc}    ${0}
394
395 *** Keywords ***
396 Select_MOCK_Machine
397     [Documentation]    Check the tools system variable and assigns the PCC Mock
398     Run Keyword If    '${USE_TOOLS_SYSTEM}' == 'False'    Run Keywords    Pccmock_From_Odl_System    AND    Updater_From_Odl_System
399     BuiltIn.Set_Suite_Variable    ${FIRST_PCC_IP}    ${PCCMOCKVM_IP}
400
401 Start_Pcc_Mock
402     [Arguments]    ${mock-ip}=${FIRST_PCC_IP}    ${pccs}=${PCCS}    ${lsps}=${LSPS}    ${log_name}=${LOG_NAME}
403     [Documentation]    Launch pcc-mock on background so simulated PCCs start connecting to controller.
404     SSHLibrary.Switch_Connection    pccmock
405     ${command} =    NexusKeywords.Compose_Full_Java_Command    -jar ${mock_location} --local-address ${mock-ip} --remote-address ${ODL_SYSTEM_IP} --pcc ${pccs} --lsp ${lsps} &> ${LOG_PATH}/${log_name}
406     BuiltIn.Log    ${command}
407     SSHLibrary.Write    ${command}
408     # The pccmock SSH session is left alive, but no data will be exchanged for a while.
409     # We need this connection to stay alive to send ctrl+c later.
410     # SSHLibrary.Start_Command would not do that for us.
411
412 Pccmock_From_Odl_System
413     [Documentation]    Copy Odl_System values to Pccmock VM variables.
414     BuiltIn.Set_Suite_Variable    ${PCCMOCKVM_IP}    ${ODL_SYSTEM_IP}
415     BuiltIn.Set_Suite_Variable    ${PCCMOCKVM_PASSWORD}    ${ODL_SYSTEM_PASSWORD}
416     BuiltIn.Set_Suite_Variable    ${PCCMOCKVM_PROMPT}    ${ODL_SYSTEM_PROMPT}
417     BuiltIn.Set_Suite_Variable    ${PCCMOCKVM_WORKSPACE}    ${ODL_SYSTEM_WORKSPACE}
418     BuiltIn.Set_Suite_Variable    ${LOG_PATH}    ${ODL_SYSTEM_WORKSPACE}
419
420 Updater_From_Odl_System
421     [Documentation]    Copy Odl_System values to Uprater VM variables.
422     BuiltIn.Set_Suite_Variable    ${UPDATERVM_IP}    ${ODL_SYSTEM_IP}
423     BuiltIn.Set_Suite_Variable    ${UPDATERVM_PASSWORD}    ${ODL_SYSTEM_PASSWORD}
424     BuiltIn.Set_Suite_Variable    ${UPDATERVM_PROMPT}    ${ODL_SYSTEM_PROMPT}
425     BuiltIn.Set_Suite_Variable    ${UPDATERVM_WORKSPACE}    ${ODL_SYSTEM_WORKSPACE}
426
427 Disconnect
428     [Documentation]    Explicitly close all SSH connections.
429     SSHLibrary.Close_All_Connections
430     # TODO: Make AuthStandalone session object closable?
431
432 Get_Pcep_Topology_Data
433     [Documentation]    Use session object to download PCEP topology JSON. Check status and return Response object.
434     ${resp} =    AuthStandalone.Get_Using_Session    ${rest_session}    operational/network-topology:network-topology/topology/pcep-topology
435     # Not Logging content, as it may be huge.
436     BuiltIn.Should_Be_Equal    ${resp.status_code}    ${200}
437     [Return]    ${resp}
438
439 Get_Pcep_Topology_Count
440     [Arguments]    ${pattern}
441     [Documentation]    Get topology data, return number of pattern matches.
442     ${resp} =    Get_Pcep_Topology_Data
443     # BuiltIn.Log    ${resp.text}
444     ${count} =    BuiltIn.Evaluate    len(re.findall('${pattern}', '''${resp.text}'''))    modules=re
445     BuiltIn.Log    ${count}
446     [Return]    ${count}
447
448 Pcep_Off
449     [Documentation]    Get topology data, Log content and assert the exact JSON of empty topology.
450     ${resp} =    Get_Pcep_Topology_Data
451     # Used before topology had chance to grow huge. Be aware when creating a longevity suite from this.
452     BuiltIn.Log    ${resp.text}
453     BuiltIn.Should_Be_Equal    ${resp.text}    {"topology":[{"topology-id":"pcep-topology","topology-types":{"network-topology-pcep:topology-pcep":{}}}]}
454
455 Pcep_On
456     [Documentation]    Get topology count of current hop, assert the number of matches.
457     # Suite variables ${size} and ${hop} are set elsewhere.
458     ${resp} =    Get_Pcep_Topology_Count    ${hop}
459     BuiltIn.Should_Be_Equal    ${resp}    ${size}
460
461 Pcep_Off_Again
462     [Documentation]    Get topology count of final hop, assert there is none.
463     ...    This is more log friendly than Pcep_Off keyword, as it does not Log possibly large content.
464     Set_Hop    0
465     ${resp} =    Get_Pcep_Topology_Count    ${hop}
466     BuiltIn.Should_Be_Equal    ${resp}    ${0}
467
468 Set_Hop
469     [Arguments]    ${iteration}
470     [Documentation]    Set pattern to match the currently expected hop.
471     ${i} =    BuiltIn.Evaluate    str(1 + int(${iteration}))
472     # Regular Expressions need a dot to be escaped to represent a dot.
473     BuiltIn.Set_Suite_Variable    ${hop}    ${i}\.${i}\.${i}\.${i}/32
474     BuiltIn.Log    ${hop}
475
476 Updater
477     [Arguments]    ${iteration}    ${workers}    ${mock-ip}=${FIRST_PCC_IP}    ${pccs}=${PCCS}    ${lsps}=${LSPS}    ${parallel}=False    ${delegate}=true    ${pccip}=${none}    ${tunnel_no}=${none}
478     [Documentation]    Compute number of workers, call updater.py, assert its response.
479     SSHLibrary.Switch_Connection    pccmock
480     # In some systems, inactive SSH sessions get severed.
481     ${command} =    BuiltIn.Set_Variable    echo "still alive"
482     ${output} =    SSHLibrary.Execute_Command    bash -c '${command}'
483     # The previous line relies on a fact that Execute_Command spawns separate shels, so running pcc-mock is not affected.
484     Set_Hop    ${iteration}
485     SSHLibrary.Switch_Connection    updater
486     ${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"
487     Check Updater response    ${response}    ${parallel}
488
489 Check Updater response
490     [Arguments]    ${response}    ${parallel}
491     BuiltIn.Log    ${response}
492     ${expected_value_continuous_execution} =    BuiltIn.Set_Variable    Counter({'pass': ${size}})
493     ${not_expected_value_for_parallel_execution} =    BuiltIn.Set_Variable    Counter({'pass': 0})
494     BuiltIn.Log    ${expected_value_continuous_execution}
495     Run Keyword If    '${parallel}' == 'False'    BuiltIn.Should_Contain    ${response}    ${expected_value_continuous_execution}
496     ...    ELSE    BuiltIn.Should_Not_Contain    ${response}    ${not_expected_value_for_parallel_execution}
497
498 Verify
499     [Arguments]    ${iteration}
500     [Documentation]    Set hop and verify that within timeout, all LSPs in topology are updated.
501     Set_Hop    ${iteration}
502     Builtin.Wait_Until_Keyword_Succeeds    30s    1s    Pcep_On
503
504 Flap Pcc Mock sessions continuously with LSP updates
505     [Arguments]    ${mock-ip}=${FIRST_PCC_IP}    ${pccs}=${PCCS}    ${lsps}=${LSPS}
506     ${localsize} =    Evaluate    int(${pccs})*int(${lsps})
507     Builtin.Set_Suite_Variable    ${size}    ${localsize}
508     ${workers} =    Set Variable    ${BLOCKING-THREAD}
509     FOR    ${i}    IN RANGE    ${SEQUENTIAL_ITERATION}
510         ${workers} =    Evaluate    ${workers}*${workers}
511         Set_Hop    0
512         Builtin.Wait_Until_Keyword_Succeeds    ${PCEP_READY_VERIFY_TIMEOUT}    5s    Pcep_Off
513         Start_Pcc_Mock    ${mock-ip}    ${pccs}    ${lsps}    serial_execution.log
514         Builtin.Wait_Until_Keyword_Succeeds    60s    5s    Pcep_On
515         ${i} =    Evaluate    ${i}+1
516         Updater    ${i}    ${workers}    127.1.0.0    ${pccs}    ${lsps}
517         Verify    ${i}
518         SSHLibrary.Switch_Connection    pccmock
519         BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
520     END
521     Check PCEP is stable
522
523 Flap Pcc Mock sessions parallelly with LSP updates
524     [Arguments]    ${mock-ip}=${FIRST_PCC_IP}    ${pccs}=${PCCS}    ${lsps}=${LSPS}
525     SSHLibrary.Switch_Connection    pccmock
526     SSHLibrary.Put File    ${CURDIR}/../../../../tools/pcep_updater/mock.sh    /tmp/mock.sh
527     Set_Hop    0
528     Builtin.Wait_Until_Keyword_Succeeds    ${PCEP_READY_VERIFY_TIMEOUT}    5s    Pcep_Off
529     SSHLibrary.Start Command    sh /tmp/mock.sh ${mock_location} ${mock-ip} ${ODL_SYSTEM_IP} ${pccs} ${lsps} parallel_Execution ${DELAY_TIME} &>1
530     FOR    ${i}    IN RANGE    ${PARALLEL_ITERATION}
531         ${pid} =    SSHLibrary.Execute Command    ps -fu ${ODL_SYSTEM_USER} | grep "/home/${ODL_SYSTEM_USER}/${mock_location}" | grep -v "grep" | awk '{print $2}'
532         Run Keyword If    '${pid}'!= ""    Log    ${pid}
533         ${i} =    Evaluate    ${i}+1
534         Run Keyword If    '${pid}'!= ""    Updater    ${i}    1    127.1.0.0    ${pccs}    ${lsps}    True
535     END
536     BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
537     Kill all pcc mock simulator processes
538     Check PCEP is stable
539
540 Check PCEP is stable
541     [Documentation]    Check PCEP topology with default pcc and lsp values
542     ${localsize} =    Evaluate    int(${PCCS})*int(${LSPS})
543     Builtin.Set_Suite_Variable    ${size}    ${localsize}
544     Builtin.Wait_Until_Keyword_Succeeds    90s    5s    Pcep_Off_Again
545     Start_Pcc_Mock
546     Builtin.Wait_Until_Keyword_Succeeds    60s    5s    Pcep_On
547     Updater    2    1
548     Verify    2
549     SSHLibrary.Switch_Connection    pccmock
550     BGPcliKeywords.Stop_Console_Tool_And_Wait_Until_Prompt
551
552 Kill all pcc mock simulator processes
553     SSHLibrary.Switch_Connection    pccmock
554     ${mock_pid}    Get pid    /home/${ODL_SYSTEM_USER}/${mock_location}
555     SSHLibrary.Execute_Command    kill -9 ${mock_pid}
556     ${script_pid_1}    Get pid    bash -c sh /tmp/mock.sh
557     SSHLibrary.Execute_Command    kill -9 ${script_pid_1}
558     ${script_pid_2}    Get pid    sh /tmp/mock.sh
559     SSHLibrary.Execute_Command    kill -9 ${script_pid_2}
560
561 Get pid
562     [Arguments]    ${process_name}
563     ${pid} =    SSHLibrary.Execute Command    ps -fu ${ODL_SYSTEM_USER} | grep "${process_name}" | grep -v "grep" | awk '{print $2}'
564     [Return]    ${pid}