Scott Baker | 363fc80 | 2019-04-26 18:10:30 -0700 | [diff] [blame] | 1 | # XOS Backup Tests
|
| 2 | #
|
| 3 |
|
| 4 | *** Settings ***
|
| 5 | Documentation Test backup/restore of a models in XOS
|
| 6 | Library RequestsLibrary
|
| 7 | Library HttpLibrary.HTTP
|
| 8 | Library Collections
|
| 9 | Library String
|
| 10 | Library OperatingSystem
|
| 11 | Library DateTime
|
| 12 | Library ../../Framework/utils/utils.py
|
| 13 | Resource ../../Framework/utils/utils.robot
|
| 14 | Library ../../Framework/restApi.py
|
| 15 | Variables ../../Properties/RestApiProperties.py
|
| 16 | Suite Setup Setup
|
| 17 | Suite Teardown Teardown
|
| 18 | Test Template Validate Operation
|
| 19 |
|
| 20 | *** Variables ***
|
| 21 | ${timeout} 300s
|
| 22 | ${fail_try} fail_try_models_
|
| 23 | ${fail_restore} fail_before_restore_
|
| 24 | ${fail_backup} fail_before_backup_
|
| 25 | ${flavor_original} one
|
| 26 | ${flavor_updated} two
|
| 27 |
|
| 28 | *** Test Cases ***
|
| 29 | Backup ${EMPTY} created restored ${flavor_original}
|
| 30 |
|
| 31 | Backup Fail Try ${fail_try} created failed ${flavor_updated}
|
| 32 |
|
| 33 | Backup Fail Before Restore ${fail_restore} created failed ${flavor_updated}
|
| 34 |
|
| 35 | Backup Fail Before Backup ${fail_backup} failed
|
| 36 |
|
| 37 | *** Keywords ***
|
| 38 | Setup
|
| 39 | ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
|
| 40 | ${HEADERS} Create Dictionary Content-Type=application/json allow_modify_feedback=True
|
| 41 | Create Session ${server_ip} http://${server_ip}:${server_port} auth=${AUTH} headers=${HEADERS}
|
| 42 |
|
| 43 | Teardown
|
| 44 | [Documentation] Delete all https sessions
|
| 45 | Delete All Sessions
|
| 46 |
|
| 47 | Validate Operation
|
| 48 | [Documentation] Tests and validates various backup/restore operations
|
| 49 | [Arguments] ${scenario} ${backup_state} ${restore_state}=${EMPTY} ${flavor_expected}=${EMPTY}
|
| 50 | ${backup_id}= Create BackupFile ${scenario}
|
| 51 | ${test_model_id}= Create Test Model
|
| 52 | ${backup_operation_id}= Perform Backup ${backup_id} ${backup_state}
|
| 53 | Run Keyword If '${restore_state}' != '${EMPTY}' Modify Test Model ${test_model_id}
|
| 54 | Run Keyword If '${restore_state}' != '${EMPTY}' Perform Restore ${backup_id} ${restore_state}
|
| 55 | Run Keyword If '${restore_state}' != '${EMPTY}' Verify Test Model ${test_model_id} ${flavor_expected}
|
| 56 |
|
| 57 | Create BackupFile
|
| 58 | [Documentation] Create a backupfile model
|
| 59 | [Arguments] ${operation}
|
| 60 | ${file_name}= Generate Random Value string
|
| 61 | ${file_uri}= Catenate SEPARATOR= file:///var/run/xos/backup/local/ ${operation} ${file_name}
|
| 62 | ${data}= Create Dictionary name=${file_name} uri=${file_uri}
|
| 63 | ${data}= Evaluate json.dumps(${data}) json
|
| 64 | ${resp}= CORD Post /xosapi/v1/core/backupfiles ${data}
|
| 65 | Should Be Equal As Strings ${resp.status_code} 200
|
| 66 | ${json_content}= To Json ${resp.content}
|
| 67 | ${id}= Get From Dictionary ${json_content} id
|
| 68 | [Return] ${id}
|
| 69 |
|
| 70 | Create Test Model
|
| 71 | [Documentation] Create model we can use to test restore
|
| 72 | ${name}= Generate Random Value string
|
| 73 | ${data}= Create Dictionary name=${name} flavor=${flavor_original} description=for_backup_testing
|
| 74 | ${data}= Evaluate json.dumps(${data}) json
|
| 75 | ${resp}= CORD Post /xosapi/v1/core/flavors ${data}
|
| 76 | Should Be Equal As Strings ${resp.status_code} 200
|
| 77 | ${json_content}= To Json ${resp.content}
|
| 78 | ${id}= Get From Dictionary ${json_content} id
|
| 79 | [Return] ${id}
|
| 80 |
|
| 81 | Perform Backup
|
| 82 | [Documentation] Perform backup
|
| 83 | [Arguments] ${backupfile_id} ${status}
|
| 84 | ${data}= Create Dictionary operation=create file_id=${backupfile_id}
|
| 85 | ${data}= Evaluate json.dumps(${data}) json
|
| 86 | ${resp}= CORD Post /xosapi/v1/core/backupoperations ${data}
|
| 87 | Should Be Equal As Strings ${resp.status_code} 200
|
| 88 | ${json_content}= To Json ${resp.content}
|
| 89 | ${id}= Get From Dictionary ${json_content} id
|
| 90 | Wait Until Keyword Succeeds ${timeout} 5s Validate Backup ${id} ${status}
|
| 91 |
|
| 92 | Modify Test Model
|
| 93 | [Documentation] Modify the test model
|
| 94 | [Arguments] ${testmodel_id}
|
| 95 | ${data}= Create Dictionary flavor=${flavor_updated}
|
| 96 | ${data}= Evaluate json.dumps(${data}) json
|
| 97 | ${resp}= CORD Put /xosapi/v1/core/flavors ${data} ${testmodel_id}
|
| 98 | Should Be Equal As Strings ${resp.status_code} 200
|
| 99 | ${jsondata}= To Json ${resp.content}
|
| 100 | Should Be Equal As Strings ${jsondata['flavor']} two
|
| 101 |
|
| 102 | Perform Restore
|
| 103 | [Documentation] Perform Restore
|
| 104 | [Arguments] ${id} ${restore_state}
|
| 105 | ${data}= Create Dictionary operation=restore file_id=${id}
|
| 106 | ${data}= Evaluate json.dumps(${data}) json
|
| 107 | ${resp}= CORD Post /xosapi/v1/core/backupoperations ${data}
|
| 108 | Should Be Equal As Strings ${resp.status_code} 200
|
| 109 | ${json_content}= To Json ${resp.content}
|
| 110 | ${backupop_id}= Get From Dictionary ${json_content} id
|
| 111 | Wait Until Keyword Succeeds ${timeout} 5s Validate Restore ${backupop_id} ${restore_state}
|
| 112 |
|
| 113 | Verify Test Model
|
| 114 | [Documentation] Verify Test Model has original contents
|
| 115 | [Arguments] ${testmodel_id} ${value}
|
| 116 | ${resp}= Cord Get /xosapi/v1/core/flavors/${testmodel_id}
|
| 117 | Should Be Equal As Strings ${resp.status_code} 200
|
| 118 | ${jsondata}= To Json ${resp.content}
|
| 119 | Should Be Equal As Strings ${jsondata['flavor']} ${value}
|
| 120 |
|
| 121 | Validate Backup
|
| 122 | [Documentation] Wait for a backupoperation to be in "created" state
|
| 123 | [Arguments] ${id} ${state}
|
| 124 | ${resp}= Get Request ${SERVER_IP} uri=/xosapi/v1/core/backupoperations/${id}
|
| 125 | Log ${resp.content}
|
| 126 | Should Be Equal As Strings ${resp.status_code} 200
|
| 127 | ${jsondata}= To Json ${resp.content}
|
| 128 | Should Be Equal As Strings ${jsondata['status']} ${state}
|
| 129 |
|
| 130 | Validate Restore
|
| 131 | [Documentation] Validate Backup operation status
|
| 132 | [Arguments] ${id} ${state}
|
| 133 | ${resp}= Get Request ${SERVER_IP} uri=/xosapi/v1/core/backupoperations/${id}
|
| 134 | Log ${resp.content}
|
| 135 | Should Be Equal As Strings ${resp.status_code} 200
|
| 136 | ${jsondata}= To Json ${resp.content}
|
| 137 | Should Be Equal As Strings ${jsondata['status']} ${state} |