blob: 9a4ad68cae4a3db80544d4554d9259445a36b532 [file] [log] [blame]
DR695Hccff30b2017-02-17 18:44:24 -05001*** Settings ***
2Documentation Create A&AI Customer API.
DR695Hccff30b2017-02-17 18:44:24 -05003
DR695Hccff30b2017-02-17 18:44:24 -05004Resource aai_interface.robot
DR695Hccff30b2017-02-17 18:44:24 -05005Library Collections
DR695Hd9794652019-07-19 18:20:40 -04006Library ONAPLibrary.Templating WITH NAME Templating
7Library ONAPLibrary.AAI WITH NAME AAI
DR695Hccff30b2017-02-17 18:44:24 -05008
9
10*** Variables ***
Jerry Flood8a6b0b52017-11-12 15:44:21 -050011${INDEX PATH} /aai/v11
DR695Hccff30b2017-02-17 18:44:24 -050012${ROOT_TENANT_PATH} /cloud-infrastructure/cloud-regions/cloud-region/
13
DR695H3bb6cf42019-06-20 15:04:04 -040014${AAI_ADD_TENANT_BODY}= aai/add_tenant_body.jinja
DR695Hccff30b2017-02-17 18:44:24 -050015
jf98603b22a2d2017-03-01 19:43:28 -050016*** Keywords ***
DR695Hccff30b2017-02-17 18:44:24 -050017Inventory Tenant If Not Exists
jf98603b22a2d2017-03-01 19:43:28 -050018 [Documentation] Creates a service in A&AI if it doesn't exist
DR695Hccff30b2017-02-17 18:44:24 -050019 [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}
jf98603b22a2d2017-03-01 19:43:28 -050021 ${status} ${value}= Run Keyword And Ignore Error Dictionary Should Contain Key ${dict} ${tenant_id}
DR695Hccff30b2017-02-17 18:44:24 -050022 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}
jf98603b22a2d2017-03-01 19:43:28 -050023
DR695Hccff30b2017-02-17 18:44:24 -050024Inventory Tenant
jf98603b22a2d2017-03-01 19:43:28 -050025 [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}
jf986075010a42017-02-22 16:52:54 -050027 ${json_resource_version}= Get Resource Version If Exists ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone}
jf98603b22a2d2017-03-01 19:43:28 -050028 ${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}
DR695Hd9794652019-07-19 18:20:40 -040029 Templating.Create Environment aai ${GLOBAL_TEMPLATE_FOLDER}
30 ${data}= Templating.Apply Template aai ${AAI_ADD_TENANT_BODY} ${arguments}
DR695Hc6184272019-07-26 15:50:23 -040031 ${put_resp}= AAI.Run Put Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${data} auth=${GLOBAL_AAI_AUTHENTICATION}
jf986075010a42017-02-22 16:52:54 -050032 ${status_string}= Convert To String ${put_resp.status_code}
jf98603b22a2d2017-03-01 19:43:28 -050033 Should Match Regexp ${status_string} ^(201|200)$
jf986075010a42017-02-22 16:52:54 -050034
35Get Resource Version If Exists
jf98603b22a2d2017-03-01 19:43:28 -050036 [Documentation] Creates a service in A&AI if it doesn't exist
jf986075010a42017-02-22 16:52:54 -050037 [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()}
jf98603b22a2d2017-03-01 19:43:28 -050042 ${resource_version}= Catenate ${json['resource-version']}
43 [Return] "resource-version":"${resource_version}",
44
DR695Hccff30b2017-02-17 18:44:24 -050045
46Delete Tenant
jf98603b22a2d2017-03-01 19:43:28 -050047 [Documentation] Removes both Tenant
DR695Hccff30b2017-02-17 18:44:24 -050048 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
DR695Hc6184272019-07-26 15:50:23 -040049 ${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}
DR695Hccff30b2017-02-17 18:44:24 -050050 Run Keyword If '${get_resp.status_code}' == '200' Delete Tenant Exists ${tenant_id} ${cloud_owner} ${cloud_region_id} ${get_resp.json()['resource-version']}
51
52Delete Tenant Exists
53 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version}
DR695Hc6184272019-07-26 15:50:23 -040054 ${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}
jf98603b22a2d2017-03-01 19:43:28 -050055 Should Be Equal As Strings ${put_resp.status_code} 204
56
DR695Hccff30b2017-02-17 18:44:24 -050057Delete Cloud Region
58 [Documentation] Removes both Tenant and Cloud Region in A&AI
59 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
DR695Hc6184272019-07-26 15:50:23 -040060 ${get_resp}= AAI.Run Get Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} auth=${GLOBAL_AAI_AUTHENTICATION}
DR695Hccff30b2017-02-17 18:44:24 -050061 Run Keyword If '${get_resp.status_code}' == '200' Delete Cloud Region Exists ${tenant_id} ${cloud_owner} ${cloud_region_id} ${get_resp.json()['resource-version']}
jf98603b22a2d2017-03-01 19:43:28 -050062
DR695Hccff30b2017-02-17 18:44:24 -050063Delete Cloud Region Exists
jf98603b22a2d2017-03-01 19:43:28 -050064 [Documentation] Delete may get status 400 (Bad Request) if the region is still referenced
DR695Hccff30b2017-02-17 18:44:24 -050065 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version}
DR695Hc6184272019-07-26 15:50:23 -040066 ${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}
jf98603b22a2d2017-03-01 19:43:28 -050067 ${status_string}= Convert To String ${put_resp.status_code}
68 Should Match Regexp ${status_string} ^(204|400)$
69
DR695Hccff30b2017-02-17 18:44:24 -050070Get Tenants
jf98603b22a2d2017-03-01 19:43:28 -050071 [Documentation] Return list of tenants for this cloud owner/region
72 [Arguments] ${cloud_owner} ${cloud_region_id}
DR695Hc6184272019-07-26 15:50:23 -040073 ${resp}= AAI.Run Get Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants auth=${GLOBAL_AAI_AUTHENTICATION}
jf98603b22a2d2017-03-01 19:43:28 -050074 ${dict}= Create Dictionary
DR695Hccff30b2017-02-17 18:44:24 -050075 ${status} ${value}= Run Keyword And Ignore Error Should Be Equal As Strings ${resp.status_code} 200
jf98603b22a2d2017-03-01 19:43:28 -050076 Run Keyword If '${status}' == 'PASS' Update Tenant Dictionary ${dict} ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -050077 [Return] ${dict}
78
jf986075010a42017-02-22 16:52:54 -050079Get Cloud Region
jf98603b22a2d2017-03-01 19:43:28 -050080 [Documentation] Returns the Cloud Region if it exists
81 [Arguments] ${cloud_owner} ${cloud_region_id}
DR695Hc6184272019-07-26 15:50:23 -040082 ${resp}= AAI.Run Get Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} auth=${GLOBAL_AAI_AUTHENTICATION}
jf986075010a42017-02-22 16:52:54 -050083 [Return] ${resp}
84
DR695Hccff30b2017-02-17 18:44:24 -050085Update Tenant Dictionary
86 [Arguments] ${dict} ${json}
DR695Hd9794652019-07-19 18:20:40 -040087 @{list}= Copy List ${json['tenant']}
DR695H910097e2019-05-08 13:55:32 -040088 :FOR ${map} IN @{list}
DR695Hccff30b2017-02-17 18:44:24 -050089 \ ${status} ${tenant_id}= Run Keyword And Ignore Error Get From Dictionary ${map} tenant-id
jf98603b22a2d2017-03-01 19:43:28 -050090 \ Run Keyword If '${status}' == 'PASS' Set To Dictionary ${dict} ${tenant_id}=${map}
DR695Hccff30b2017-02-17 18:44:24 -050091 Log ${dict}
DR695Hccff30b2017-02-17 18:44:24 -050092
jf98603b22a2d2017-03-01 19:43:28 -050093
94