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 ${JSON1} OperatingSystem.Get File ${file}
97 ${JSON2} Builtin.Replace Variables ${JSON1}
98 Cleanup The Export Files ${controller_index}
99 ${response_json} ClusterManagement.Post_As_Json_To_Member ${SCHEDULE_EXPORT_URL} ${JSON2} ${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}
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 Schedule Export ${controller_index} 500 ${FALSE} ${module} ${store} ${TRUE}
121 Builtin.Wait Until Keyword Succeeds 10 sec 5 sec Verify Export Status complete ${controller_index}
122 Verify Export Files ${controller_index}
123 Copy Export Directory To Test VM ${host}
124 ${export_file} Builtin.Set Variable If '${store}' == 'operational' ${EXP_OPER_FILE} ${EXP_DATA_FILE}
125 ${file_path} OperatingSystem.Join Path ${EXP_DIR}${host} ${export_file}
126 [Return] ${file_path}
129 [Arguments] ${controller_index}
130 [Documentation] Cancel the export job
131 ${response_json} ClusterManagement.Post_As_Json_To_Member ${CANCEL_EXPORT_URL} ${EMPTY} ${controller_index}
132 Builtin.Log ${response_json}
135 [Arguments] ${system}=${ODL_SYSTEM_IP} ${prompt}=${DEFAULT_LINUX_PROMPT} ${prompt_timeout}=${DEFAULT_TIMEOUT} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD}
136 [Documentation] Returns the connection of any host. Defaults to controller
137 ${conn_id} SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${prompt_timeout}
138 SSHKeywords.Flexible SSH Login ${user} ${password}
143 [Documentation] Cleans up the given directory if it exists
144 OperatingSystem.Empty Directory ${dir}
145 OperatingSystem.Remove Directory ${dir}
147 Copy Export Directory To Test VM
149 [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
150 ${new_dir} Builtin.Set Variable ${EXP_DIR}${host}
151 ${directory_exist} Builtin.Run Keyword And Return Status OperatingSystem.Directory Should Exist ${new_dir}
152 Builtin.Run Keyword If ${directory_exist} Cleanup Directory ${new_dir}
153 ${connections} Return ConnnectionID ${host}
154 SSHLibrary.Switch Connection ${connections}
155 SSHLibrary.Directory Should Exist ${WORKSPACE}/${BUNDLEFOLDER}/daexim
156 SSHLibrary.Get Directory ${WORKSPACE}/${BUNDLEFOLDER}/daexim ${new_dir}
157 SSHLibrary.Close Connection
158 ${output} OperatingSystem.List Files In Directory ${new_dir}
159 Builtin.Log ${output}
160 ${fl} OperatingSystem.Get File ${new_dir}/${EXP_DATA_FILE}
163 Copy Config Data To Controller
164 [Arguments] ${host_index}
165 [Documentation] This keyword copies the daexim folder under variables folder to the Controller
166 ${host_index} Builtin.Convert To Integer ${host_index}
167 ${host} ClusterManagement.Resolve IP Address For Member ${host_index}
168 ${connections} Return ConnnectionID ${host}
169 SSHLibrary.Switch Connection ${connections}
170 SSHLibrary.Put Directory ${CURDIR}/${DAEXIM_DATA_DIRECTORY} ${WORKSPACE}/${BUNDLEFOLDER}/ mode=664
171 SSHLibrary.Close Connection
173 Mount Netconf Endpoint
174 [Arguments] ${endpoint} ${host_index}
175 [Documentation] Mount a netconf endpoint
176 ${ENDPOINT} Builtin.Set Variable ${endpoint}
177 ${JSON1} OperatingSystem.Get File ${CURDIR}/${NETCONF_PAYLOAD_JSON}
178 ${JSON2} Builtin.Replace Variables ${JSON1}
180 ${resp} ClusterManagement.Put_As_Json_To_Member ${NETCONF_MOUNT_URL}${endpoint} ${JSON2} ${host_index}
183 Fetch Status Information From Netconf Endpoint
184 [Arguments] ${endpoint} ${host_index}
185 [Documentation] This keyword fetches netconf endpoint information
186 ${resp} ClusterManagement.Get_From_Member ${NTCF_TPLG_OPR_URL}${endpoint} ${host_index}
187 ${output1} Builtin.Set Variable ${resp}
188 ${output} RequestsLibrary.To Json ${output1}
189 Builtin.Log ${output}
190 ${status} Collections.Get From Dictionary ${output['node'][0]} netconf-node-topology:connection-status
191 [Return] ${status} ${output}
193 Verify Status Information
194 [Arguments] ${endpoint} ${host_index} ${itr}=50
195 [Documentation] Verify if a netconf endpoint status is connected by running in a loop
196 : FOR ${i} IN RANGE ${itr}
197 \ ${sts} ${op} Fetch Status Information From Netconf Endpoint ${endpoint} ${host_index}
199 \ Builtin.Exit For Loop If "${sts}" == "${NTCF_OPR_STATUS}"
200 [Return] ${sts} ${op}
203 [Arguments] ${endpoint} ${host_index}
204 [Documentation] Verify if a netconf endpoint is mounted
205 ${sts1} ${output} Verify Status Information ${endpoint} ${host_index}
206 ${ep} Collections.Get From Dictionary ${output['node'][0]} node-id
207 ${port} Collections.Get From Dictionary ${output['node'][0]} netconf-node-topology:port
208 ${port} Builtin.Convert To String ${port}
209 Builtin.Should Be Equal ${endpoint} ${ep}
210 Builtin.Should Be Equal ${port} ${NETCONF_PORT}
213 [Arguments] ${host_index} ${result}=true ${reason}=${EMPTY} ${mdlflag}=${MDL_DEF_FLAG} ${strflag}=${STR_DEF_FLAG}
214 [Documentation] Schedule an Import API
215 ${MODELFLAG} Builtin.Set Variable ${mdlflag}
216 ${STOREFLAG} Builtin.Set Variable ${strflag}
217 ${JSON1} OperatingSystem.Get File ${CURDIR}/${IMPORT_PAYLOAD}
218 ${JSON2} Builtin.Replace Variables ${JSON1}
220 ${resp} Builtin.Wait Until Keyword Succeeds 120 seconds 10 seconds ClusterManagement.Post_As_Json_To_Member ${IMPORT_URL} ${JSON2}
223 Builtin.Should Match Regexp ${resp} .*"result": ${result}
224 Builtin.Run Keyword If "${reason}" != "${EMPTY}" Builtin.Should Match Regexp ${response_json} .*"reason":"${reason}
226 Cleanup Cluster Export Files
227 [Arguments] ${member_index_list}=${EMPTY}
228 [Documentation] This keyword cleansup export files of a cluster
229 ${index_list} = List_Indices_Or_All given_list=${member_index_list}
230 : FOR ${index} IN @{index_list} # usually: 1, 2, 3.
231 \ DaeximKeywords.Cleanup The Export Files ${index}