Basic Tests for DAEXIM project
[integration/test.git] / csit / libraries / DaeximKeywords.robot
1 *** Settings ***
2 Library           OperatingSystem
3 Library           SSHLibrary
4 Resource          ClusterManagement.robot
5 Resource          ../variables/Variables.robot
6 Resource          ../variables/daexim/DaeximVariables.robot
7 Variables         ../variables/Variables.py
8 Resource          ../variables/Variables.robot
9 Resource          Utils.robot
10
11 *** Keywords ***
12 Verify Backup 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}    ${rc}    ClusterManagement.Run Bash Command On Member    ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${BKP_DATA_FILE}    ${host_index}
17     Builtin.Run Keyword If    "${rc}" != "0"    Builtin.Fail    Return code is not equal to zero on this command
18     ...    ELSE    Builtin.Log    ${cfg}
19     ${mdl}    ${rc}    ClusterManagement.Run Bash Command On Member    ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${MODELS_FILE}    ${host_index}
20     Builtin.Run Keyword If    "${rc}" != "0"    Builtin.Fail    Return code is not equal to zero on this command
21     ...    ELSE    Builtin.Log    ${mdl}
22     ${opr}    ${rc}    ClusterManagement.Run Bash Command On Member    ls -lart ${WORKSPACE}/${BUNDLEFOLDER}/daexim/${BKP_OPER_FILE}    ${host_index}
23     Builtin.Run Keyword If    "${rc}" != "0"    Builtin.Fail    Return code is not equal to zero on this command
24     ...    ELSE    Builtin.Log    ${opr}
25
26 Cleanup The Backup Files
27     [Arguments]    ${host_index}
28     [Documentation]    Verify if the backup directory exists and delete the files if needed
29     ${host_index}    Builtin.Convert To Integer    ${host_index}
30     ${output}    ${rc}    ClusterManagement.Run Bash Command On Member    sudo rm -rf ${WORKSPACE}/${BUNDLEFOLDER}/daexim    ${host_index}
31     Builtin.Run Keyword If    "${rc}" != "0"    Fail    Return code is not equal to zero on this command
32     ...    ELSE    Builtin.Log    ${output}
33
34 Verify Backup Status
35     [Arguments]    ${status}    ${controller_index}
36     [Documentation]    Verify backup status is as expected
37     ${response_json}    ClusterManagement.Post As Json To Member    ${STATUS_BACKUP_URL}    ${EMPTY}    ${controller_index}
38     Builtin.Log    ${response_json}
39     ${response_json}    Builtin.Convert To String    ${response_json}
40     Verify Backup Status Message    ${status}    ${response_json}
41
42 Verify Scheduled Backup Timestamp
43     [Arguments]    ${controller_index}    ${time}
44     [Documentation]    Verify backup timestamp is as expected
45     ${response_json}    ClusterManagement.Post As Json To Member    ${STATUS_BACKUP_URL}    ${EMPTY}    ${controller_index}
46     Builtin.Log    ${response_json}
47     ${response_json}    Builtin.Convert To String    ${response_json}
48     Builtin.Should Match Regexp    ${response_json}    .*"run-at": "${time}"
49
50 Verify Backup Status Message
51     [Arguments]    ${status}    ${output}
52     [Documentation]    Verify backup restconf response message is as expected
53     Builtin.Should Match Regexp    ${output}    "status": "${status}"
54     Builtin.Run Keyword If    "${status}" == "initial" or "${status}" == "scheduled"    Verify Json Files Not Present    ${output}
55     ...    ELSE    Verify Json Files Present    ${output}
56
57 Verify Json Files Present
58     [Arguments]    ${output}    ${config_json}=${BKP_DATA_FILE}    ${models_json}=${MODELS_FILE}    ${operational_json}=${BKP_OPER_FILE}
59     [Documentation]    Verify if the json files are generated after a backup/export
60     Builtin.Should Match Regexp    ${output}    .*${config_json}
61     Builtin.Should Match Regexp    ${output}    .*${models_json}
62     Builtin.Should Match Regexp    ${output}    .*${operational_json}
63     Builtin.Log    Found all Json Files
64
65 Verify Json Files Not Present
66     [Arguments]    ${output}    ${config_json}=${BKP_DATA_FILE}    ${models_json}=${MODELS_FILE}    ${operational_json}=${BKP_OPER_FILE}
67     [Documentation]    Verify if the json files are not present under the daexim folder
68     Builtin.Should Not Match Regexp    ${output}    .*${config_json}
69     Builtin.Should Not Match Regexp    ${output}    .*${models_json}
70     Builtin.Should Not Match Regexp    ${output}    .*${operational_json}
71     Builtin.Log    Did not Find all Json Files
72
73 Schedule Backup
74     [Arguments]    ${controller_index}    ${TIME}=500    ${exclude}=${FALSE}    ${MODULE}=${EMPTY}    ${STORE}=${EMPTY}
75     ${file}    Builtin.Set Variable If    ${exclude}    ${BACKUP_EXCLUDE_FILE}    ${BACKUP_FILE}
76     ${JSON1}    OperatingSystem.Get File    ${file}
77     ${JSON2}    Builtin.Replace Variables    ${JSON1}
78     Cleanup The Backup Files    ${controller_index}
79     ${response_json}    ClusterManagement.Post As Json To Member    ${SCHEDULE_BACKUP_URL}    ${JSON2}    ${controller_index}
80
81 Schedule Exclude Backup
82     [Arguments]    ${controller_index}    ${store}    ${module}
83     [Documentation]    Schedules a backup with exclude option. Returns the file that has the excluded backup.
84     ${controller_index}    Builtin.Convert To Integer    ${controller_index}
85     ${host}    ClusterManagement.Resolve IP Address For Member    ${controller_index}
86     Schedule Backup    ${controller_index}    500    ${TRUE}    ${module}    ${store}
87     Builtin.Wait Until Keyword Succeeds    10 sec    5 sec    Verify Backup Status    complete    ${controller_index}
88     Verify Backup Files    ${controller_index}
89     Copy Backup Directory To Test VM    ${host}
90     ${backup_file}    Builtin.Set Variable If    '${store}' == 'operational'    ${BKP_OPER_FILE}    ${BKP_DATA_FILE}
91     ${file_path}    OperatingSystem.Join Path    ${BKP_DIR}${host}    ${backup_file}
92     [Return]    ${file_path}
93
94 Cancel Backup
95     [Arguments]    ${controller_index}
96     [Documentation]    Cancel the export job
97     ClusterManagement.Post As Json To Member    ${CANCEL_BACKUP_URL}    ${EMPTY}    ${controller_index}
98
99 Return ConnnectionID
100     [Arguments]    ${system}=${ODL_SYSTEM_IP}    ${prompt}=${DEFAULT_LINUX_PROMPT}    ${prompt_timeout}=${DEFAULT_TIMEOUT}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}
101     [Documentation]    Returns the connection of any host. Defaults to controller
102     ${conn_id}    SSHLibrary.Open Connection    ${system}    prompt=${prompt}    timeout=${prompt_timeout}
103     Utils.Flexible SSH Login    ${user}    ${password}
104     [Return]    ${conn_id}
105
106 Cleanup Directory
107     [Arguments]    ${dir}
108     [Documentation]    Cleans up the given directory if it exists
109     OperatingSystem.Empty Directory    ${dir}
110     OperatingSystem.Remove Directory    ${dir}
111
112 Copy Backup Directory To Test VM
113     [Arguments]    ${host}
114     [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
115     ${new_dir}    Builtin.Set Variable    ${BKP_DIR}${host}
116     ${directory_exist}    Builtin.Run Keyword And Return Status    OperatingSystem.Directory Should Exist    ${new_dir}
117     Builtin.Run Keyword If    ${directory_exist}    Cleanup Directory    ${new_dir}
118     ${connections}    Return ConnnectionID    ${host}
119     SSHLibrary.Switch Connection    ${connections}
120     SSHLibrary.Directory Should Exist    ${WORKSPACE}/${BUNDLEFOLDER}/daexim
121     SSHLibrary.Get Directory    ${WORKSPACE}/${BUNDLEFOLDER}/daexim    ${new_dir}
122     SSHLibrary.Close Connection
123     ${output}    OperatingSystem.List Files In Directory    ${new_dir}
124     Builtin.Log    ${output}
125     ${fl}    OperatingSystem.Get File    ${new_dir}/${BKP_DATA_FILE}
126     Builtin.Log    ${fl}