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