DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Create A&AI Customer API. |
| 3 | ... |
| 4 | ... Create A&AI Customer API |
| 5 | |
| 6 | Resource ../json_templater.robot |
| 7 | Resource aai_interface.robot |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 8 | Library Collections |
| 9 | |
| 10 | |
| 11 | |
| 12 | *** Variables *** |
Jerry Flood | 8a6b0b5 | 2017-11-12 15:44:21 -0500 | [diff] [blame] | 13 | ${INDEX PATH} /aai/v11 |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 14 | ${ROOT_TENANT_PATH} /cloud-infrastructure/cloud-regions/cloud-region/ |
| 15 | |
| 16 | ${SYSTEM USER} robot-ete |
| 17 | ${AAI_ADD_TENANT_BODY}= robot/assets/templates/aai/add_tenant_body.template |
| 18 | |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 19 | *** Keywords *** |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 20 | Inventory Tenant If Not Exists |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 21 | [Documentation] Creates a service in A&AI if it doesn't exist |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 22 | [Arguments] ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone} ${tenant_id} ${tenant_name} |
| 23 | ${dict}= Get Tenants ${cloud_owner} ${cloud_region_id} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 24 | ${status} ${value}= Run Keyword And Ignore Error Dictionary Should Contain Key ${dict} ${tenant_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 25 | Run Keyword If '${status}' == 'FAIL' Inventory Tenant ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone} ${tenant_id} ${tenant_name} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 26 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 27 | Inventory Tenant |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 28 | [Documentation] Inventorys a Tenant in A&AI |
| 29 | [Arguments] ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone} ${tenant_id} ${tenant_name} |
jf9860 | 75010a4 | 2017-02-22 16:52:54 -0500 | [diff] [blame] | 30 | ${json_resource_version}= Get Resource Version If Exists ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 31 | ${arguments}= Create Dictionary cloud_owner=${cloud_owner} cloud_region_id=${cloud_region_id} cloud_type=${cloud_type} owner_defined_type=${owner_defined_type} cloud_region_version=${cloud_region_version} cloud_zone=${cloud_zone} tenant_id=${tenant_id} tenant_name=${tenant_name} resource_version=${json_resource_version} |
DR695H | daec16c | 2019-06-19 17:40:26 -0400 | [diff] [blame^] | 32 | ${data}= Fill JSON Template File ${AAI_ADD_TENANT_BODY} ${arguments} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 33 | ${put_resp}= Run A&AI Put Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${data} |
jf9860 | 75010a4 | 2017-02-22 16:52:54 -0500 | [diff] [blame] | 34 | ${status_string}= Convert To String ${put_resp.status_code} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 35 | Should Match Regexp ${status_string} ^(201|200)$ |
jf9860 | 75010a4 | 2017-02-22 16:52:54 -0500 | [diff] [blame] | 36 | |
| 37 | Get Resource Version If Exists |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 38 | [Documentation] Creates a service in A&AI if it doesn't exist |
jf9860 | 75010a4 | 2017-02-22 16:52:54 -0500 | [diff] [blame] | 39 | [Arguments] ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone} |
| 40 | ${resource_version}= Set Variable |
| 41 | ${resp}= Get Cloud Region ${cloud_owner} ${cloud_region_id} |
| 42 | Return from Keyword if '${resp.status_code}' != '200' ${resource_version} |
| 43 | ${json}= Set Variable ${resp.json()} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 44 | ${resource_version}= Catenate ${json['resource-version']} |
| 45 | [Return] "resource-version":"${resource_version}", |
| 46 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 47 | |
| 48 | Delete Tenant |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 49 | [Documentation] Removes both Tenant |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 50 | [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 51 | ${get_resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 52 | Run Keyword If '${get_resp.status_code}' == '200' Delete Tenant Exists ${tenant_id} ${cloud_owner} ${cloud_region_id} ${get_resp.json()['resource-version']} |
| 53 | |
| 54 | Delete Tenant Exists |
| 55 | [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 56 | ${put_resp}= Run A&AI Delete Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id} ${resource_version} |
| 57 | Should Be Equal As Strings ${put_resp.status_code} 204 |
| 58 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 59 | Delete Cloud Region |
| 60 | [Documentation] Removes both Tenant and Cloud Region in A&AI |
| 61 | [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 62 | ${get_resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 63 | Run Keyword If '${get_resp.status_code}' == '200' Delete Cloud Region Exists ${tenant_id} ${cloud_owner} ${cloud_region_id} ${get_resp.json()['resource-version']} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 64 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 65 | Delete Cloud Region Exists |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 66 | [Documentation] Delete may get status 400 (Bad Request) if the region is still referenced |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 67 | [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version} |
| 68 | ${put_resp}= Run A&AI Delete Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${resource_version} |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 69 | ${status_string}= Convert To String ${put_resp.status_code} |
| 70 | Should Match Regexp ${status_string} ^(204|400)$ |
| 71 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 72 | Get Tenants |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 73 | [Documentation] Return list of tenants for this cloud owner/region |
| 74 | [Arguments] ${cloud_owner} ${cloud_region_id} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 75 | ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 76 | ${dict}= Create Dictionary |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 77 | ${status} ${value}= Run Keyword And Ignore Error Should Be Equal As Strings ${resp.status_code} 200 |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 78 | Run Keyword If '${status}' == 'PASS' Update Tenant Dictionary ${dict} ${resp.json()} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 79 | [Return] ${dict} |
| 80 | |
jf9860 | 75010a4 | 2017-02-22 16:52:54 -0500 | [diff] [blame] | 81 | Get Cloud Region |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 82 | [Documentation] Returns the Cloud Region if it exists |
| 83 | [Arguments] ${cloud_owner} ${cloud_region_id} |
jf9860 | 75010a4 | 2017-02-22 16:52:54 -0500 | [diff] [blame] | 84 | ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} |
| 85 | [Return] ${resp} |
| 86 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 87 | Update Tenant Dictionary |
| 88 | [Arguments] ${dict} ${json} |
| 89 | ${list}= Evaluate ${json}['tenant'] |
DR695H | 910097e | 2019-05-08 13:55:32 -0400 | [diff] [blame] | 90 | :FOR ${map} IN @{list} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 91 | \ ${status} ${tenant_id}= Run Keyword And Ignore Error Get From Dictionary ${map} tenant-id |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 92 | \ Run Keyword If '${status}' == 'PASS' Set To Dictionary ${dict} ${tenant_id}=${map} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 93 | Log ${dict} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 94 | |
jf9860 | 3b22a2d | 2017-03-01 19:43:28 -0500 | [diff] [blame] | 95 | |
| 96 | |