2 Library OperatingSystem
5 Library RequestsLibrary
6 Resource ClusterManagement.robot
7 Resource ../variables/daexim/DaeximVariables.robot
8 Resource ../variables/Variables.robot
9 Resource SSHKeywords.robot
14 [Documentation] Verify if the backedup files are present in the controller
15 [Arguments] ${host_index}
16 ${host_index} Builtin.Convert To Integer ${host_index}
17 ${cfg} ClusterManagement.Run Bash Command On Member
18 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_DATA_FILE}
21 Builtin.Should Match Regexp ${cfg} .*${EXP_DATA_FILE}
22 ${mdl} ClusterManagement.Run Bash Command On Member
23 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${MODELS_FILE}
26 Builtin.Should Match Regexp ${mdl} .*${MODELS_FILE}
27 ${opr} ClusterManagement.Run Bash Command On Member
28 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_OPER_FILE}
31 Builtin.Should Match Regexp ${opr} .*${EXP_OPER_FILE}
33 Verify Export Files Not Present
34 [Documentation] Verify if the backedup files are not present in the controller
35 [Arguments] ${host_index}
36 ${host_index} Builtin.Convert To Integer ${host_index}
37 ${cfg} ClusterManagement.Run Bash Command On Member
38 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_DATA_FILE}
41 Builtin.Should Not Match Regexp ${cfg} .*${EXP_DATA_FILE}
42 ${mdl} ClusterManagement.Run Bash Command On Member
43 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${MODELS_FILE}
46 Builtin.Should Not Match Regexp ${mdl} .*${MODELS_FILE}
47 ${opr} ClusterManagement.Run Bash Command On Member
48 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_OPER_FILE}
51 Builtin.Should Not Match Regexp ${opr} .*${EXP_OPER_FILE}
53 Cleanup The Export Files
54 [Documentation] Verify if the export directory exists and delete the files if needed
55 [Arguments] ${host_index}
56 ${host_index} Builtin.Convert To Integer ${host_index}
57 Builtin.Run Keyword And Ignore Error
58 ... ClusterManagement.Delete And Check Member List Or All
61 ${output1} Builtin.Run Keyword and IgnoreError
62 ... ClusterManagement.Run Bash Command On Member
63 ... sudo rm -rf ${WORKSPACE}/${BUNDLEFOLDER}/daexim;clear
65 ${output2} Builtin.Run Keyword and IgnoreError
66 ... ClusterManagement.Run Bash Command On Member
67 ... rm -rf ${WORKSPACE}/${BUNDLEFOLDER}/daexim;clear
69 ${output} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER} ${host_index}
71 Builtin.Should Not Match Regexp ${output} daexim
74 [Documentation] Verify export status is as expected
75 [Arguments] ${status} ${controller_index}
76 ${response_json} ClusterManagement.Post As Json To Member
77 ... ${STATUS_EXPORT_URL}
79 ... ${controller_index}
80 Builtin.Log ${response_json}
81 ${response_json} Builtin.Convert To String ${response_json}
82 Verify Export Status Message ${status} ${response_json}
84 Verify Scheduled Export Timestamp
85 [Documentation] Verify export timestamp is as expected
86 [Arguments] ${controller_index} ${time}
87 ${response_json} ClusterManagement.Post As Json To Member
88 ... ${STATUS_EXPORT_URL}
90 ... ${controller_index}
91 Builtin.Log ${response_json}
92 ${response_json} Builtin.Convert To String ${response_json}
93 Builtin.Should Match Regexp ${response_json} .*"run-at": "${time}"
95 Verify Export Status Message
96 [Documentation] Verify export restconf response message is as expected
97 [Arguments] ${status} ${output}
98 Builtin.Should Match Regexp ${output} "status": "${status}"
99 IF "${status}" == "initial" or "${status}" == "scheduled" or "${status}" == "skipped"
100 Verify Json Files Not Present ${output}
102 Verify Json Files Present ${output}
105 Verify Json Files Present
106 [Documentation] Verify if the json files are generated after a export/export
107 [Arguments] ${output} ${config_json}=${EXP_DATA_FILE} ${models_json}=${MODELS_FILE} ${operational_json}=${EXP_OPER_FILE}
108 Builtin.Should Match Regexp ${output} .*${config_json}
109 Builtin.Should Match Regexp ${output} .*${models_json}
110 Builtin.Should Match Regexp ${output} .*${operational_json}
111 Builtin.Log Found all Json Files
113 Verify Json Files Not Present
114 [Documentation] Verify if the json files are not present under the daexim folder
115 [Arguments] ${output} ${config_json}=${EXP_DATA_FILE} ${models_json}=${MODELS_FILE} ${operational_json}=${EXP_OPER_FILE}
116 Builtin.Should Not Match Regexp ${output} .*${config_json}
117 Builtin.Should Not Match Regexp ${output} .*${models_json}
118 Builtin.Should Not Match Regexp ${output} .*${operational_json}
119 Builtin.Log Did not Find all Json Files
122 [Documentation] Schedule Export job
123 [Arguments] ${controller_index} ${time}=500 ${exclude}=${FALSE} ${module}=${EMPTY} ${store}=${EMPTY} ${flag}=false
124 ... ${include}=${FALSE}
126 ${file} Builtin.Set Variable ${EXPORT_INCLUDE_FILE}
128 ${file} Builtin.Set Variable If ${exclude} ${EXPORT_EXCLUDE_FILE} ${EXPORT_FILE}
130 ${json} OperatingSystem.Get File ${file}
131 ${json} Builtin.Replace Variables ${json}
132 Cleanup The Export Files ${controller_index}
133 ${response_json} ClusterManagement.Post As Json To Member
134 ... ${SCHEDULE_EXPORT_URL}
136 ... ${controller_index}
137 Builtin.Log ${response_json}
139 Schedule Exclude Export
140 [Documentation] Schedules a export with exclude option. Returns the file that has the excluded export.
141 [Arguments] ${controller_index} ${store} ${module}
142 ${controller_index} Builtin.Convert To Integer ${controller_index}
143 ${host} ClusterManagement.Resolve IP Address For Member ${controller_index}
144 Schedule Export ${controller_index} 500 ${TRUE} ${module} ${store}
145 Builtin.Wait Until Keyword Succeeds 10 sec 5 sec Verify Export Status complete ${controller_index}
146 Verify Export Files ${controller_index}
147 Copy Export Directory To Test VM ${host}
148 ${export_file} Builtin.Set Variable If '${store}' == 'operational' ${EXP_OPER_FILE} ${EXP_DATA_FILE}
149 ${file_path} OperatingSystem.Join Path ${EXP_DIR}${host} ${export_file}
152 Schedule Include Export
153 [Documentation] Schedules a export with include option. Returns the file that has the included export.
154 [Arguments] ${controller_index} ${store} ${module}=${EMPTY} ${exclude}=${FALSE}
155 ${controller_index} Builtin.Convert To Integer ${controller_index}
156 ${host} ClusterManagement.Resolve IP Address For Member ${controller_index}
157 ${time} Builtin.Set Variable 500
158 ${file} Builtin.Set Variable If ${exclude} ${EXPORT_INCEXCLUDE_FILE} ${EXPORT_INCLUDE_FILE}
159 ${json} OperatingSystem.Get File ${file}
160 ${json} Builtin.Replace Variables ${json}
161 Cleanup The Export Files ${controller_index}
162 ${response_json} ClusterManagement.Post As Json To Member
163 ... ${SCHEDULE_EXPORT_URL}
165 ... ${controller_index}
166 Builtin.Log ${response_json}
167 Builtin.Wait Until Keyword Succeeds 10 sec 5 sec Verify Export Status complete ${controller_index}
168 Verify Export Files ${controller_index}
169 Copy Export Directory To Test VM ${host}
170 ${export_file} Builtin.Set Variable If '${store}' == 'operational' ${EXP_OPER_FILE} ${EXP_DATA_FILE}
171 ${file_path} OperatingSystem.Join Path ${EXP_DIR}${host} ${export_file}
175 [Documentation] Cancel the export job
176 [Arguments] ${controller_index}
177 ${response_json} ClusterManagement.Post As Json To Member
178 ... ${CANCEL_EXPORT_URL}
180 ... ${controller_index}
181 Builtin.Log ${response_json}
184 [Documentation] Returns the connection of any host. Defaults to controller
185 [Arguments] ${system}=${ODL_SYSTEM_IP} ${prompt}=${DEFAULT_LINUX_PROMPT} ${prompt_timeout}=${DEFAULT_TIMEOUT} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD}
186 ${conn_id} SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${prompt_timeout}
187 SSHKeywords.Flexible SSH Login ${user} ${password}
191 [Documentation] Cleans up the given directory if it exists
193 OperatingSystem.Empty Directory ${dir}
194 OperatingSystem.Remove Directory ${dir}
196 Copy Export Directory To Test VM
197 [Documentation] This keyword copies the daexim folder genereated in the controller to robot vm. This is done to editing if needed on the json files
199 ${new_dir} Builtin.Set Variable ${EXP_DIR}${host}
200 ${directory_exist} Builtin.Run Keyword And Return Status OperatingSystem.Directory Should Exist ${new_dir}
201 IF ${directory_exist} Cleanup Directory ${new_dir}
202 ${connections} Return ConnnectionID ${host}
203 SSHLibrary.Switch Connection ${connections}
204 SSHLibrary.Directory Should Exist ${WORKSPACE}/${BUNDLEFOLDER}/daexim
205 SSHLibrary.Get Directory ${WORKSPACE}/${BUNDLEFOLDER}/daexim ${new_dir}
206 SSHLibrary.Close Connection
207 ${output} OperatingSystem.List Files In Directory ${new_dir}
208 Builtin.Log ${output}
209 ${fl} OperatingSystem.Get File ${new_dir}/${EXP_DATA_FILE}
212 Copy Config Data To Controller
213 [Documentation] This keyword copies the daexim folder under variables folder to the Controller
214 [Arguments] ${host_index}
215 ${host_index} Builtin.Convert To Integer ${host_index}
216 ${host} ClusterManagement.Resolve IP Address For Member ${host_index}
217 ${connections} Return ConnnectionID ${host}
218 SSHLibrary.Switch Connection ${connections}
219 SSHLibrary.Put Directory ${CURDIR}/${DAEXIM_DATA_DIRECTORY} ${WORKSPACE}/${BUNDLEFOLDER}/ mode=664
220 SSHLibrary.Close Connection
222 Mount Netconf Endpoint
223 [Documentation] Mount a netconf endpoint
224 [Arguments] ${endpoint} ${host_index}
225 ${ENDPOINT} Builtin.Set Variable ${endpoint}
226 ${json} OperatingSystem.Get File ${CURDIR}/${NETCONF_PAYLOAD_JSON}
227 ${json} Builtin.Replace Variables ${json}
229 ${resp} ClusterManagement.Put As Json To Member ${NETCONF_NODE_URL}=${endpoint} ${json} ${host_index}
232 Fetch Status Information From Netconf Endpoint
233 [Documentation] This keyword fetches netconf endpoint information
234 [Arguments] ${endpoint} ${host_index}
235 ${resp} ClusterManagement.Get From Member ${NETCONF_NODE_URL}=${endpoint} ${host_index}
236 ${output1} Builtin.Set Variable ${resp}
237 ${output} RequestsLibrary.To Json ${output1}
238 Builtin.Log ${output}
239 ${status} Collections.Get From Dictionary
240 ... ${output['network-topology:node'][0]}
241 ... netconf-node-topology:connection-status
242 RETURN ${status} ${output}
244 Verify Status Information
245 [Documentation] Verify if a netconf endpoint status is connected by running in a loop
246 [Arguments] ${endpoint} ${host_index} ${itr}=50
247 FOR ${i} IN RANGE ${itr}
248 ${sts} ${op} Fetch Status Information From Netconf Endpoint ${endpoint} ${host_index}
250 IF "${sts}" == "${NTCF_OPR_STATUS}" BREAK
255 [Documentation] Verify if a netconf endpoint is mounted
256 [Arguments] ${endpoint} ${host_index}
257 ${sts1} ${output} Verify Status Information ${endpoint} ${host_index}
258 ${ep} Collections.Get From Dictionary ${output['network-topology:node'][0]} node-id
259 ${port} Collections.Get From Dictionary ${output['network-topology:node'][0]} netconf-node-topology:port
260 ${port} Builtin.Convert To String ${port}
261 Builtin.Should Be Equal ${endpoint} ${ep}
262 Builtin.Should Be Equal ${port} ${NETCONF_PORT}
265 [Documentation] Schedule an Import API
266 [Arguments] ${host_index} ${result}=true ${reason}=${EMPTY} ${mdlflag}=${MDL_DEF_FLAG} ${strflag}=${STR_DEF_FLAG}
267 ${modelflag} Builtin.Set Variable ${mdlflag}
268 ${storeflag} Builtin.Set Variable ${strflag}
269 ${json} OperatingSystem.Get File ${CURDIR}/${IMPORT_PAYLOAD}
270 ${json} Builtin.Replace Variables ${json}
272 ${resp} Builtin.Wait Until Keyword Succeeds
275 ... ClusterManagement.Post As Json To Member
280 Builtin.Should Match Regexp ${resp} .*"result": ${result}
281 IF "${reason}" != "${EMPTY}"
282 Builtin.Should Match Regexp ${response_json} .*"reason":"${reason}
285 Cleanup Cluster Export Files
286 [Documentation] This keyword cleansup export files of a cluster
287 [Arguments] ${member_index_list}=${EMPTY}
288 ${index_list} List Indices Or All given_list=${member_index_list}
289 FOR ${index} IN @{index_list} # usually: 1, 2, 3.
290 DaeximKeywords.Cleanup The Export Files ${index}