2 Documentation Karaf library. This library is useful to deal with controller Karaf console.
4 Library OperatingSystem
5 Variables ../variables/Variables.py
9 ${BUNDLEFOLDER} distribution-karaf-0.3.0-SNAPSHOT
10 ${KarafKeywords__karaf_connection_index} -1
13 Verify Feature Is Installed
14 [Arguments] ${feature_name} ${controller}=${CONTROLLER} ${karaf_port}=${KARAF_SHELL_PORT}
15 [Documentation] Will Succeed if the given ${feature_name} is found in the output of "feature:list -i"
16 ${output}= Issue Command On Karaf Console feature:list -i | grep ${feature_name} ${controller} ${karaf_port}
17 Should Contain ${output} ${feature_name}
20 Verify Feature Is Not Installed
21 [Arguments] ${feature_name} ${controller}=${CONTROLLER} ${karaf_port}=${KARAF_SHELL_PORT}
22 [Documentation] Will Succeed if the given ${feature_name} is NOT found in the output of "feature:list -i"
23 ${output}= Issue Command On Karaf Console feature:list -i | grep ${feature_name} ${controller} ${karaf_port}
24 Should Not Contain ${output} ${feature_name}
27 Issue Command On Karaf Console
28 [Arguments] ${cmd} ${controller}=${CONTROLLER} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=5
29 [Documentation] Will execute the given ${cmd} by ssh'ing to the karaf console running on ${CONTROLLER}
30 ... Note that this keyword will open&close new SSH connection, without switching back to previously current session.
31 Open Connection ${controller} port=${karaf_port} prompt=${KARAF_PROMPT} timeout=${timeout}
32 Login ${KARAF_USER} ${KARAF_PASSWORD}
34 ${output} Read Until ${KARAF_PROMPT}
39 Verify Bundle Is Installed
40 [Arguments] ${bundle_name} ${controller}=${CONTROLLER} ${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}=${CONTROLLER} ${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}=${CONTROLLER_USER} ${password}=${CONTROLLER_PASSWORD} ${prompt}=${DEFAULT_LINUX_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}=${CONTROLLER} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=15
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}=${CONTROLLER} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=15
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 ${CONTROLLER} 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 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 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 Restore Current SSH Connection From Index ${current_connection_index}
136 BuiltIn.Run Keyword If '${status_write}' != 'PASS' BuiltIn.Fail Failed to send the command: ${command}
137 BuiltIn.Log ${message_wait}
138 BuiltIn.Run Keyword If '${status_wait}' != 'PASS' BuiltIn.Fail Failed to see prompt after sending the command: ${command}
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 ${status} ${message}= BuiltIn.Run Keyword And Ignore Error Execute Controller Karaf Command On Background ${command}
145 BuiltIn.Return_From_Keyword_If '${status}' == 'PASS' ${message}
146 # TODO: Verify this does not leak connections indices.
147 Open Controller Karaf Console On Background
148 ${message}= Execute Controller Karaf Command On Background ${command}
151 Log Message To Controller Karaf
152 [Arguments] ${message}
153 [Documentation] Send a message into the controller's karaf log file. Do not change current SSH connection.
154 ${reply}= Execute Controller Karaf Command With Retry On Background log:log "ROBOT MESSAGE: ${message}"
157 Log Test Suite Start To Controller Karaf
158 [Documentation] Log suite name to karaf log, useful in suite setup.
159 Log Message To Controller Karaf Starting suite ${SUITE_SOURCE}
161 Log Testcase Start To Controller Karaf
162 [Documentation] Log test case name to karaf log, useful in test case setup.
163 Log Message To Controller Karaf Starting test ${TEST_NAME}
165 Set Bgpcep Log Levels
166 [Arguments] ${bgpcep_level}=${DEFAULT_BGPCEP_LOG_LEVEL} ${protocol_level}=${DEFAULT_PROTOCOL_LOG_LEVEL}
167 [Documentation] Assuming OCKCOB was used, set logging level on bgpcep and protocol loggers without affecting current SSH session.
168 # FIXME: Move to appropriate Resource
169 Execute Controller Karaf Command On Background log:set ${bgpcep_level} org.opendaylight.bgpcep
170 Execute Controller Karaf Command On Background log:set ${protocol_level} org.opendaylight.protocol
173 [Arguments] ${message} ${timeout}=60
174 [Documentation] Read karaf logs until message appear
175 Log Waiting for '${message}' in karaf log
176 Open Connection ${CONTROLLER} port=${KARAF_SHELL_PORT} prompt=${KARAF_PROMPT} timeout=${timeout}
177 Flexible SSH Login ${KARAF_USER} ${KARAF_PASSWORD}
179 Read Until ${message}