Bump pre-commit-hooks to v4.1.0
[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 *** Keywords ***
15 Set Global Variable If It Does Not Exist
16     [Arguments]    ${name}    ${value}
17     [Documentation]    Checks whether a given variable has been defined. If it does not, sets the passed value to that global variable
18     ${status}    ${message} =    Run Keyword And Ignore Error    Variable Should Exist    ${name}
19     Run Keyword If    "${status}" == "FAIL"    Set Global Variable    ${name}    ${value}
20
21 Perform Export
22     [Arguments]    ${controller_index}
23     [Documentation]    schedule a basic export/backup, waiting for completion
24     [Tags]    create backup
25     DaeximKeywords.Schedule Export    ${controller_index}
26     DaeximKeywords.Verify Export Status    ${EXPORT_SCHEDULED_STATUS}    ${controller_index}
27     Builtin.Wait Until Keyword Succeeds    10 sec    5 sec    DaeximKeywords.Verify Export Status    ${EXPORT_COMPLETE_STATUS}    ${controller_index}
28     DaeximKeywords.Verify Export Files    ${controller_index}
29
30 ConditionalBackupRestoreCheck
31     [Arguments]    ${exclusionsConfigBefore}=${EMPTY}    ${exclusionsConfigAfter}=${EMPTY}    ${exclusionsOperationalBefore}=${EMPTY}    ${exclusionsOperationalAfter}=${EMPTY}    ${odlControllerIndex}=${FIRST_CONTROLLER_INDEX}
32     [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)
33     Set Global Variable If It Does Not Exist    \${BR_TESTING_ENABLED}    FALSE
34     Return From Keyword If    '${BR_TESTING_ENABLED}'!='true'
35     BackupRestoreCheck    ${exclusionsConfigBefore}    ${exclusionsConfigAfter}    ${exclusionsOperationalBefore}    ${exclusionsOperationalAfter}    ${odlControllerIndex}
36
37 BackupRestoreCheck
38     [Arguments]    ${exclusionsConfigBefore}=${EMPTY}    ${exclusionsConfigAfter}=${EMPTY}    ${exclusionsOperationalBefore}=${EMPTY}    ${exclusionsOperationalAfter}=${EMPTY}    ${odlControllerIndex}=${FIRST_CONTROLLER_INDEX}
39     [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)
40     Log    Performing backup-restore check
41     ${ARG_CONFIG_BEFORE}=    Set Variable    ' '
42     ${ARG_CONFIG_AFTER}=    Set Variable    ' '
43     ${ARG_OPER_BEFORE}=    Set Variable    ' '
44     ${ARG_OPER_AFTER}=    Set Variable    ' '
45     ${ARG_CONFIG_BEFORE}=    Run Keyword If    '${exclusionsConfigBefore}'!='${EMPTY}'    '${exclusionsConfigBefore}'
46     ${ARG_CONFIG_AFTER}=    Run Keyword If    '${exclusionsConfigAfter}'!='${EMPTY}'    '${exclusionsConfigAfter}'
47     ${ARG_OPER_BEFORE}=    Run Keyword If    '${exclusionsOperationalBefore}'!='${EMPTY}'    Normalize Path    ${CURDIR}/${exclusionsOperationalBefore}
48     ${ARG_OPER_AFTER}=    Run Keyword If    '${exclusionsOperationalAfter}'!='${EMPTY}'    Normalize Path    ${CURDIR}/${exclusionsOperationalAfter}
49     ${controller_index}    Builtin.Convert To Integer    ${odlControllerIndex}
50     Perform Export    ${controller_index}
51     ${host}    ClusterManagement.Resolve IP Address For Member    ${controller_index}
52     ${directory_exist}    Builtin.Run Keyword And Return Status    OperatingSystem.Directory Should Exist    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}
53     Builtin.Run Keyword If    ${directory_exist}    Cleanup Directory    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}
54     Copy Export Directory To Test VM    ${host}
55     OperatingSystem.Move Directory    ${EXP_DIR}${host}    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}
56     #
57     # TODO: Insert The Backup + Restore call here
58     #
59     Log    doing the second export!
60     Perform Export    ${controller_index}
61     Copy Export Directory To Test VM    ${host}
62     ${directory_exist}    Builtin.Run Keyword And Return Status    OperatingSystem.Directory Should Exist    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}
63     Builtin.Run Keyword If    ${directory_exist}    Cleanup Directory    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}
64     OperatingSystem.Move Directory    ${EXP_DIR}${host}    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}
65     log    "Performing comparison"
66     ${differencesConfigDatastore}=    Json Diff Check Keyword    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}/${EXP_DATA_FILE}    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}/${EXP_DATA_FILE}    ${ARG_CONFIG_BEFORE}    ${ARG_CONFIG_AFTER}
67     ${differencesOperationalDatastore}=    Json Diff Check Keyword    ${EXP_DIR}/${RELATIVE_BEFORE_BACKUP_DIR}/${EXP_OPER_FILE}    ${EXP_DIR}/${RELATIVE_AFTER_RESTORE_DIR}/${EXP_OPER_FILE}    ${ARG_OPER_BEFORE}    ${ARG_OPER_AFTER}
68     Should Be Equal    '0'    '${differencesConfigDatastore}'    Error: Diferences found in the config DS before backup / after restore
69     Should Be Equal    '0'    '${differencesOperationalDatastore}'    Error: Diferences found in the config DS before backup / after restore