blob: 08e70ce74227da370fb06d237ef083de182c7ed8 [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}
31 ${auth}= Create List ${GLOBAL_AAI_USERNAME} ${GLOBAL_AAI_PASSWORD}
32 ${put_resp}= AAI.Run Put Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${data} auth=${auth}
jf986075010a42017-02-22 16:52:54 -050033 ${status_string}= Convert To String ${put_resp.status_code}
jf98603b22a2d2017-03-01 19:43:28 -050034 Should Match Regexp ${status_string} ^(201|200)$
jf986075010a42017-02-22 16:52:54 -050035
36Get Resource Version If Exists
jf98603b22a2d2017-03-01 19:43:28 -050037 [Documentation] Creates a service in A&AI if it doesn't exist
jf986075010a42017-02-22 16:52:54 -050038 [Arguments] ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone}
39 ${resource_version}= Set Variable
40 ${resp}= Get Cloud Region ${cloud_owner} ${cloud_region_id}
41 Return from Keyword if '${resp.status_code}' != '200' ${resource_version}
42 ${json}= Set Variable ${resp.json()}
jf98603b22a2d2017-03-01 19:43:28 -050043 ${resource_version}= Catenate ${json['resource-version']}
44 [Return] "resource-version":"${resource_version}",
45
DR695Hccff30b2017-02-17 18:44:24 -050046
47Delete Tenant
jf98603b22a2d2017-03-01 19:43:28 -050048 [Documentation] Removes both Tenant
DR695Hccff30b2017-02-17 18:44:24 -050049 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
DR695Hd9794652019-07-19 18:20:40 -040050 ${auth}= Create List ${GLOBAL_AAI_USERNAME} ${GLOBAL_AAI_PASSWORD}
51 ${get_resp}= AAI.Run Get Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id} auth=${auth}
DR695Hccff30b2017-02-17 18:44:24 -050052 Run Keyword If '${get_resp.status_code}' == '200' Delete Tenant Exists ${tenant_id} ${cloud_owner} ${cloud_region_id} ${get_resp.json()['resource-version']}
53
54Delete Tenant Exists
55 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version}
DR695Hd9794652019-07-19 18:20:40 -040056 ${auth}= Create List ${GLOBAL_AAI_USERNAME} ${GLOBAL_AAI_PASSWORD}
57 ${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=${auth}
jf98603b22a2d2017-03-01 19:43:28 -050058 Should Be Equal As Strings ${put_resp.status_code} 204
59
DR695Hccff30b2017-02-17 18:44:24 -050060Delete Cloud Region
61 [Documentation] Removes both Tenant and Cloud Region in A&AI
62 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
DR695Hd9794652019-07-19 18:20:40 -040063 ${auth}= Create List ${GLOBAL_AAI_USERNAME} ${GLOBAL_AAI_PASSWORD}
64 ${get_resp}= AAI.Run Get Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} auth=${auth}
DR695Hccff30b2017-02-17 18:44:24 -050065 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 -050066
DR695Hccff30b2017-02-17 18:44:24 -050067Delete Cloud Region Exists
jf98603b22a2d2017-03-01 19:43:28 -050068 [Documentation] Delete may get status 400 (Bad Request) if the region is still referenced
DR695Hccff30b2017-02-17 18:44:24 -050069 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version}
DR695Hd9794652019-07-19 18:20:40 -040070 ${auth}= Create List ${GLOBAL_AAI_USERNAME} ${GLOBAL_AAI_PASSWORD}
71 ${put_resp}= AAI.Run Delete Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${resource_version} auth=${auth}
jf98603b22a2d2017-03-01 19:43:28 -050072 ${status_string}= Convert To String ${put_resp.status_code}
73 Should Match Regexp ${status_string} ^(204|400)$
74
DR695Hccff30b2017-02-17 18:44:24 -050075Get Tenants
jf98603b22a2d2017-03-01 19:43:28 -050076 [Documentation] Return list of tenants for this cloud owner/region
77 [Arguments] ${cloud_owner} ${cloud_region_id}
DR695Hd9794652019-07-19 18:20:40 -040078 ${auth}= Create List ${GLOBAL_AAI_USERNAME} ${GLOBAL_AAI_PASSWORD}
79 ${resp}= AAI.Run Get Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants auth=${auth}
jf98603b22a2d2017-03-01 19:43:28 -050080 ${dict}= Create Dictionary
DR695Hccff30b2017-02-17 18:44:24 -050081 ${status} ${value}= Run Keyword And Ignore Error Should Be Equal As Strings ${resp.status_code} 200
jf98603b22a2d2017-03-01 19:43:28 -050082 Run Keyword If '${status}' == 'PASS' Update Tenant Dictionary ${dict} ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -050083 [Return] ${dict}
84
jf986075010a42017-02-22 16:52:54 -050085Get Cloud Region
jf98603b22a2d2017-03-01 19:43:28 -050086 [Documentation] Returns the Cloud Region if it exists
87 [Arguments] ${cloud_owner} ${cloud_region_id}
DR695Hd9794652019-07-19 18:20:40 -040088 ${auth}= Create List ${GLOBAL_AAI_USERNAME} ${GLOBAL_AAI_PASSWORD}
89 ${resp}= AAI.Run Get Request ${AAI_FRONTEND_ENDPOINT} ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} auth=${auth}
jf986075010a42017-02-22 16:52:54 -050090 [Return] ${resp}
91
DR695Hccff30b2017-02-17 18:44:24 -050092Update Tenant Dictionary
93 [Arguments] ${dict} ${json}
DR695Hd9794652019-07-19 18:20:40 -040094 @{list}= Copy List ${json['tenant']}
DR695H910097e2019-05-08 13:55:32 -040095 :FOR ${map} IN @{list}
DR695Hccff30b2017-02-17 18:44:24 -050096 \ ${status} ${tenant_id}= Run Keyword And Ignore Error Get From Dictionary ${map} tenant-id
jf98603b22a2d2017-03-01 19:43:28 -050097 \ Run Keyword If '${status}' == 'PASS' Set To Dictionary ${dict} ${tenant_id}=${map}
DR695Hccff30b2017-02-17 18:44:24 -050098 Log ${dict}
DR695Hccff30b2017-02-17 18:44:24 -050099
jf98603b22a2d2017-03-01 19:43:28 -0500100
101