blob: 1e9fa80242760b81773e24e5ceb83de783d72856 [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
DR695H3bb6cf42019-06-20 15:04:04 -04006Library ONAPLibrary.Templating
DR695Hccff30b2017-02-17 18:44:24 -05007
8
9*** Variables ***
Jerry Flood8a6b0b52017-11-12 15:44:21 -050010${INDEX PATH} /aai/v11
DR695Hccff30b2017-02-17 18:44:24 -050011${ROOT_TENANT_PATH} /cloud-infrastructure/cloud-regions/cloud-region/
12
DR695H3bb6cf42019-06-20 15:04:04 -040013${AAI_ADD_TENANT_BODY}= aai/add_tenant_body.jinja
DR695Hccff30b2017-02-17 18:44:24 -050014
jf98603b22a2d2017-03-01 19:43:28 -050015*** Keywords ***
DR695Hccff30b2017-02-17 18:44:24 -050016Inventory Tenant If Not Exists
jf98603b22a2d2017-03-01 19:43:28 -050017 [Documentation] Creates a service in A&AI if it doesn't exist
DR695Hccff30b2017-02-17 18:44:24 -050018 [Arguments] ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone} ${tenant_id} ${tenant_name}
19 ${dict}= Get Tenants ${cloud_owner} ${cloud_region_id}
jf98603b22a2d2017-03-01 19:43:28 -050020 ${status} ${value}= Run Keyword And Ignore Error Dictionary Should Contain Key ${dict} ${tenant_id}
DR695Hccff30b2017-02-17 18:44:24 -050021 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 -050022
DR695Hccff30b2017-02-17 18:44:24 -050023Inventory Tenant
jf98603b22a2d2017-03-01 19:43:28 -050024 [Documentation] Inventorys a Tenant in A&AI
25 [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 -050026 ${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 -050027 ${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}
DR695H3bb6cf42019-06-20 15:04:04 -040028 Create Environment aai ${GLOBAL_TEMPLATE_FOLDER}
29 ${data}= Apply Template aai ${AAI_ADD_TENANT_BODY} ${arguments}
DR695Hccff30b2017-02-17 18:44:24 -050030 ${put_resp}= Run A&AI Put Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${data}
jf986075010a42017-02-22 16:52:54 -050031 ${status_string}= Convert To String ${put_resp.status_code}
jf98603b22a2d2017-03-01 19:43:28 -050032 Should Match Regexp ${status_string} ^(201|200)$
jf986075010a42017-02-22 16:52:54 -050033
34Get Resource Version If Exists
jf98603b22a2d2017-03-01 19:43:28 -050035 [Documentation] Creates a service in A&AI if it doesn't exist
jf986075010a42017-02-22 16:52:54 -050036 [Arguments] ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone}
37 ${resource_version}= Set Variable
38 ${resp}= Get Cloud Region ${cloud_owner} ${cloud_region_id}
39 Return from Keyword if '${resp.status_code}' != '200' ${resource_version}
40 ${json}= Set Variable ${resp.json()}
jf98603b22a2d2017-03-01 19:43:28 -050041 ${resource_version}= Catenate ${json['resource-version']}
42 [Return] "resource-version":"${resource_version}",
43
DR695Hccff30b2017-02-17 18:44:24 -050044
45Delete Tenant
jf98603b22a2d2017-03-01 19:43:28 -050046 [Documentation] Removes both Tenant
DR695Hccff30b2017-02-17 18:44:24 -050047 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
jf98603b22a2d2017-03-01 19:43:28 -050048 ${get_resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id}
DR695Hccff30b2017-02-17 18:44:24 -050049 Run Keyword If '${get_resp.status_code}' == '200' Delete Tenant Exists ${tenant_id} ${cloud_owner} ${cloud_region_id} ${get_resp.json()['resource-version']}
50
51Delete Tenant Exists
52 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version}
jf98603b22a2d2017-03-01 19:43:28 -050053 ${put_resp}= Run A&AI Delete Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id} ${resource_version}
54 Should Be Equal As Strings ${put_resp.status_code} 204
55
DR695Hccff30b2017-02-17 18:44:24 -050056Delete Cloud Region
57 [Documentation] Removes both Tenant and Cloud Region in A&AI
58 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
jf98603b22a2d2017-03-01 19:43:28 -050059 ${get_resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
DR695Hccff30b2017-02-17 18:44:24 -050060 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 -050061
DR695Hccff30b2017-02-17 18:44:24 -050062Delete Cloud Region Exists
jf98603b22a2d2017-03-01 19:43:28 -050063 [Documentation] Delete may get status 400 (Bad Request) if the region is still referenced
DR695Hccff30b2017-02-17 18:44:24 -050064 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version}
65 ${put_resp}= Run A&AI Delete Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${resource_version}
jf98603b22a2d2017-03-01 19:43:28 -050066 ${status_string}= Convert To String ${put_resp.status_code}
67 Should Match Regexp ${status_string} ^(204|400)$
68
DR695Hccff30b2017-02-17 18:44:24 -050069Get Tenants
jf98603b22a2d2017-03-01 19:43:28 -050070 [Documentation] Return list of tenants for this cloud owner/region
71 [Arguments] ${cloud_owner} ${cloud_region_id}
DR695Hccff30b2017-02-17 18:44:24 -050072 ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants
jf98603b22a2d2017-03-01 19:43:28 -050073 ${dict}= Create Dictionary
DR695Hccff30b2017-02-17 18:44:24 -050074 ${status} ${value}= Run Keyword And Ignore Error Should Be Equal As Strings ${resp.status_code} 200
jf98603b22a2d2017-03-01 19:43:28 -050075 Run Keyword If '${status}' == 'PASS' Update Tenant Dictionary ${dict} ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -050076 [Return] ${dict}
77
jf986075010a42017-02-22 16:52:54 -050078Get Cloud Region
jf98603b22a2d2017-03-01 19:43:28 -050079 [Documentation] Returns the Cloud Region if it exists
80 [Arguments] ${cloud_owner} ${cloud_region_id}
jf986075010a42017-02-22 16:52:54 -050081 ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
82 [Return] ${resp}
83
DR695Hccff30b2017-02-17 18:44:24 -050084Update Tenant Dictionary
85 [Arguments] ${dict} ${json}
86 ${list}= Evaluate ${json}['tenant']
DR695H910097e2019-05-08 13:55:32 -040087 :FOR ${map} IN @{list}
DR695Hccff30b2017-02-17 18:44:24 -050088 \ ${status} ${tenant_id}= Run Keyword And Ignore Error Get From Dictionary ${map} tenant-id
jf98603b22a2d2017-03-01 19:43:28 -050089 \ Run Keyword If '${status}' == 'PASS' Set To Dictionary ${dict} ${tenant_id}=${map}
DR695Hccff30b2017-02-17 18:44:24 -050090 Log ${dict}
DR695Hccff30b2017-02-17 18:44:24 -050091
jf98603b22a2d2017-03-01 19:43:28 -050092
93