2 Documentation Karaf library. This library is useful to deal with controller Karaf console for ssh sessions in cluster.
3 ... Running Setup Karaf Keywords is necessary. If SetupUtils initialization is called, this gets initialized as well.
4 ... If this gets initialized, ClusterManagement gets initialized as well.
6 Library OperatingSystem
7 Resource ${CURDIR}/ClusterManagement.robot
8 Resource ${CURDIR}/SSHKeywords.robot
9 Variables ${CURDIR}/../variables/Variables.py
13 ${connection_index_dict} &{EMPTY}
17 [Documentation] Initialize ClusterManagement. Open ssh karaf connections to each ODL.
18 ClusterManagement.ClusterManagement_Setup
19 BuiltIn.Comment First connections to Karaf console may fail, so WUKS is used. TODO: Track as a Bug.
20 : FOR ${index} IN @{ClusterManagement__member_index_list}
21 \ BuiltIn.Wait_Until_Keyword_Succeeds 3x 0.2s Open Controller Karaf Console On Background member_index=${index}
23 Verify Feature Is Installed
24 [Arguments] ${feature_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT}
25 [Documentation] Will Succeed if the given ${feature_name} is found in the output of "feature:list -i"
26 ${output}= Issue Command On Karaf Console feature:list -i | grep ${feature_name} ${controller} ${karaf_port}
27 Should Contain ${output} ${feature_name}
30 Issue Command On Karaf Console
31 [Arguments] ${cmd} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=5 ${loglevel}=INFO
32 [Documentation] Will execute the given ${cmd} by ssh'ing to the karaf console running on ${controller}
33 ... Note that this keyword will open&close new SSH connection, without switching back to previously current session.
34 Open Connection ${controller} port=${karaf_port} prompt=${KARAF_PROMPT} timeout=${timeout}
35 Login ${KARAF_USER} ${KARAF_PASSWORD} loglevel=${loglevel}
37 ${output} Read Until ${KARAF_PROMPT}
42 Safe_Issue_Command_On_Karaf_Console
43 [Arguments] ${cmd} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=5 ${loglevel}=INFO
44 [Documentation] Run Issue_Command_On_Karaf_Console but restore previous connection afterwards.
45 BuiltIn.Run_Keyword_And_Return SSHKeywords.Run_Keyword_Preserve_Connection Issue_Command_On_Karaf_Console ${cmd} ${controller} ${karaf_port} ${timeout}
48 Check For Elements On Karaf Command Output Message
49 [Arguments] ${cmd} ${elements} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=5
50 [Documentation] Will execute the command using Issue Command On Karaf Console then check for the given elements
51 ... in the command output message
52 ${output} Issue Command On Karaf Console ${cmd} ${controller} ${karaf_port} ${timeout}
53 : FOR ${i} IN @{elements}
54 \ Should Contain ${output} ${i}
56 Verify Bundle Is Installed
57 [Arguments] ${bundle_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT}
58 [Documentation] Will succeed if the given ${bundle name} is present in the output of "bundle:list -s "
59 ${output}= Issue Command On Karaf Console bundle:list -s | grep ${bundle_name} ${controller} ${karaf_port}
60 Should Contain ${output} ${bundle_name}
63 Verify Bundle Is Not Installed
64 [Arguments] ${bundle_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT}
65 [Documentation] Will succeed if the given ${bundle_name} is NOT found in the output of "bundle:list -s"
66 ${output}= Issue Command On Karaf Console bundle:list -i | grep ${bundle_name} ${controller} ${karaf_port}
67 Should Not Contain ${output} ${bundle_name}
70 Check Karaf Log Has Messages
71 [Arguments] ${filter_string} @{message_list}
72 [Documentation] Will succeed if the @{messages} are found in \ the output of "log:display"
73 ${output}= Issue Command On Karaf Console log:display | grep ${filter_string}
74 : FOR ${message} IN @{message_list}
75 \ Should Contain ${output} ${message}
79 [Arguments] ${feature_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=180
80 [Documentation] Will Install the given ${feature_name}
82 ${output}= Issue Command On Karaf Console feature:install ${feature_name} ${controller} ${karaf_port} ${timeout}
87 [Arguments] ${feature_name} ${controller}=${ODL_SYSTEM_IP} ${karaf_port}=${KARAF_SHELL_PORT} ${timeout}=180
88 [Documentation] Will UnInstall the given ${feature_name}
89 ${output}= Issue Command On Karaf Console feature:uninstall ${feature_name} ${controller} ${karaf_port} ${timeout}
93 Open Controller Karaf Console On Background
94 [Arguments] ${member_index}=${1}
95 [Documentation] If there is a stored ssh connection index of connection to the controller's karaf console for ${member_index},
96 ... close the previous connection. In any case create a new connection
97 ... to karaf console for ${member_index}, set correct prompt set and login to karaf console.
98 ... Store connection index for ${member_index} and restore the previous active connection.
99 ${current_ssh_connection_object}= SSHLibrary.Get Connection
100 BuiltIn.Log ${connection_index_dict}
101 BuiltIn.Log ${member_index}
102 ${status} ${old_connection_index} = BuiltIn.Run Keyword And Ignore Error Get From Dictionary ${connection_index_dict} ${member_index}
103 BuiltIn.Run Keyword If '${status}'=='PASS' BuiltIn.Run Keywords SSHLibrary.Switch Connection ${old_connection_index}
104 ... AND SSHLibrary.Close Connection
105 ${odl_ip}= ClusterManagement.Resolve_IP_Address_For_Member ${member_index}
106 SSHLibrary.Open Connection ${odl_ip} port=${KARAF_SHELL_PORT} prompt=${KARAF_DETAILED_PROMPT}
107 ${karaf_connection_object}= SSHLibrary.Get Connection
108 Collections.Set To Dictionary ${connection_index_dict} ${member_index} ${karaf_connection_object.index}
109 SSHLibrary.Login ${KARAF_USER} ${KARAF_PASSWORD}
110 [Teardown] SSHKeywords.Restore Current SSH Connection From Index ${current_ssh_connection_object.index}
112 Configure Timeout For Karaf Console
113 [Arguments] ${timeout} ${member_index_list}=${EMPTY}
114 [Documentation] Configure a different timeout for each Karaf console.
115 ${index_list} = ClusterManagement.ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
116 ${current_connection_object}= SSHLibrary.Get Connection
117 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
118 \ ${karaf_connection_index}= Collections.Get From Dictionary ${connection_index_dict} ${member_index}
119 \ SSHLibrary.Switch Connection ${karaf_connection_index}
120 \ SSHLibrary.Set_Client_Configuration timeout=${timeout}
121 [Teardown] SSHKeywords.Restore Current SSH Connection From Index ${current_connection_object.index}
123 Execute Controller Karaf Command On Background
124 [Arguments] ${command} ${member_index}=${1}
125 [Documentation] Send command to karaf without affecting current SSH connection. Read, log and return response.
126 ${karaf_connection_index}= Collections.Get From Dictionary ${connection_index_dict} ${member_index}
127 ${current_connection_index}= SSHLibrary.Switch Connection ${karaf_connection_index}
128 ${status_write} ${message_write}= BuiltIn.Run Keyword And Ignore Error SSHLibrary.Write ${command}
129 ${status_wait} ${message_wait}= BuiltIn.Run Keyword And Ignore Error SSHLibrary.Read Until Prompt
130 BuiltIn.Run Keyword If '${status_write}' != 'PASS' BuiltIn.Fail Failed to send the command: ${command}
131 BuiltIn.Log ${message_wait}
132 BuiltIn.Run Keyword If '${status_wait}' != 'PASS' BuiltIn.Fail Failed to see prompt after sending the command: ${command}
133 [Teardown] SSHKeywords.Restore Current SSH Connection From Index ${current_connection_index}
134 [Return] ${message_wait}
136 Execute Controller Karaf Command With Retry On Background
137 [Arguments] ${command} ${member_index}=${1}
138 [Documentation] Attemp to send command to karaf for ${member_index}, if fail then open connection and try again.
139 ${status} ${message}= BuiltIn.Run Keyword And Ignore Error Execute Controller Karaf Command On Background ${command} ${member_index}
140 BuiltIn.Return_From_Keyword_If '${status}' == 'PASS' ${message}
141 # TODO: Verify this does not leak connections indices.
142 Open Controller Karaf Console On Background ${member_index}
143 ${message}= Execute Controller Karaf Command On Background ${command} ${member_index}
146 Log Message To Controller Karaf
147 [Arguments] ${message} ${member_index_list}=${EMPTY}
148 [Documentation] Make sure this resource is initialized. Send a message into the controller's karaf log file on every node listed (or all).
149 ${index_list} = ClusterManagement.ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
150 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
151 \ Execute Controller Karaf Command With Retry On Background log:log "ROBOT MESSAGE: ${message}" member_index=${index}
153 Log Test Suite Start To Controller Karaf
154 [Arguments] ${member_index_list}=${EMPTY}
155 [Documentation] Log suite name to karaf log, useful in suite setup.
156 Log Message To Controller Karaf Starting suite ${SUITE_SOURCE} ${member_index_list}
158 Log Testcase Start To Controller Karaf
159 [Arguments] ${member_index_list}=${EMPTY}
160 [Documentation] Log test case name to karaf log, useful in test case setup.
161 Log Message To Controller Karaf Starting test ${TEST_NAME} ${member_index_list}
163 Set Bgpcep Log Levels
164 [Arguments] ${bgpcep_level}=${DEFAULT_BGPCEP_LOG_LEVEL} ${protocol_level}=${DEFAULT_PROTOCOL_LOG_LEVEL} ${member_index_list}=${EMPTY}
165 [Documentation] Assuming OCKCOB was used, set logging level on bgpcep and protocol loggers without affecting current SSH session.
166 # FIXME: Move to appropriate Resource
167 ${index_list} = ClusterManagement.ClusterManagement__Given_Or_Internal_Index_List given_list=${member_index_list}
168 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
169 \ Execute Controller Karaf Command On Background log:set ${bgpcep_level} org.opendaylight.bgpcep member_index=${index}
170 \ Execute Controller Karaf Command On Background log:set ${protocol_level} org.opendaylight.protocol member_index=${index}
173 [Arguments] ${message} ${timeout}=60 ${member_index}=${1}
174 [Documentation] Read karaf logs until message appear
175 # TODO: refactor this keyword to use the new workflow to account for multiple controllers. Initial work was done
176 # in this patch https://git.opendaylight.org/gerrit/#/c/45596/
177 # however, the consumers of this keyword were breaking after that change. Initial theory is that a previous
178 # keyword used before this "Wait For Karaf Log" keyword was closing the karaf console connection, so the
179 # "Flexible SSH Login" keyword from the patch above (45596) was failing.
180 Log Waiting for '${message}' in karaf log
181 Open Connection ${ODL_SYSTEM_IP} port=${KARAF_SHELL_PORT} prompt=${KARAF_PROMPT} timeout=${timeout}
182 Login ${KARAF_USER} ${KARAF_PASSWORD} loglevel=${loglevel}
184 Read Until ${message}