Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / libraries / DaeximKeywords.robot
1 *** Settings ***
2 Library           OperatingSystem
3 Library           SSHLibrary
4 Library           Collections
5 Library           RequestsLibrary
6 Resource          ClusterManagement.robot
7 Resource          ../variables/daexim/DaeximVariables.robot
8 Resource          ../variables/Variables.robot
9 Resource          SSHKeywords.robot
10
11 *** Keywords ***
12 Verify Export Files
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}
17     Builtin.Log    ${cfg}
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}
20     Builtin.Log    ${mdl}
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}
23     Builtin.Log    ${opr}
24     Builtin.Should Match Regexp    ${opr}    .*${EXP_OPER_FILE}
25
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}
31     Builtin.Log    ${cfg}
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}
34     Builtin.Log    ${mdl}
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}
37     Builtin.Log    ${opr}
38     Builtin.Should Not Match Regexp    ${opr}    .*${EXP_OPER_FILE}
39
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}
48     Builtin.Log    ${output}
49     Builtin.Should Not Match Regexp    ${output}    daexim
50
51 Verify Export Status
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}
58
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}"
66
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}
73
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
81
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
89
90 Schedule Export
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}
101
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}
114
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}
133
134 Cancel Export
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}
139
140 Return ConnnectionID
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}
145     [Return]    ${conn_id}
146
147 Cleanup Directory
148     [Arguments]    ${dir}
149     [Documentation]    Cleans up the given directory if it exists
150     OperatingSystem.Empty Directory    ${dir}
151     OperatingSystem.Remove Directory    ${dir}
152
153 Copy Export Directory To Test VM
154     [Arguments]    ${host}
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}
167     Builtin.Log    ${fl}
168
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
178
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}
185     Builtin.Log    ${json}
186     ${resp}    ClusterManagement.Put As Json To Member    ${NETCONF_MOUNT_URL}${endpoint}    ${json}    ${host_index}
187     Builtin.Log    ${resp}
188
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}
198
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}
204         Builtin.Log    ${i}
205         Builtin.Exit For Loop If    "${sts}" == "${NTCF_OPR_STATUS}"
206     END
207     [Return]    ${sts}    ${op}
208
209 Verify Netconf Mount
210     [Arguments]    ${endpoint}    ${host_index}
211     [Documentation]    Verify if a netconf endpoint is mounted
212     ${sts1}    ${output}    Verify Status Information    ${endpoint}    ${host_index}
213     ${ep}    Collections.Get From Dictionary    ${output['node'][0]}    node-id
214     ${port}    Collections.Get From Dictionary    ${output['node'][0]}    netconf-node-topology:port
215     ${port}    Builtin.Convert To String    ${port}
216     Builtin.Should Be Equal    ${endpoint}    ${ep}
217     Builtin.Should Be Equal    ${port}    ${NETCONF_PORT}
218
219 Schedule Import
220     [Arguments]    ${host_index}    ${result}=true    ${reason}=${EMPTY}    ${mdlflag}=${MDL_DEF_FLAG}    ${strflag}=${STR_DEF_FLAG}
221     [Documentation]    Schedule an Import API
222     ${modelflag}    Builtin.Set Variable    ${mdlflag}
223     ${storeflag}    Builtin.Set Variable    ${strflag}
224     ${json}    OperatingSystem.Get File    ${CURDIR}/${IMPORT_PAYLOAD}
225     ${json}    Builtin.Replace Variables    ${json}
226     Builtin.Log    ${json}
227     ${resp}    Builtin.Wait Until Keyword Succeeds    120 seconds    10 seconds    ClusterManagement.Post As Json To Member    ${IMPORT_URL}    ${json}
228     ...    ${host_index}
229     Builtin.Log    ${resp}
230     Builtin.Should Match Regexp    ${resp}    .*"result": ${result}
231     Builtin.Run Keyword If    "${reason}" != "${EMPTY}"    Builtin.Should Match Regexp    ${response_json}    .*"reason":"${reason}
232
233 Cleanup Cluster Export Files
234     [Arguments]    ${member_index_list}=${EMPTY}
235     [Documentation]    This keyword cleansup export files of a cluster
236     ${index_list} =    List Indices Or All    given_list=${member_index_list}
237     FOR    ${index}    IN    @{index_list}    # usually: 1, 2, 3.
238         DaeximKeywords.Cleanup The Export Files    ${index}
239     END