Add argon stream keywords
[integration/test.git] / csit / libraries / BackupRestoreKeywords.robot
1 *** Settings ***
2 Library     OperatingSystem
3 Library     SSHLibrary
4 Library     Collections
5 Library     RequestsLibrary
6 Library     backuprestore/JsonDiffTool.py
7 Resource    ClusterManagement.robot
8 Resource    ../variables/daexim/DaeximVariables.robot
9 Resource    DaeximKeywords.robot
10 Resource    ../variables/backuprestore/BackupRestoreVariables.robot
11 Resource    ../variables/Variables.robot
12 Resource    Utils.robot
13
14
15 *** Keywords ***
16 Set Global Variable If It Does Not Exist
17     [Documentation]    Checks whether a given variable has been defined. If it does not, sets the passed value to that global variable
18     [Arguments]    ${name}    ${value}
19     ${status}    ${message}=    Run Keyword And Ignore Error    Variable Should Exist    ${name}
20     IF    "${status}" == "FAIL"    Set Global Variable    ${name}    ${value}
21
22 Perform Export
23     [Documentation]    schedule a basic export/backup, waiting for completion
24     [Tags]    create backup
25     [Arguments]    ${controller_index}
26     DaeximKeywords.Schedule Export    ${controller_index}
27     DaeximKeywords.Verify Export Status    ${EXPORT_SCHEDULED_STATUS}    ${controller_index}
28     Builtin.Wait Until Keyword Succeeds
29     ...    10 sec
30     ...    5 sec
31     ...    DaeximKeywords.Verify Export Status
32     ...    ${EXPORT_COMPLETE_STATUS}
33     ...    ${controller_index}
34     DaeximKeywords.Verify Export Files    ${controller_index}
35
36 ConditionalBackupRestoreCheck
37     [Documentation]    When enabled, performs a datastore export, then a backup, then a restore, then an export. The check is considered to be failed when exports before and after are different (two different json path files can be passed in order to filter certain subtrees from the export files before / after the export)
38     [Arguments]    ${exclusionsConfigBefore}=${EMPTY}    ${exclusionsConfigAfter}=${EMPTY}    ${exclusionsOperationalBefore}=${EMPTY}    ${exclusionsOperationalAfter}=${EMPTY}    ${odlControllerIndex}=${FIRST_CONTROLLER_INDEX}
39     Set Global Variable If It Does Not Exist    \${BR_TESTING_ENABLED}    FALSE
40     IF    '${BR_TESTING_ENABLED}'!='true'    RETURN
41     BackupRestoreCheck
42     ...    ${exclusionsConfigBefore}
43     ...    ${exclusionsConfigAfter}
44     ...    ${exclusionsOperationalBefore}
45     ...    ${exclusionsOperationalAfter}
46     ...    ${odlControllerIndex}
47
48 BackupRestoreCheck
49     [Documentation]    When enabled, performs a datastore export, then a backup, then a restore, then an export. The check is considered to be failed when exports before and after are different (two different json path files can be passed in order to filter certain subtrees from the export files before / after the export)
50     [Arguments]    ${exclusionsConfigBefore}=${EMPTY}    ${exclusionsConfigAfter}=${EMPTY}    ${exclusionsOperationalBefore}=${EMPTY}    ${exclusionsOperationalAfter}=${EMPTY}    ${odlControllerIndex}=${FIRST_CONTROLLER_INDEX}
51     Log    Performing backup-restore check
52     ${ARG_CONFIG_BEFORE}=    Set Variable    ' '
53     ${ARG_CONFIG_AFTER}=    Set Variable    ' '
54     ${ARG_OPER_BEFORE}=    Set Variable    ' '
55     ${ARG_OPER_AFTER}=    Set Variable    ' '
56     IF    '${exclusionsConfigBefore}'!='${EMPTY}'
57         ${ARG_CONFIG_BEFORE}=    '${exclusionsConfigBefore}'
58     ELSE
59         ${ARG_CONFIG_BEFORE}=    Set Variable    ${None}
60     END
61     IF    '${exclusionsConfigAfter}'!='${EMPTY}'
62         ${ARG_CONFIG_AFTER}=    '${exclusionsConfigAfter}'
63     ELSE
64         ${ARG_CONFIG_AFTER}=    Set Variable    ${None}
65     END
66     IF    '${exclusionsOperationalBefore}'!='${EMPTY}'
67         ${ARG_OPER_BEFORE}=    Normalize Path    ${CURDIR}/${exclusionsOperationalBefore}
68     ELSE
69         ${ARG_OPER_BEFORE}=    Set Variable    ${None}
70     END
71     IF    '${exclusionsOperationalAfter}'!='${EMPTY}'
72         ${ARG_OPER_AFTER}=    Normalize Path    ${CURDIR}/${exclusionsOperationalAfter}
73     ELSE
74         ${ARG_OPER_AFTER}=    Set Variable    ${None}
75     END
76     ${controller_index}=    Builtin.Convert To Integer    ${odlControllerIndex}
77     Perform Export    ${controller_index}
78     ${host}=    ClusterManagement.Resolve IP Address For Member    ${controller_index}
79     ${directory_exist}=    Builtin.Run Keyword And Return Status
80     ...    OperatingSystem.Directory Should Exist
81     ...    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}
82     IF    ${directory_exist}
83         Cleanup Directory    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}
84     END
85     Copy Export Directory To Test VM    ${host}
86     OperatingSystem.Move Directory    ${EXP_DIR}${host}    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}
87     #
88     # TODO: Insert The Backup + Restore call here
89     #
90     Log    doing the second export!
91     Perform Export    ${controller_index}
92     Copy Export Directory To Test VM    ${host}
93     ${directory_exist}=    Builtin.Run Keyword And Return Status
94     ...    OperatingSystem.Directory Should Exist
95     ...    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}
96     IF    ${directory_exist}
97         Cleanup Directory    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}
98     END
99     OperatingSystem.Move Directory    ${EXP_DIR}${host}    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}
100     log    "Performing comparison"
101     ${differencesConfigDatastore}=    Json Diff Check Keyword
102     ...    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}/${EXP_DATA_FILE}
103     ...    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}/${EXP_DATA_FILE}
104     ...    ${ARG_CONFIG_BEFORE}
105     ...    ${ARG_CONFIG_AFTER}
106     ${differencesOperationalDatastore}=    Json Diff Check Keyword
107     ...    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}/${EXP_OPER_FILE}
108     ...    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}/${EXP_OPER_FILE}
109     ...    ${ARG_OPER_BEFORE}
110     ...    ${ARG_OPER_AFTER}
111     Should Be Equal
112     ...    '0'
113     ...    '${differencesConfigDatastore}'
114     ...    Error: Diferences found in the config DS before backup / after restore
115     Should Be Equal
116     ...    '0'
117     ...    '${differencesOperationalDatastore}'
118     ...    Error: Diferences found in the config DS before backup / after restore