Rename Check Status of Services keyword
[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     ${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}
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}
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}
127
128 Cancel Export
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}
133
134 Return ConnnectionID
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}
139     [Return]    ${conn_id}
140
141 Cleanup Directory
142     [Arguments]    ${dir}
143     [Documentation]    Cleans up the given directory if it exists
144     OperatingSystem.Empty Directory    ${dir}
145     OperatingSystem.Remove Directory    ${dir}
146
147 Copy Export Directory To Test VM
148     [Arguments]    ${host}
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}
161     Builtin.Log    ${fl}
162
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
172
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}
179     Builtin.Log    ${JSON2}
180     ${resp}    ClusterManagement.Put_As_Json_To_Member    ${NETCONF_MOUNT_URL}${endpoint}    ${JSON2}    ${host_index}
181     Builtin.Log    ${resp}
182
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}
192
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}
198     \    Builtin.Log    ${i}
199     \    Builtin.Exit For Loop If    "${sts}" == "${NTCF_OPR_STATUS}"
200     [Return]    ${sts}    ${op}
201
202 Verify Netconf Mount
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}
211
212 Schedule Import
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}
219     Builtin.Log    ${JSON2}
220     ${resp}    Builtin.Wait Until Keyword Succeeds    120 seconds    10 seconds    ClusterManagement.Post_As_Json_To_Member    ${IMPORT_URL}    ${JSON2}
221     ...    ${host_index}
222     Builtin.Log    ${resp}
223     Builtin.Should Match Regexp    ${resp}    .*"result": ${result}
224     Builtin.Run Keyword If    "${reason}" != "${EMPTY}"    Builtin.Should Match Regexp    ${response_json}    .*"reason":"${reason}
225
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}