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
13 [Arguments] ${host_index}
14 [Documentation] Verify if the backedup files are present in the controller
15 ${host_index} Builtin.Convert To Integer ${host_index}
16 ${cfg} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_DATA_FILE} ${host_index}
18 Builtin.Should Match Regexp ${cfg} .*${EXP_DATA_FILE}
19 ${mdl} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${MODELS_FILE} ${host_index}
21 Builtin.Should Match Regexp ${mdl} .*${MODELS_FILE}
22 ${opr} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_OPER_FILE} ${host_index}
24 Builtin.Should Match Regexp ${opr} .*${EXP_OPER_FILE}
26 Verify Export Files Not Present
27 [Arguments] ${host_index}
28 [Documentation] Verify if the backedup files are not present in the controller
29 ${host_index} Builtin.Convert To Integer ${host_index}
30 ${cfg} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_DATA_FILE} ${host_index}
32 Builtin.Should Not Match Regexp ${cfg} .*${EXP_DATA_FILE}
33 ${mdl} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${MODELS_FILE} ${host_index}
35 Builtin.Should Not Match Regexp ${mdl} .*${MODELS_FILE}
36 ${opr} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${EXP_OPER_FILE} ${host_index}
38 Builtin.Should Not Match Regexp ${opr} .*${EXP_OPER_FILE}
40 Cleanup The Export Files
41 [Arguments] ${host_index}
42 [Documentation] Verify if the export directory exists and delete the files if needed
43 ${host_index} Builtin.Convert To Integer ${host_index}
44 Builtin.Run Keyword And Ignore Error ClusterManagement.Delete And Check Member List Or All ${TOPOLOGY_URL} ${host_index}
45 ${output1} Builtin.Run Keyword and IgnoreError ClusterManagement.Run Bash Command On Member sudo rm -rf ${WORKSPACE}/${BUNDLEFOLDER}/daexim;clear ${host_index}
46 ${output2} Builtin.Run Keyword and IgnoreError ClusterManagement.Run Bash Command On Member rm -rf ${WORKSPACE}/${BUNDLEFOLDER}/daexim;clear ${host_index}
47 ${output} ClusterManagement.Run Bash Command On Member ls -lart ${WORKSPACE}/${BUNDLEFOLDER} ${host_index}
49 Builtin.Should Not Match Regexp ${output} daexim
52 [Arguments] ${status} ${controller_index}
53 [Documentation] Verify export status is as expected
54 ${response_json} ClusterManagement.Post As Json To Member ${STATUS_EXPORT_URL} ${EMPTY} ${controller_index}
55 Builtin.Log ${response_json}
56 ${response_json} Builtin.Convert To String ${response_json}
57 Verify Export Status Message ${status} ${response_json}
59 Verify Scheduled Export Timestamp
60 [Arguments] ${controller_index} ${time}
61 [Documentation] Verify export timestamp is as expected
62 ${response_json} ClusterManagement.Post As Json To Member ${STATUS_EXPORT_URL} ${EMPTY} ${controller_index}
63 Builtin.Log ${response_json}
64 ${response_json} Builtin.Convert To String ${response_json}
65 Builtin.Should Match Regexp ${response_json} .*"run-at": "${time}"
67 Verify Export Status Message
68 [Arguments] ${status} ${output}
69 [Documentation] Verify export restconf response message is as expected
70 Builtin.Should Match Regexp ${output} "status": "${status}"
71 Builtin.Run Keyword If "${status}" == "initial" or "${status}" == "scheduled" or "${status}" == "skipped" Verify Json Files Not Present ${output}
72 ... ELSE Verify Json Files Present ${output}
74 Verify Json Files Present
75 [Arguments] ${output} ${config_json}=${EXP_DATA_FILE} ${models_json}=${MODELS_FILE} ${operational_json}=${EXP_OPER_FILE}
76 [Documentation] Verify if the json files are generated after a export/export
77 Builtin.Should Match Regexp ${output} .*${config_json}
78 Builtin.Should Match Regexp ${output} .*${models_json}
79 Builtin.Should Match Regexp ${output} .*${operational_json}
80 Builtin.Log Found all Json Files
82 Verify Json Files Not Present
83 [Arguments] ${output} ${config_json}=${EXP_DATA_FILE} ${models_json}=${MODELS_FILE} ${operational_json}=${EXP_OPER_FILE}
84 [Documentation] Verify if the json files are not present under the daexim folder
85 Builtin.Should Not Match Regexp ${output} .*${config_json}
86 Builtin.Should Not Match Regexp ${output} .*${models_json}
87 Builtin.Should Not Match Regexp ${output} .*${operational_json}
88 Builtin.Log Did not Find all Json Files
91 [Arguments] ${controller_index} ${time}=500 ${exclude}=${FALSE} ${module}=${EMPTY} ${store}=${EMPTY} ${flag}=false
92 ... ${include}=${FALSE}
93 [Documentation] Schedule Export job
94 ${file} = Builtin.Run Keyword If ${include} Builtin.Set Variable ${EXPORT_INCLUDE_FILE}
95 ... ELSE Builtin.Set Variable If ${exclude} ${EXPORT_EXCLUDE_FILE} ${EXPORT_FILE}
96 ${json} OperatingSystem.Get File ${file}
97 ${json} Builtin.Replace Variables ${json}
98 Cleanup The Export Files ${controller_index}
99 ${response_json} ClusterManagement.Post As Json To Member ${SCHEDULE_EXPORT_URL} ${json} ${controller_index}
100 Builtin.Log ${response_json}
102 Schedule Exclude Export
103 [Arguments] ${controller_index} ${store} ${module}
104 [Documentation] Schedules a export with exclude option. Returns the file that has the excluded export.
105 ${controller_index} Builtin.Convert To Integer ${controller_index}
106 ${host} ClusterManagement.Resolve IP Address For Member ${controller_index}
107 Schedule Export ${controller_index} 500 ${TRUE} ${module} ${store}
108 Builtin.Wait Until Keyword Succeeds 10 sec 5 sec Verify Export Status complete ${controller_index}
109 Verify Export Files ${controller_index}
110 Copy Export Directory To Test VM ${host}
111 ${export_file} Builtin.Set Variable If '${store}' == 'operational' ${EXP_OPER_FILE} ${EXP_DATA_FILE}
112 ${file_path} OperatingSystem.Join Path ${EXP_DIR}${host} ${export_file}
113 [Return] ${file_path}
115 Schedule Include Export
116 [Arguments] ${controller_index} ${store} ${module}=${EMPTY} ${exclude}=${FALSE}
117 [Documentation] Schedules a export with include option. Returns the file that has the included export.
118 ${controller_index} Builtin.Convert To Integer ${controller_index}
119 ${host} ClusterManagement.Resolve IP Address For Member ${controller_index}
120 ${time} Builtin.Set Variable 500
121 ${file} = Builtin.Set Variable If ${exclude} ${EXPORT_INCEXCLUDE_FILE} ${EXPORT_INCLUDE_FILE}
122 ${json} OperatingSystem.Get File ${file}
123 ${json} Builtin.Replace Variables ${json}
124 Cleanup The Export Files ${controller_index}
125 ${response_json} ClusterManagement.Post As Json To Member ${SCHEDULE_EXPORT_URL} ${json} ${controller_index}
126 Builtin.Log ${response_json}
127 Builtin.Wait Until Keyword Succeeds 10 sec 5 sec Verify Export Status complete ${controller_index}
128 Verify Export Files ${controller_index}
129 Copy Export Directory To Test VM ${host}
130 ${export_file} Builtin.Set Variable If '${store}' == 'operational' ${EXP_OPER_FILE} ${EXP_DATA_FILE}
131 ${file_path} OperatingSystem.Join Path ${EXP_DIR}${host} ${export_file}
132 [Return] ${file_path}
135 [Arguments] ${controller_index}
136 [Documentation] Cancel the export job
137 ${response_json} ClusterManagement.Post As Json To Member ${CANCEL_EXPORT_URL} ${EMPTY} ${controller_index}
138 Builtin.Log ${response_json}
141 [Arguments] ${system}=${ODL_SYSTEM_IP} ${prompt}=${DEFAULT_LINUX_PROMPT} ${prompt_timeout}=${DEFAULT_TIMEOUT} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD}
142 [Documentation] Returns the connection of any host. Defaults to controller
143 ${conn_id} SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${prompt_timeout}
144 SSHKeywords.Flexible SSH Login ${user} ${password}
149 [Documentation] Cleans up the given directory if it exists
150 OperatingSystem.Empty Directory ${dir}
151 OperatingSystem.Remove Directory ${dir}
153 Copy Export Directory To Test VM
155 [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
156 ${new_dir} Builtin.Set Variable ${EXP_DIR}${host}
157 ${directory_exist} Builtin.Run Keyword And Return Status OperatingSystem.Directory Should Exist ${new_dir}
158 Builtin.Run Keyword If ${directory_exist} Cleanup Directory ${new_dir}
159 ${connections} Return ConnnectionID ${host}
160 SSHLibrary.Switch Connection ${connections}
161 SSHLibrary.Directory Should Exist ${WORKSPACE}/${BUNDLEFOLDER}/daexim
162 SSHLibrary.Get Directory ${WORKSPACE}/${BUNDLEFOLDER}/daexim ${new_dir}
163 SSHLibrary.Close Connection
164 ${output} OperatingSystem.List Files In Directory ${new_dir}
165 Builtin.Log ${output}
166 ${fl} OperatingSystem.Get File ${new_dir}/${EXP_DATA_FILE}
169 Copy Config Data To Controller
170 [Arguments] ${host_index}
171 [Documentation] This keyword copies the daexim folder under variables folder to the Controller
172 ${host_index} Builtin.Convert To Integer ${host_index}
173 ${host} ClusterManagement.Resolve IP Address For Member ${host_index}
174 ${connections} Return ConnnectionID ${host}
175 SSHLibrary.Switch Connection ${connections}
176 SSHLibrary.Put Directory ${CURDIR}/${DAEXIM_DATA_DIRECTORY} ${WORKSPACE}/${BUNDLEFOLDER}/ mode=664
177 SSHLibrary.Close Connection
179 Mount Netconf Endpoint
180 [Arguments] ${endpoint} ${host_index}
181 [Documentation] Mount a netconf endpoint
182 ${ENDPOINT} Builtin.Set Variable ${endpoint}
183 ${json} OperatingSystem.Get File ${CURDIR}/${NETCONF_PAYLOAD_JSON}
184 ${json} Builtin.Replace Variables ${json}
186 ${resp} ClusterManagement.Put As Json To Member ${NETCONF_MOUNT_URL}${endpoint} ${json} ${host_index}
189 Fetch Status Information From Netconf Endpoint
190 [Arguments] ${endpoint} ${host_index}
191 [Documentation] This keyword fetches netconf endpoint information
192 ${resp} ClusterManagement.Get From Member ${NTCF_TPLG_OPR_URL}${endpoint} ${host_index}
193 ${output1} Builtin.Set Variable ${resp}
194 ${output} RequestsLibrary.To Json ${output1}
195 Builtin.Log ${output}
196 ${status} Collections.Get From Dictionary ${output['node'][0]} netconf-node-topology:connection-status
197 [Return] ${status} ${output}
199 Verify Status Information
200 [Arguments] ${endpoint} ${host_index} ${itr}=50
201 [Documentation] Verify if a netconf endpoint status is connected by running in a loop
202 : FOR ${i} IN RANGE ${itr}
203 \ ${sts} ${op} Fetch Status Information From Netconf Endpoint ${endpoint} ${host_index}
205 \ Builtin.Exit For Loop If "${sts}" == "${NTCF_OPR_STATUS}"
206 [Return] ${sts} ${op}
209 [Arguments] ${endpoint} ${host_index}
210 [Documentation] Verify if a netconf endpoint is mounted
211 ${sts1} ${output} Verify Status Information ${endpoint} ${host_index}
212 ${ep} Collections.Get From Dictionary ${output['node'][0]} node-id
213 ${port} Collections.Get From Dictionary ${output['node'][0]} netconf-node-topology:port
214 ${port} Builtin.Convert To String ${port}
215 Builtin.Should Be Equal ${endpoint} ${ep}
216 Builtin.Should Be Equal ${port} ${NETCONF_PORT}
219 [Arguments] ${host_index} ${result}=true ${reason}=${EMPTY} ${mdlflag}=${MDL_DEF_FLAG} ${strflag}=${STR_DEF_FLAG}
220 [Documentation] Schedule an Import API
221 ${modelflag} Builtin.Set Variable ${mdlflag}
222 ${storeflag} Builtin.Set Variable ${strflag}
223 ${json} OperatingSystem.Get File ${CURDIR}/${IMPORT_PAYLOAD}
224 ${json} Builtin.Replace Variables ${json}
226 ${resp} Builtin.Wait Until Keyword Succeeds 120 seconds 10 seconds ClusterManagement.Post As Json To Member ${IMPORT_URL} ${json}
229 Builtin.Should Match Regexp ${resp} .*"result": ${result}
230 Builtin.Run Keyword If "${reason}" != "${EMPTY}" Builtin.Should Match Regexp ${response_json} .*"reason":"${reason}
232 Cleanup Cluster Export Files
233 [Arguments] ${member_index_list}=${EMPTY}
234 [Documentation] This keyword cleansup export files of a cluster
235 ${index_list} = List Indices Or All given_list=${member_index_list}
236 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
237 \ DaeximKeywords.Cleanup The Export Files ${index}