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
15 [Documentation] Verify if the backedup files are present in the controller
16 [Arguments] ${host_index}
17 ${host_index} Builtin.Convert To Integer ${host_index}
18 ${cfg} ClusterManagement.Run Bash Command On Member
19 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_DATA_FILE}
22 Builtin.Should Match Regexp ${cfg} .*${EXP_DATA_FILE}
23 ${mdl} ClusterManagement.Run Bash Command On Member
24 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${MODELS_FILE}
27 Builtin.Should Match Regexp ${mdl} .*${MODELS_FILE}
28 ${opr} ClusterManagement.Run Bash Command On Member
29 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_OPER_FILE}
32 Builtin.Should Match Regexp ${opr} .*${EXP_OPER_FILE}
34 Verify Export Files Not Present
35 [Documentation] Verify if the backedup files are not present in the controller
36 [Arguments] ${host_index}
37 ${host_index} Builtin.Convert To Integer ${host_index}
38 ${cfg} ClusterManagement.Run Bash Command On Member
39 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_DATA_FILE}
42 Builtin.Should Not Match Regexp ${cfg} .*${EXP_DATA_FILE}
43 ${mdl} ClusterManagement.Run Bash Command On Member
44 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${MODELS_FILE}
47 Builtin.Should Not Match Regexp ${mdl} .*${MODELS_FILE}
48 ${opr} ClusterManagement.Run Bash Command On Member
49 ... ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_OPER_FILE}
52 Builtin.Should Not Match Regexp ${opr} .*${EXP_OPER_FILE}
54 Cleanup The Export Files
55 [Documentation] Verify if the export directory exists and delete the files if needed
56 [Arguments] ${host_index}
57 ${host_index} Builtin.Convert To Integer ${host_index}
58 Builtin.Run Keyword And Ignore Error
59 ... ClusterManagement.Delete And Check Member List Or All
62 ${output1} Builtin.Run Keyword and IgnoreError
63 ... ClusterManagement.Run Bash Command On Member
64 ... sudo rm -rf ${WORKSPACE}/${BUNDLEFOLDER}/daexim;clear
66 ${output2} Builtin.Run Keyword and IgnoreError
67 ... ClusterManagement.Run Bash Command On Member
68 ... rm -rf ${WORKSPACE}/${BUNDLEFOLDER}/daexim;clear
70 ${output} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER} ${host_index}
72 Builtin.Should Not Match Regexp ${output} daexim
75 [Documentation] Verify export status is as expected
76 [Arguments] ${status} ${controller_index}
77 ${response_json} ClusterManagement.Post As Json To Member
78 ... ${STATUS_EXPORT_URL}
80 ... ${controller_index}
81 Builtin.Log ${response_json}
82 ${response_json} Builtin.Convert To String ${response_json}
83 Verify Export Status Message ${status} ${response_json}
85 Verify Scheduled Export Timestamp
86 [Documentation] Verify export timestamp is as expected
87 [Arguments] ${controller_index} ${time}
88 ${response_json} ClusterManagement.Post As Json To Member
89 ... ${STATUS_EXPORT_URL}
91 ... ${controller_index}
92 Builtin.Log ${response_json}
93 ${response_json} Builtin.Convert To String ${response_json}
94 Builtin.Should Match Regexp ${response_json} .*"run-at": "${time}"
96 Verify Export Status Message
97 [Documentation] Verify export restconf response message is as expected
98 [Arguments] ${status} ${output}
99 Builtin.Should Match Regexp ${output} "status": "${status}"
100 IF "${status}" == "initial" or "${status}" == "scheduled" or "${status}" == "skipped"
101 Verify Json Files Not Present ${output}
103 Verify Json Files Present ${output}
106 Verify Json Files Present
107 [Documentation] Verify if the json files are generated after a export/export
108 [Arguments] ${output} ${config_json}=${EXP_DATA_FILE} ${models_json}=${MODELS_FILE} ${operational_json}=${EXP_OPER_FILE}
109 Builtin.Should Match Regexp ${output} .*${config_json}
110 Builtin.Should Match Regexp ${output} .*${models_json}
111 Builtin.Should Match Regexp ${output} .*${operational_json}
112 Builtin.Log Found all Json Files
114 Verify Json Files Not Present
115 [Documentation] Verify if the json files are not present under the daexim folder
116 [Arguments] ${output} ${config_json}=${EXP_DATA_FILE} ${models_json}=${MODELS_FILE} ${operational_json}=${EXP_OPER_FILE}
117 Builtin.Should Not Match Regexp ${output} .*${config_json}
118 Builtin.Should Not Match Regexp ${output} .*${models_json}
119 Builtin.Should Not Match Regexp ${output} .*${operational_json}
120 Builtin.Log Did not Find all Json Files
123 [Documentation] Schedule Export job
124 [Arguments] ${controller_index} ${time}=500 ${exclude}=${FALSE} ${module}=${EMPTY} ${store}=${EMPTY} ${flag}=false
125 ... ${include}=${FALSE}
127 ${file} Builtin.Set Variable ${EXPORT_INCLUDE_FILE}
129 ${file} Builtin.Set Variable If ${exclude} ${EXPORT_EXCLUDE_FILE} ${EXPORT_FILE}
131 ${json} OperatingSystem.Get File ${file}
132 ${json} Builtin.Replace Variables ${json}
133 Cleanup The Export Files ${controller_index}
134 ${response_json} ClusterManagement.Post As Json To Member
135 ... ${SCHEDULE_EXPORT_URL}
137 ... ${controller_index}
138 Builtin.Log ${response_json}
140 Schedule Exclude Export
141 [Documentation] Schedules a export with exclude option. Returns the file that has the excluded export.
142 [Arguments] ${controller_index} ${store} ${module}
143 ${controller_index} Builtin.Convert To Integer ${controller_index}
144 ${host} ClusterManagement.Resolve IP Address For Member ${controller_index}
145 Schedule Export ${controller_index} 500 ${TRUE} ${module} ${store}
146 Builtin.Wait Until Keyword Succeeds 10 sec 5 sec Verify Export Status complete ${controller_index}
147 Verify Export Files ${controller_index}
148 Copy Export Directory To Test VM ${host}
149 ${export_file} Builtin.Set Variable If '${store}' == 'operational' ${EXP_OPER_FILE} ${EXP_DATA_FILE}
150 ${file_path} OperatingSystem.Join Path ${EXP_DIR}${host} ${export_file}
153 Schedule Include Export
154 [Documentation] Schedules a export with include option. Returns the file that has the included export.
155 [Arguments] ${controller_index} ${store} ${module}=${EMPTY} ${exclude}=${FALSE}
156 ${controller_index} Builtin.Convert To Integer ${controller_index}
157 ${host} ClusterManagement.Resolve IP Address For Member ${controller_index}
158 ${time} Builtin.Set Variable 500
159 ${file} Builtin.Set Variable If ${exclude} ${EXPORT_INCEXCLUDE_FILE} ${EXPORT_INCLUDE_FILE}
160 ${json} OperatingSystem.Get File ${file}
161 ${json} Builtin.Replace Variables ${json}
162 Cleanup The Export Files ${controller_index}
163 ${response_json} ClusterManagement.Post As Json To Member
164 ... ${SCHEDULE_EXPORT_URL}
166 ... ${controller_index}
167 Builtin.Log ${response_json}
168 Builtin.Wait Until Keyword Succeeds 10 sec 5 sec Verify Export Status complete ${controller_index}
169 Verify Export Files ${controller_index}
170 Copy Export Directory To Test VM ${host}
171 ${export_file} Builtin.Set Variable If '${store}' == 'operational' ${EXP_OPER_FILE} ${EXP_DATA_FILE}
172 ${file_path} OperatingSystem.Join Path ${EXP_DIR}${host} ${export_file}
176 [Documentation] Cancel the export job
177 [Arguments] ${controller_index}
178 ${response_json} ClusterManagement.Post As Json To Member
179 ... ${CANCEL_EXPORT_URL}
181 ... ${controller_index}
182 Builtin.Log ${response_json}
185 [Documentation] Returns the connection of any host. Defaults to controller
186 [Arguments] ${system}=${ODL_SYSTEM_IP} ${prompt}=${DEFAULT_LINUX_PROMPT} ${prompt_timeout}=${DEFAULT_TIMEOUT} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD}
187 ${conn_id} SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${prompt_timeout}
188 SSHKeywords.Flexible SSH Login ${user} ${password}
192 [Documentation] Cleans up the given directory if it exists
194 OperatingSystem.Empty Directory ${dir}
195 OperatingSystem.Remove Directory ${dir}
197 Copy Export Directory To Test VM
198 [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
200 ${new_dir} Builtin.Set Variable ${EXP_DIR}${host}
201 ${directory_exist} Builtin.Run Keyword And Return Status OperatingSystem.Directory Should Exist ${new_dir}
202 IF ${directory_exist} Cleanup Directory ${new_dir}
203 ${connections} Return ConnnectionID ${host}
204 SSHLibrary.Switch Connection ${connections}
205 SSHLibrary.Directory Should Exist ${WORKSPACE}/${BUNDLEFOLDER}/daexim
206 SSHLibrary.Get Directory ${WORKSPACE}/${BUNDLEFOLDER}/daexim ${new_dir}
207 SSHLibrary.Close Connection
208 ${output} OperatingSystem.List Files In Directory ${new_dir}
209 Builtin.Log ${output}
210 ${fl} OperatingSystem.Get File ${new_dir}/${EXP_DATA_FILE}
213 Copy Config Data To Controller
214 [Documentation] This keyword copies the daexim folder under variables folder to the Controller
215 [Arguments] ${host_index}
216 ${host_index} Builtin.Convert To Integer ${host_index}
217 ${host} ClusterManagement.Resolve IP Address For Member ${host_index}
218 ${connections} Return ConnnectionID ${host}
219 SSHLibrary.Switch Connection ${connections}
220 SSHLibrary.Put Directory ${CURDIR}/${DAEXIM_DATA_DIRECTORY} ${WORKSPACE}/${BUNDLEFOLDER}/ mode=664
221 SSHLibrary.Close Connection
223 Mount Netconf Endpoint
224 [Documentation] Mount a netconf endpoint
225 [Arguments] ${endpoint} ${host_index}
226 ${ENDPOINT} Builtin.Set Variable ${endpoint}
227 ${json} OperatingSystem.Get File ${CURDIR}/${NETCONF_PAYLOAD_JSON}
228 ${json} Builtin.Replace Variables ${json}
230 ${resp} ClusterManagement.Put As Json To Member ${NETCONF_NODE_URL}=${endpoint} ${json} ${host_index}
233 Fetch Status Information From Netconf Endpoint
234 [Documentation] This keyword fetches netconf endpoint information
235 [Arguments] ${endpoint} ${host_index}
236 ${resp} ClusterManagement.Get From Member ${NETCONF_NODE_URL}=${endpoint} ${host_index}
237 ${output1} Builtin.Set Variable ${resp}
238 ${output} Utils.Json Parse From String ${output1}
239 Builtin.Log ${output}
240 ${status} Collections.Get From Dictionary
241 ... ${output['network-topology:node'][0]}
242 ... netconf-node-topology:connection-status
243 RETURN ${status} ${output}
245 Verify Status Information
246 [Documentation] Verify if a netconf endpoint status is connected by running in a loop
247 [Arguments] ${endpoint} ${host_index} ${itr}=50
248 FOR ${i} IN RANGE ${itr}
249 ${sts} ${op} Fetch Status Information From Netconf Endpoint ${endpoint} ${host_index}
251 IF "${sts}" == "${NTCF_OPR_STATUS}" BREAK
256 [Documentation] Verify if a netconf endpoint is mounted
257 [Arguments] ${endpoint} ${host_index}
258 ${sts1} ${output} Verify Status Information ${endpoint} ${host_index}
259 ${ep} Collections.Get From Dictionary ${output['network-topology:node'][0]} node-id
260 ${port} Collections.Get From Dictionary ${output['network-topology:node'][0]} netconf-node-topology:port
261 ${port} Builtin.Convert To String ${port}
262 Builtin.Should Be Equal ${endpoint} ${ep}
263 Builtin.Should Be Equal ${port} ${NETCONF_PORT}
266 [Documentation] Schedule an Import API
267 [Arguments] ${host_index} ${result}=true ${reason}=${EMPTY} ${mdlflag}=${MDL_DEF_FLAG} ${strflag}=${STR_DEF_FLAG}
268 ${modelflag} Builtin.Set Variable ${mdlflag}
269 ${storeflag} Builtin.Set Variable ${strflag}
270 ${json} OperatingSystem.Get File ${CURDIR}/${IMPORT_PAYLOAD}
271 ${json} Builtin.Replace Variables ${json}
273 ${resp} Builtin.Wait Until Keyword Succeeds
276 ... ClusterManagement.Post As Json To Member
281 Builtin.Should Match Regexp ${resp} .*"result": ${result}
282 IF "${reason}" != "${EMPTY}"
283 Builtin.Should Match Regexp ${response_json} .*"reason":"${reason}
286 Cleanup Cluster Export Files
287 [Documentation] This keyword cleansup export files of a cluster
288 [Arguments] ${member_index_list}=${EMPTY}
289 ${index_list} List Indices Or All given_list=${member_index_list}
290 FOR ${index} IN @{index_list} # usually: 1, 2, 3.
291 DaeximKeywords.Cleanup The Export Files ${index}