2 Documentation Karaf library. This library is useful to deal with controller Karaf console.
4 Library OperatingSystem
5 Variables ../variables/Variables.py
9 ${KarafKeywords__karaf_connection_index} -1
12 Verify Feature Is Installed
13 [Arguments] ${feature_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT}
14 [Documentation] Will Succeed if the given ${feature_name} is found in the output of "feature:list -i"
15 ${output}= Issue Command On Karaf Console feature:list -i | grep ${feature_name} ${controller} ${karaf_port}
16 Should Contain ${output} ${feature_name}
19 Issue Command On Karaf Console
20 [Arguments] ${cmd} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=5 ${loglevel}=INFO
21 [Documentation] Will execute the given ${cmd} by ssh'ing to the karaf console running on ${ODL_SYSTEM_IP}
22 ... Note that this keyword will open&close new SSH connection, without switching back to previously current session.
23 Open Connection ${controller} port=${karaf_port} prompt=${KARAF_PROMPT} timeout=${timeout}
24 Login ${KARAF_USER} ${KARAF_PASSWORD} loglevel=${loglevel}
26 ${output} Read Until ${KARAF_PROMPT}
31 Check For Elements On Karaf Command Output Message
32 [Arguments] ${cmd} ${elements} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=5
33 [Documentation] Will execute the command using Issue Command On Karaf Console then check for the given elements
34 ... in the command output message
35 ${output} Issue Command On Karaf Console ${cmd} ${controller} ${karaf_port} ${timeout}
36 : FOR ${i} IN @{elements}
37 \ Should Contain ${output} ${i}
39 Verify Bundle Is Installed
40 [Arguments] ${bundle_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT}
41 [Documentation] Will succeed if the given ${bundle name} is present in the output of "bundle:list -s "
42 ${output}= Issue Command On Karaf Console bundle:list -s | grep ${bundle_name} ${controller} ${karaf_port}
43 Should Contain ${output} ${bundle_name}
46 Verify Bundle Is Not Installed
47 [Arguments] ${bundle_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT}
48 [Documentation] Will succeed if the given ${bundle_name} is NOT found in the output of "bundle:list -s"
49 ${output}= Issue Command On Karaf Console bundle:list -i | grep ${bundle_name} ${controller} ${karaf_port}
50 Should Not Contain ${output} ${bundle_name}
53 Check Karaf Log Has Messages
54 [Arguments] ${filter_string} @{message_list}
55 [Documentation] Will succeed if the @{messages} are found in \ the output of "log:display"
56 ${output}= Issue Command On Karaf Console log:display | grep ${filter_string}
57 : FOR ${message} IN @{message_list}
58 \ Should Contain ${output} ${message}
61 Check Karaf Log File Does Not Have Messages
62 [Arguments] ${ip} ${message} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT} ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
63 [Documentation] Fails if the provided ${message} is found in the karaf.log file. Uses grep to search. The
64 ... karaf.log file can be overridden with ${log_file} to be any file on the given system @ ${ip}
65 ${output}= Run Command On Controller ${ip} grep -c '${message}' ${log_file} user=${user} password=${password} prompt=${prompt}
66 Should Be Equal As Strings ${output} 0
69 [Arguments] ${feature_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=180
70 [Documentation] Will Install the given ${feature_name}
72 ${output}= Issue Command On Karaf Console feature:install ${feature_name} ${controller} ${karaf_port} ${timeout}
77 [Arguments] ${feature_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=180
78 [Documentation] Will UnInstall the given ${feature_name}
79 ${output}= Issue Command On Karaf Console feature:uninstall ${feature_name} ${controller} ${karaf_port} ${timeout}
83 Restore Current SSH Connection From Index
84 [Arguments] ${connection_index}
85 [Documentation] Restore active SSH connection in SSHLibrary to given index.
87 ... Restore the currently active connection state in
88 ... SSHLibrary to match the state returned by "Switch
89 ... Connection" or "Get Connection". More specifically makes
90 ... sure that there will be no active connection when the
91 ... \${connection_index} reported by these means is None.
93 ... There is a misfeature in SSHLibrary: Invoking "SSHLibrary.Switch_Connection"
94 ... and passing None as the "index_or_alias" argument to it has exactly the
95 ... same effect as invoking "Close Connection".
96 ... https://github.com/robotframework/SSHLibrary/blob/master/src/SSHLibrary/library.py#L560
98 ... We want to have Keyword which will "switch out" to previous
99 ... "no connection active" state without killing the background one.
101 ... As some suites may hypothetically rely on non-writability of active connection,
102 ... workaround is applied by opening and closing temporary connection.
103 ... Unfortunately this will fail if run on Jython and there is no SSH server
104 ... running on localhost, port 22 but there is nothing easy that can be done about it.
105 BuiltIn.Run Keyword And Return If ${connection_index} is not None SSHLibrary.Switch Connection ${connection_index}
106 # The background connection is still current, bury it.
107 SSHLibrary.Open Connection 127.0.0.1
108 SSHLibrary.Close Connection
110 Open Controller Karaf Console On Background
111 [Documentation] Connect to the controller's karaf console, but do not switch to it.
112 ${current_ssh_connection}= SSHLibrary.Get Connection
113 SSHLibrary.Open Connection ${ODL_SYSTEM_IP} port=${KARAF_SHELL_PORT} prompt=${KARAF_DETAILED_PROMPT}
114 ${karaf_connection}= SSHLibrary.Get Connection
115 SSHLibrary.Login ${KARAF_USER} ${KARAF_PASSWORD}
116 BuiltIn.Set Suite Variable ${KarafKeywords__karaf_connection_index} ${karaf_connection.index}
117 [Teardown] Restore Current SSH Connection From Index ${current_ssh_connection.index}
119 Configure Timeout For Karaf Console
120 [Arguments] ${timeout}
121 [Documentation] Configure a different timeout for the Karaf console
122 BuiltIn.Run Keyword If ${KarafKeywords__karaf_connection_index} == -1 Fail Need to connect to a Karaf Console first
123 ${current_connection_index}= SSHLibrary.Switch Connection ${KarafKeywords__karaf_connection_index}
124 SSHLibrary.Set_Client_Configuration timeout=${timeout}
125 [Teardown] Restore Current SSH Connection From Index ${current_connection_index}
127 Execute Controller Karaf Command On Background
128 [Arguments] ${command}
129 [Documentation] Send command to karaf without affecting current SSH connection. Read, log and return response.
130 ... This assumes Karaf connection has index saved and correct prompt set.
131 BuiltIn.Run Keyword If ${KarafKeywords__karaf_connection_index} == -1 Fail Need to connect to a Karaf Console first
132 ${current_connection_index}= SSHLibrary.Switch Connection ${KarafKeywords__karaf_connection_index}
133 ${status_write} ${message_write}= BuiltIn.Run Keyword And Ignore Error SSHLibrary.Write ${command}
134 ${status_wait} ${message_wait}= BuiltIn.Run Keyword And Ignore Error SSHLibrary.Read Until Prompt
135 BuiltIn.Run Keyword If '${status_write}' != 'PASS' BuiltIn.Fail Failed to send the command: ${command}
136 BuiltIn.Log ${message_wait}
137 BuiltIn.Run Keyword If '${status_wait}' != 'PASS' BuiltIn.Fail Failed to see prompt after sending the command: ${command}
138 [Teardown] Restore Current SSH Connection From Index ${current_connection_index}
139 [Return] ${message_wait}
141 Execute Controller Karaf Command With Retry On Background
142 [Arguments] ${command}
143 [Documentation] Attemp to send command to karaf, if fail then open connection and try again.
144 # As an attempt to debug intermittent SSH failures in the karaf logging command, we want to know the avail entropy on the controller system
145 Run Command On Controller cmd=cat /proc/sys/kernel/random/entropy_avail
146 ${status} ${message}= BuiltIn.Run Keyword And Ignore Error Execute Controller Karaf Command On Background ${command}
147 BuiltIn.Return_From_Keyword_If '${status}' == 'PASS' ${message}
148 # TODO: Verify this does not leak connections indices.
149 Open Controller Karaf Console On Background
150 ${message}= Execute Controller Karaf Command On Background ${command}
153 Log Message To Controller Karaf
154 [Arguments] ${message}
155 [Documentation] Send a message into the controller's karaf log file. Do not change current SSH connection.
156 ${reply}= Execute Controller Karaf Command With Retry On Background log:log "ROBOT MESSAGE: ${message}"
159 Log Test Suite Start To Controller Karaf
160 [Documentation] Log suite name to karaf log, useful in suite setup.
161 Log Message To Controller Karaf Starting suite ${SUITE_SOURCE}
163 Log Testcase Start To Controller Karaf
164 [Documentation] Log test case name to karaf log, useful in test case setup.
165 Log Message To Controller Karaf Starting test ${TEST_NAME}
167 Set Bgpcep Log Levels
168 [Arguments] ${bgpcep_level}=${DEFAULT_BGPCEP_LOG_LEVEL} ${protocol_level}=${DEFAULT_PROTOCOL_LOG_LEVEL}
169 [Documentation] Assuming OCKCOB was used, set logging level on bgpcep and protocol loggers without affecting current SSH session.
170 # FIXME: Move to appropriate Resource
171 Execute Controller Karaf Command On Background log:set ${bgpcep_level} org.opendaylight.bgpcep
172 Execute Controller Karaf Command On Background log:set ${protocol_level} org.opendaylight.protocol
175 [Arguments] ${message} ${timeout}=60
176 [Documentation] Read karaf logs until message appear
177 Log Waiting for '${message}' in karaf log
178 Open Connection ${ODL_SYSTEM_IP} port=${KARAF_SHELL_PORT} prompt=${KARAF_PROMPT} timeout=${timeout}
179 Flexible SSH Login ${KARAF_USER} ${KARAF_PASSWORD}
181 Read Until ${message}