Marco Platania | 9d992ae | 2019-01-23 17:20:05 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Create availability zone in A&AI. |
| 3 | |
| 4 | Resource ../json_templater.robot |
| 5 | Resource aai_interface.robot |
| 6 | Library OperatingSystem |
| 7 | Library Collections |
| 8 | |
| 9 | |
| 10 | *** Variables *** |
| 11 | ${INDEX_PATH} /aai/v14 |
| 12 | ${ROOT_PATH} /cloud-infrastructure/cloud-regions/cloud-region |
| 13 | ${ZONE_PATH} /availability-zones/availability-zone |
| 14 | |
| 15 | ${SYSTEM USER} robot-ete |
| 16 | ${AAI_ADD_AVAILABILITY_ZONE_BODY}= robot/assets/templates/aai/add_availability_zone_body.template |
| 17 | |
| 18 | *** Keywords *** |
| 19 | Create Availability Zone If Not Exists |
| 20 | [Documentation] Creates availability zone in A&AI if it doesn't exist |
| 21 | [Arguments] ${cloud-owner} ${cloud-region-id} ${availability_zone_name}=${GLOBAL_AAI_AVAILABILITY_ZONE_NAME} |
| 22 | ${get_resp}= Run A&AI Get Request ${INDEX_PATH}${ROOT_PATH}/${cloud-owner}/${cloud-region-id}${ZONE_PATH}/${availability_zone_name} |
| 23 | Return From Keyword If '${get_resp.status_code}' == '200' |
| 24 | Create Availability Zone ${availability_zone_name} ${cloud-owner} ${cloud-region-id} |
| 25 | |
| 26 | Create Availability Zone |
| 27 | [Documentation] Creates availability zone in A&AI |
| 28 | [Arguments] ${availability_zone_name} ${cloud-owner} ${cloud-region-id} |
| 29 | ${arguments}= Create Dictionary availability_zone_name=${availability_zone_name} |
| 30 | ${data}= Fill JSON Template File ${AAI_ADD_AVAILABILITY_ZONE_BODY} ${arguments} |
| 31 | ${put_resp}= Run A&AI Put Request ${INDEX_PATH}${ROOT_PATH}/${cloud-owner}/${cloud-region-id}${ZONE_PATH}/${availability_zone_name} ${data} |
| 32 | ${status_string}= Convert To String ${put_resp.status_code} |
| 33 | Should Match Regexp ${status_string} ^(201|200)$ |
| 34 | |
| 35 | Delete Availability Zone If Exists |
| 36 | [Documentation] Removes availability zone |
| 37 | [Arguments] ${cloud-owner} ${cloud-region-id} ${availability_zone_name}=${GLOBAL_AAI_AVAILABILITY_ZONE_NAME} |
| 38 | ${get_resp}= Run A&AI Get Request ${INDEX_PATH}${ROOT_PATH}/${cloud-owner}/${cloud-region-id}${ZONE_PATH}/${availability_zone_name} |
| 39 | Run Keyword If '${get_resp.status_code}' == '200' Delete Availability Zone ${availability_zone_name} ${cloud-owner} ${cloud-region-id} ${get_resp.json()} |
| 40 | |
| 41 | Delete Availability Zone |
| 42 | [Arguments] ${availability_zone_name} ${cloud-owner} ${cloud-region-id} ${json} |
| 43 | ${resource_version}= Catenate ${json['resource-version']} |
| 44 | ${put_resp}= Run A&AI Delete Request ${INDEX_PATH}${ROOT_PATH}/${cloud-owner}/${cloud-region-id}${ZONE_PATH}/${availability_zone_name} ${resource_version} |
| 45 | Should Be Equal As Strings ${put_resp.status_code} 204 |
| 46 | |
| 47 | Get Availability Zone |
| 48 | [Documentation] Return availability zone |
| 49 | [Arguments] ${availability_zone_name} ${cloud-owner} ${cloud-region-id} |
| 50 | ${resp}= Run A&AI Get Request ${INDEX_PATH}${ROOT_PATH}/${cloud-owner}/${cloud-region-id}${ZONE_PATH}/${availability_zone_name} |
| 51 | Should Be Equal As Strings ${resp.status_code} 200 |
| 52 | [Return] ${resp.json()} |