Remove remnants of sfc project
[integration/test.git] / csit / libraries / KarafKeywords.robot
1 *** Settings ***
2 Documentation       Karaf library. General utility keywords for interacting with the karaf environment, such as the
3 ...                 karaf console, karaf.log, karaf features, and karaf config files.
4 ...
5 ...                 This library is useful to deal with controller Karaf console for ssh sessions in cluster.
6 ...                 Running Setup_Karaf_Keywords is necessary. If SetupUtils initialization is called, this gets initialized as well.
7 ...                 If this gets initialized, ClusterManagement gets initialized as well.
8
9 Library             SSHLibrary
10 Library             OperatingSystem
11 Resource            ${CURDIR}/ClusterManagement.robot
12 Resource            ${CURDIR}/SSHKeywords.robot
13 Variables           ${CURDIR}/../variables/Variables.py
14
15
16 *** Variables ***
17 ${WORKSPACE}                /tmp
18 ${connection_index_dict}    &{EMPTY}
19
20
21 *** Keywords ***
22 Setup_Karaf_Keywords
23     [Documentation]    Initialize ClusterManagement. Open ssh karaf connections to each ODL.
24     [Arguments]    ${http_timeout}=${DEFAULT_TIMEOUT_HTTP}
25     ClusterManagement.ClusterManagement_Setup    http_timeout=${http_timeout}
26     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
27     ClusterManagement.Run_Bash_Command_On_List_Or_All
28     ...    iptables -I INPUT -p tcp --dport ${KARAF_SHELL_PORT} -j ACCEPT; iptables-save
29     BuiltIn.Comment    First connections to Karaf console may fail, so WUKS is used. TODO: Track as a Bug.
30     FOR    ${index}    IN    @{ClusterManagement__member_index_list}
31         BuiltIn.Run_Keyword_And_Ignore_Error
32         ...    BuiltIn.Wait_Until_Keyword_Succeeds
33         ...    3s
34         ...    1s
35         ...    Open_Controller_Karaf_Console_On_Background
36         ...    member_index=${index}
37     END
38
39 Verify_Feature_Is_Installed
40     [Documentation]    Will Succeed if the given ${feature_name} is found in the output of "feature:list -i"
41     [Arguments]    ${feature_name}    ${controller}=${ODL_SYSTEM_IP}    ${karaf_port}=${KARAF_SHELL_PORT}
42     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
43     ${output} =    Issue_Command_On_Karaf_Console
44     ...    feature:list -i | grep ${feature_name}
45     ...    ${controller}
46     ...    ${karaf_port}
47     BuiltIn.Should_Contain    ${output}    ${feature_name}
48     RETURN    ${output}
49
50 Issue_Command_On_Karaf_Console
51     [Documentation]    Will execute the given ${cmd} by ssh'ing to the karaf console running on ${controller}
52     ...    Note that this keyword will open&close new SSH connection, without switching back to previously current session.
53     [Arguments]    ${cmd}    ${controller}=${ODL_SYSTEM_IP}    ${karaf_port}=${KARAF_SHELL_PORT}    ${timeout}=10    ${loglevel}=INFO
54     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
55     SSHLibrary.Open_Connection
56     ...    ${controller}
57     ...    port=${karaf_port}
58     ...    prompt=${KARAF_PROMPT_LOGIN}
59     ...    timeout=${timeout}
60     SSHLibrary.Login    ${KARAF_USER}    ${KARAF_PASSWORD}    loglevel=${loglevel}
61     SSHLibrary.Write    ${cmd}
62     ${output} =    SSHLibrary.Read_Until_Regexp    ${KARAF_PROMPT}
63     SSHLibrary.Write_Bare    logout\n
64     SSHLibrary.Close_Connection
65     BuiltIn.Log    ${output}
66     RETURN    ${output}
67
68 Safe_Issue_Command_On_Karaf_Console
69     [Documentation]    Run Issue_Command_On_Karaf_Console but restore previous connection afterwards.
70     [Arguments]    ${cmd}    ${controller}=${ODL_SYSTEM_IP}    ${karaf_port}=${KARAF_SHELL_PORT}    ${timeout}=10    ${loglevel}=INFO
71     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
72     BuiltIn.Run_Keyword_And_Return
73     ...    SSHKeywords.Run_Keyword_Preserve_Connection
74     ...    Issue_Command_On_Karaf_Console
75     ...    ${cmd}
76     ...    ${controller}
77     ...    ${karaf_port}
78     ...    ${timeout}
79     ...    ${loglevel}
80
81 Check For Elements On Karaf Command Output Message
82     [Documentation]    Will execute the command using Issue Command On Karaf Console then check for the given elements
83     ...    in the command output message
84     [Arguments]    ${cmd}    ${elements}    ${controller}=${ODL_SYSTEM_IP}    ${karaf_port}=${KARAF_SHELL_PORT}    ${timeout}=5
85     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
86     ${output} =    Issue_Command_On_Karaf_Console    ${cmd}    ${controller}    ${karaf_port}    ${timeout}
87     FOR    ${i}    IN    @{elements}
88         BuiltIn.Should_Contain    ${output}    ${i}
89     END
90
91 Verify_Bundle_Is_Installed
92     [Documentation]    Will succeed if the given ${bundle name} is present in the output of "bundle:list -s "
93     [Arguments]    ${bundle_name}    ${controller}=${ODL_SYSTEM_IP}    ${karaf_port}=${KARAF_SHELL_PORT}
94     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
95     ${output} =    Issue_Command_On_Karaf_Console
96     ...    bundle:list -s | grep ${bundle_name}
97     ...    ${controller}
98     ...    ${karaf_port}
99     BuiltIn.Should_Contain    ${output}    ${bundle_name}
100     RETURN    ${output}
101
102 Verify_Bundle_Is_Not_Installed
103     [Documentation]    Will succeed if the given ${bundle_name} is NOT found in the output of "bundle:list -s"
104     [Arguments]    ${bundle_name}    ${controller}=${ODL_SYSTEM_IP}    ${karaf_port}=${KARAF_SHELL_PORT}
105     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
106     ${output} =    Issue_Command_On_Karaf_Console
107     ...    bundle:list -i | grep ${bundle_name}
108     ...    ${controller}
109     ...    ${karaf_port}
110     BuiltIn.Should_Not_Contain    ${output}    ${bundle_name}
111     RETURN    ${output}
112
113 Check_Karaf_Log_Has_Messages
114     [Documentation]    Will succeed if the @{messages} are found in \ the output of "log:display"
115     [Arguments]    ${filter_string}    @{message_list}
116     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
117     ${output} =    Issue_Command_On_Karaf_Console    log:display | grep ${filter_string}
118     FOR    ${message}    IN    @{message_list}
119         BuiltIn.Should_Contain    ${output}    ${message}
120     END
121     RETURN    ${output}
122
123 Check_Karaf_Log_Message_Count
124     [Documentation]    Verifies that the ${message} exists specified number of times in
125     ...    karaf console log or Karaf Log Folder based on the arg ${use_console}.
126     [Arguments]    ${message}    ${count}    ${use_console}=False
127     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
128     IF    ${use_console} == False
129         Check_Karaf_Log_File    ${message}    ${count}
130     ELSE
131         Check_Karaf_Log_From_Console    ${message}    ${count}
132     END
133
134 Check_Karaf_Log_From_Console
135     [Documentation]    Verifies that the ${message} exists in the Karaf Console log:display and checks
136     ...    that it appears ${count} number of times
137     [Arguments]    ${message}    ${count}
138     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
139     ${output} =    Issue_Command_On_Karaf_Console    log:display | grep ${message} | wc -l
140     ${line} =    Get Line    ${output}    0
141     ${stripped} =    Strip String    ${line}
142     Should Be Equal As Strings    ${stripped}    ${count}
143
144 Check_Karaf_Log_File
145     [Documentation]    Verifies that the ${message} exists in the Karaf Log Folder and checks
146     ...    that it appears ${count} number of times
147     [Arguments]    ${message}    ${count}
148     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
149     ${output} =    Run Command On Controller
150     ...    ${ODL_SYSTEM_IP}
151     ...    grep -o ${message} ${WORKSPACE}/${BUNDLEFOLDER}/data/log/* | wc -l
152     Should Be Equal As Strings    ${output}    ${count}
153
154 Install_A_Feature
155     [Documentation]    Will Install the given ${feature_name}
156     [Arguments]    ${feature_name}    ${controller}=${ODL_SYSTEM_IP}    ${karaf_port}=${KARAF_SHELL_PORT}    ${timeout}=180
157     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
158     BuiltIn.Log    ${timeout}
159     ${output} =    Issue_Command_On_Karaf_Console
160     ...    feature:install ${feature_name}
161     ...    ${controller}
162     ...    ${karaf_port}
163     ...    ${timeout}
164     BuiltIn.Log    ${output}
165     RETURN    ${output}
166
167 Install_A_Feature_Using_Active_Connection
168     [Documentation]    Will Install the given ${feature_name} using active connection
169     [Arguments]    ${feature_name}
170     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
171     ${cmd} =    BuiltIn.Set_Variable    feature:install ${feature_name}
172     SSHLibrary.Write    ${cmd}
173     ${output} =    SSHLibrary.Read_Until_Regexp    ${KARAF_PROMPT}
174     BuiltIn.Log    ${output}
175     RETURN    ${output}
176
177 Uninstall_A_Feature
178     [Documentation]    Will UnInstall the given ${feature_name}
179     [Arguments]    ${feature_name}    ${controller}=${ODL_SYSTEM_IP}    ${karaf_port}=${KARAF_SHELL_PORT}    ${timeout}=180
180     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
181     ${output} =    Issue_Command_On_Karaf_Console
182     ...    feature:uninstall ${feature_name}
183     ...    ${controller}
184     ...    ${karaf_port}
185     ...    ${timeout}
186     BuiltIn.Log    ${output}
187     RETURN    ${output}
188
189 Open_Controller_Karaf_Console_On_Background
190     [Documentation]    If there is a stored ssh connection index of connection to the controller's karaf console for ${member_index},
191     ...    close the previous connection. In any case create a new connection
192     ...    to karaf console for ${member_index}, set correct prompt set and login to karaf console.
193     ...    Store connection index for ${member_index} and restore the previous active connection.
194     [Arguments]    ${member_index}=${1}    ${timeout}=10    ${loglevel}=INFO
195     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
196     ${current_ssh_connection_object} =    SSHLibrary.Get_Connection
197     BuiltIn.Log    ${connection_index_dict}
198     BuiltIn.Log    ${member_index}
199     ${status}    ${old_connection_index} =    BuiltIn.Run_Keyword_And_Ignore_Error
200     ...    Get From Dictionary
201     ...    ${connection_index_dict}
202     ...    ${member_index}
203     IF    '${status}'=='PASS'
204         BuiltIn.Run_Keywords
205         ...    SSHLibrary.Switch_Connection
206         ...    ${old_connection_index}
207         ...    AND
208         ...    BuiltIn.Run_Keyword_And_Ignore_Error
209         ...    SSHLibrary.Write
210         ...    logout
211         ...    AND
212         ...    BuiltIn.Run_Keyword_And_Ignore_Error
213         ...    SSHLibrary.Close_Connection
214     END
215     ${odl_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${member_index}
216     SSHLibrary.Open_Connection
217     ...    ${odl_ip}
218     ...    port=${KARAF_SHELL_PORT}
219     ...    prompt=${KARAF_PROMPT_LOGIN}
220     ...    timeout=${timeout}
221     ${karaf_connection_object} =    SSHLibrary.Get_Connection
222     Collections.Set_To_Dictionary    ${connection_index_dict}    ${member_index}    ${karaf_connection_object.index}
223     SSHLibrary.Login    ${KARAF_USER}    ${KARAF_PASSWORD}    loglevel=${loglevel}
224     [Teardown]    Run Keyword If    '${IS_KARAF_APPL}' == 'True'    SSHKeywords.Restore_Current_Ssh_Connection_From_Index    ${current_ssh_connection_object.index}
225
226 Open_Controller_Karaf_Console_With_Timeout
227     [Documentation]    Open new connection to karaf console for member index with specified timeout.
228     [Arguments]    ${member_index}=${1}    ${timeout}=3s
229     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
230     BuiltIn.Log    ${member_index}
231     ${odl_ip} =    ClusterManagement.Resolve_IP_Address_For_Member    ${member_index}
232     SSHLibrary.Open_Connection
233     ...    ${odl_ip}
234     ...    port=${KARAF_SHELL_PORT}
235     ...    prompt=${KARAF_PROMPT_LOGIN}
236     ...    timeout=${timeout}
237     SSHLibrary.Login    ${KARAF_USER}    ${KARAF_PASSWORD}
238
239 Configure_Timeout_For_Karaf_Console
240     [Documentation]    Configure a different timeout for each Karaf console.
241     [Arguments]    ${timeout}    ${member_index_list}=${EMPTY}
242     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
243     ${index_list} =    ClusterManagement.List_Indices_Or_All    given_list=${member_index_list}
244     ${current_connection_object} =    SSHLibrary.Get_Connection
245     FOR    ${member_index}    IN    @{index_list}    # usually: 1, 2, 3
246         ${karaf_connection_index} =    Collections.Get_From_Dictionary    ${connection_index_dict}    ${member_index}
247         SSHLibrary.Switch_Connection    ${karaf_connection_index}
248         SSHLibrary.Set_Client_Configuration    timeout=${timeout}
249     END
250     [Teardown]    Run Keyword If    '${IS_KARAF_APPL}' == 'True'    SSHKeywords.Restore_Current_Ssh_Connection_From_Index    ${current_connection_object.index}
251
252 Execute_Controller_Karaf_Command_On_Background
253     [Documentation]    Send command to karaf without affecting current SSH connection. Read, log and return response.
254     [Arguments]    ${command}    ${member_index}=${1}
255     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
256     ${karaf_connection_index} =    Collections.Get_From_Dictionary    ${connection_index_dict}    ${member_index}
257     ${current_connection_index} =    SSHLibrary.Switch_Connection    ${karaf_connection_index}
258     ${status_write}    ${message_write} =    BuiltIn.Run_Keyword_And_Ignore_Error    SSHLibrary.Write    ${command}
259     ${status_wait}    ${message_wait} =    BuiltIn.Run_Keyword_And_Ignore_Error
260     ...    SSHLibrary.Read_Until_Regexp
261     ...    ${KARAF_PROMPT}
262     IF    '${status_write}' != 'PASS'
263         BuiltIn.Fail    Failed to send the command: ${command}
264     END
265     BuiltIn.Log    ${message_wait}
266     IF    '${status_wait}' != 'PASS'
267         BuiltIn.Fail    Failed to see prompt after sending the command: ${command}
268     END
269     RETURN    ${message_wait}
270     [Teardown]    Run Keyword If    '${IS_KARAF_APPL}' == 'True'    SSHKeywords.Restore_Current_Ssh_Connection_From_Index    ${current_connection_index}
271
272 Execute_Controller_Karaf_Command_With_Retry_On_Background
273     [Documentation]    Attemp to send command to karaf for ${member_index}, if fail then open connection and try again.
274     [Arguments]    ${command}    ${member_index}=${1}
275     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
276     ${status}    ${message} =    BuiltIn.Run_Keyword_And_Ignore_Error
277     ...    Execute_Controller_Karaf_Command_On_Background
278     ...    ${command}
279     ...    ${member_index}
280     IF    '${status}' == 'PASS'    RETURN    ${message}
281     # TODO: Verify this does not leak connections indices.
282     Open_Controller_Karaf_Console_On_Background    ${member_index}
283     ${message} =    Execute_Controller_Karaf_Command_On_Background    ${command}    ${member_index}
284     RETURN    ${message}
285
286 Log_Message_To_Controller_Karaf
287     [Documentation]    Make sure this resource is initialized. Send a message into the controller's karaf log file on every node listed (or all).
288     ...    By default, failure while processing a node is silently ignored, unless ${tolerate_failure} is False.
289     [Arguments]    ${message}    ${member_index_list}=${EMPTY}    ${tolerate_failure}=True
290     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
291     ${index_list} =    ClusterManagement.List_Indices_Or_All    given_list=${member_index_list}
292     FOR    ${index}    IN    @{index_list}    # usually: 1, 2, 3.
293         ${status}    ${output} =    BuiltIn.Run_Keyword_And_Ignore_Error
294         ...    Execute_Controller_Karaf_Command_With_Retry_On_Background
295         ...    log:log "ROBOT MESSAGE: ${message}"
296         ...    member_index=${index}
297         IF    not ${tolerate_failure} and "${status}" != "PASS"
298             BuiltIn.Fail    ${output}
299         END
300     END
301
302 Log_Test_Suite_Start_To_Controller_Karaf
303     [Documentation]    Log suite name to karaf log, useful in suite setup.
304     [Arguments]    ${member_index_list}=${EMPTY}
305     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
306     Log_Message_To_Controller_Karaf    Starting suite ${SUITE_SOURCE}    ${member_index_list}
307
308 Log_Testcase_Start_To_Controller_Karaf
309     [Documentation]    Log test case name to karaf log, useful in test case setup.
310     [Arguments]    ${member_index_list}=${EMPTY}
311     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
312     Log_Message_To_Controller_Karaf    Starting test ${SUITE_NAME}.${TEST_NAME}    ${member_index_list}
313
314 Set_Bgpcep_Log_Levels
315     [Documentation]    Assuming OCKCOB was used, set logging level on bgpcep and protocol loggers without affecting current SSH session.
316     [Arguments]    ${bgpcep_level}=${DEFAULT_BGPCEP_LOG_LEVEL}    ${protocol_level}=${DEFAULT_PROTOCOL_LOG_LEVEL}    ${member_index_list}=${EMPTY}
317     # FIXME: Move to appropriate Resource
318     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
319     ${index_list} =    ClusterManagement.List_Indices_Or_All    given_list=${member_index_list}
320     FOR    ${index}    IN    @{index_list}    # usually: 1, 2, 3.
321         Execute_Controller_Karaf_Command_On_Background
322         ...    log:set ${bgpcep_level} org.opendaylight.bgpcep
323         ...    member_index=${index}
324         Execute_Controller_Karaf_Command_On_Background
325         ...    log:set ${protocol_level} org.opendaylight.protocol
326         ...    member_index=${index}
327     END
328
329 Get Karaf Log Lines From Test Start
330     [Documentation]    Scrapes all log messages that match regexp ${type} which fall after a point given by a log message that
331     ...    contains ${test_name}. This is useful if your test cases are marking karaf.log with a message indicating when
332     ...    that test case has started; such that you can easily pull out any extra log messsages to parse/log/etc in the
333     ...    test logic itself. For example, you can grab all ERRORS that occur during your test case.
334     [Arguments]    ${ip}    ${test_name}    ${cmd}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
335     ...    ${log_file}=${KARAF_LOG}
336     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
337     ${output} =    Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
338     @{log_lines} =    Split String    ${output}    ${\n}
339     RETURN    ${log_lines}
340
341 Fail If Exceptions Found During Test
342     [Documentation]    Create a failure if an Exception is found in the karaf.log that has not been whitelisted.
343     ...    Will work for single controller jobs as well as 3node cluster jobs
344     [Arguments]    ${test_name}    ${log_file}=${KARAF_LOG}    ${fail}=False
345     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
346     FOR    ${i}    IN RANGE    1    ${NUM_ODL_SYSTEM} + 1
347         ${cmd} =    Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file}
348         ${output} =    Get Karaf Log Lines From Test Start    ${ODL_SYSTEM_${i}_IP}    ${test_name}    ${cmd}
349         ${exlist}    ${matchlist} =    Verify Exceptions    ${output}
350         Write Exceptions Map To File    ${SUITE_NAME}.${TEST_NAME}    /tmp/odl${i}_exceptions.txt
351         ${listlength} =    BuiltIn.Get Length    ${exlist}
352         IF    "${fail}"=="True" and ${listlength} != 0
353             Log And Fail Exceptions    ${exlist}    ${listlength}
354         ELSE
355             Collections.Log List    ${matchlist}
356         END
357     END
358
359 Log And Fail Exceptions
360     [Documentation]    Print the list of failed exceptions and fail the test
361     [Arguments]    ${exlist}    ${listlength}
362     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
363     Collections.Log List    ${exlist}
364     ${exstr} =    BuiltIn.Catenate    ${exlist}
365     BuiltIn.Fail    New exceptions found: ${listlength}\n${exstr}
366
367 Get Karaf Log Type From Test Start
368     [Documentation]    Scrapes all log messages that match regexp ${type} which fall after a point given by a log message that
369     ...    contains ${test_name}. This is useful if your test cases are marking karaf.log with a message indicating when
370     ...    that test case has started; such that you can easily pull out any extra log messsages to parse/log/etc in the
371     ...    test logic itself. For example, you can grab all ERRORS that occur during your test case.
372     [Arguments]    ${ip}    ${test_name}    ${type}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
373     ...    ${log_file}=${KARAF_LOG}
374     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
375     ${cmd} =    Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
376     ${output} =    Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
377     RETURN    ${output}
378
379 Get Karaf Log Types From Test Start
380     [Documentation]    A wrapper keyword for "Get Karaf Log Type From Test Start" so that we can parse for multiple types
381     ...    of log messages. For example, we can grab all messages of type WARN and ERROR
382     [Arguments]    ${ip}    ${test_name}    ${types}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
383     ...    ${log_file}=${KARAF_LOG}
384     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
385     FOR    ${type}    IN    @{types}
386         Get Karaf Log Type From Test Start    ${ip}    ${test_name}    ${type}    ${user}    ${password}
387         ...    ${prompt}    ${log_file}
388     END
389
390 Get Karaf Log Events From Test Start
391     [Documentation]    Wrapper for the wrapper "Get Karaf Log Types From Test Start" so that we can easily loop over
392     ...    any number of controllers to analyze karaf.log for ERROR, WARN and Exception log messages
393     [Arguments]    ${test_name}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
394     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
395     ${log_types} =    Create List    ERROR    WARN    Exception
396     FOR    ${i}    IN RANGE    1    ${NUM_ODL_SYSTEM} + 1
397         Get Karaf Log Types From Test Start    ${ODL_SYSTEM_${i}_IP}    ${test_name}    ${log_types}
398     END
399
400 Fail If Exceptions Found During Test Deprecated
401     [Documentation]    Create a failure if an Exception is found in the karaf.log. Will work for single controller jobs
402     ...    as well as 3node cluster jobs
403     [Arguments]    ${test_name}    ${exceptions_white_list}=${EMPTY}
404     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
405     FOR    ${i}    IN RANGE    1    ${NUM_ODL_SYSTEM} + 1
406         Verify Exception Logging In Controller    ${ODL_SYSTEM_${i}_IP}    ${test_name}    ${exceptions_white_list}
407     END
408
409 Verify Exception Logging In Controller
410     [Documentation]    Local keyword to make it easier to loop through N controllers to pull Exceptions from the
411     ...    karaf.log file and validate with "Check Against White List"
412     [Arguments]    ${controller_ip}    ${test_name}    ${exceptions_white_list}
413     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
414     ${exceptions} =    Get Karaf Log Type From Test Start    ${controller_ip}    ${test_name}    Exception
415     @{log_lines} =    Split String    ${exceptions}    ${\n}
416     ${num_log_entries} =    Get Length    ${log_lines}
417     IF    ${num_log_entries} == ${0}    RETURN    No Exceptions found.
418     FOR    ${log_message}    IN    @{log_lines}
419         Check Against White List    ${log_message}    ${exceptions_white_list}
420     END
421
422 Check Against White List
423     [Documentation]    As soon as the ${exceptions_line} is found in one of the elements of ${exceptions_white_list}
424     ...    this keyword will exit and give a Pass to the caller. If there is no match, this keyword will end up
425     ...    marking a failure. In the case that no exceptions are found, the caller could end up passing a single
426     ...    empty line as that is what is returned when a grep on karaf.log has no match, so we can safely return
427     ...    in that case as well.
428     [Arguments]    ${exception_line}    ${exceptions_white_list}
429     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
430     IF    "${exception_line}" == ""    RETURN
431     FOR    ${exception}    IN    @{exceptions_white_list}
432         IF    "${exception}" in "${exception_line}"
433             RETURN    Exceptions found, but whitelisted: ${\n}${exception_line}${\n}
434         END
435     END
436     Fail    Exceptions Found: ${\n}${exception_line}${\n}
437
438 Wait_For_Karaf_Log
439     [Documentation]    Read karaf logs until message appear
440     [Arguments]    ${message}    ${timeout}=60    ${member_index}=${1}
441     # TODO: refactor this keyword to use the new workflow to account for multiple controllers.    Initial work was done
442     # in this patch https://git.opendaylight.org/gerrit/#/c/45596/
443     # however, the consumers of this keyword were breaking after that change.    Initial theory is that a previous
444     # keyword used before this "Wait For Karaf Log" keyword was closing the karaf console connection, so the
445     # "Flexible SSH Login" keyword from the patch above (45596) was failing.
446     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
447     BuiltIn.Log    Waiting for '${message}' in karaf log
448     SSHLibrary.Open_Connection
449     ...    ${ODL_SYSTEM_IP}
450     ...    port=${KARAF_SHELL_PORT}
451     ...    prompt=${KARAF_PROMPT_LOGIN}
452     ...    timeout=${timeout}
453     SSHLibrary.Login    ${KARAF_USER}    ${KARAF_PASSWORD}    loglevel=${loglevel}
454     SSHLibrary.Write    log:tail
455     SSHLibrary.Read_Until    ${message}
456     SSHLibrary.Write    logout
457     SSHLibrary.Close_Connection
458
459 Restart_Bundle
460     [Documentation]    Restarts bundle passed as argument. Note this operation is only for testing and not production environments
461     [Arguments]    ${bundle_id}
462     # TODO: prepare this for cluster environment and multiple controllers
463     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
464     Execute_Controller_Karaf_Command_With_Retry_On_Background    bundle:restart $(bundle:id '${bundle_id}')
465
466 Restart_Karaf
467     [Documentation]    Restarts Karaf and polls log to detect when Karaf is up and running again
468     # TODO: prepare this for cluster environment and multiple controllers
469     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
470     Execute_Controller_Karaf_Command_With_Retry_On_Background    log:clear
471     Execute_Controller_Karaf_Command_With_Retry_On_Background    shutdown -r -f
472     BuiltIn.Run_Keyword_And_Return_Status
473     ...    BuiltIn.Wait_Until_Keyword_Succeeds
474     ...    240s
475     ...    60s
476     ...    Wait_For_Karaf_Log
477     ...    Shiro environment initialized in
478
479 Restart_Jetty
480     [Documentation]    Restarts jetty bundle (to reload certificates or key/truststore information)
481     IF    '${IS_KARAF_APPL}' == 'False'    RETURN    Not A Karaf App
482     Execute_Controller_Karaf_Command_With_Retry_On_Background    log:clear
483     Restart_Bundle    OPS4J Pax Web - Jetty
484     Wait_For_Karaf_Log    Started jetty-default