blob: 24cb4d4df33862e357c9797062289239d281e707 [file] [log] [blame]
DR695Hccff30b2017-02-17 18:44:24 -05001*** Settings ***
2Documentation Create A&AI Customer API.
3...
4... Create A&AI Customer API
5
6Resource ../json_templater.robot
7Resource aai_interface.robot
DR695Hccff30b2017-02-17 18:44:24 -05008Library Collections
9
10
11
12*** Variables ***
Jerry Flood8a6b0b52017-11-12 15:44:21 -050013${INDEX PATH} /aai/v11
DR695Hccff30b2017-02-17 18:44:24 -050014${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
jf98603b22a2d2017-03-01 19:43:28 -050019*** Keywords ***
DR695Hccff30b2017-02-17 18:44:24 -050020Inventory Tenant If Not Exists
jf98603b22a2d2017-03-01 19:43:28 -050021 [Documentation] Creates a service in A&AI if it doesn't exist
DR695Hccff30b2017-02-17 18:44:24 -050022 [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}
jf98603b22a2d2017-03-01 19:43:28 -050024 ${status} ${value}= Run Keyword And Ignore Error Dictionary Should Contain Key ${dict} ${tenant_id}
DR695Hccff30b2017-02-17 18:44:24 -050025 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 -050026
DR695Hccff30b2017-02-17 18:44:24 -050027Inventory Tenant
jf98603b22a2d2017-03-01 19:43:28 -050028 [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}
jf986075010a42017-02-22 16:52:54 -050030 ${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 -050031 ${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}
DR695Hdaec16c2019-06-19 17:40:26 -040032 ${data}= Fill JSON Template File ${AAI_ADD_TENANT_BODY} ${arguments}
DR695Hccff30b2017-02-17 18:44:24 -050033 ${put_resp}= Run A&AI Put Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${data}
jf986075010a42017-02-22 16:52:54 -050034 ${status_string}= Convert To String ${put_resp.status_code}
jf98603b22a2d2017-03-01 19:43:28 -050035 Should Match Regexp ${status_string} ^(201|200)$
jf986075010a42017-02-22 16:52:54 -050036
37Get Resource Version If Exists
jf98603b22a2d2017-03-01 19:43:28 -050038 [Documentation] Creates a service in A&AI if it doesn't exist
jf986075010a42017-02-22 16:52:54 -050039 [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()}
jf98603b22a2d2017-03-01 19:43:28 -050044 ${resource_version}= Catenate ${json['resource-version']}
45 [Return] "resource-version":"${resource_version}",
46
DR695Hccff30b2017-02-17 18:44:24 -050047
48Delete Tenant
jf98603b22a2d2017-03-01 19:43:28 -050049 [Documentation] Removes both Tenant
DR695Hccff30b2017-02-17 18:44:24 -050050 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
jf98603b22a2d2017-03-01 19:43:28 -050051 ${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 -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}
jf98603b22a2d2017-03-01 19:43:28 -050056 ${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
DR695Hccff30b2017-02-17 18:44:24 -050059Delete Cloud Region
60 [Documentation] Removes both Tenant and Cloud Region in A&AI
61 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
jf98603b22a2d2017-03-01 19:43:28 -050062 ${get_resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
DR695Hccff30b2017-02-17 18:44:24 -050063 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 -050064
DR695Hccff30b2017-02-17 18:44:24 -050065Delete Cloud Region Exists
jf98603b22a2d2017-03-01 19:43:28 -050066 [Documentation] Delete may get status 400 (Bad Request) if the region is still referenced
DR695Hccff30b2017-02-17 18:44:24 -050067 [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}
jf98603b22a2d2017-03-01 19:43:28 -050069 ${status_string}= Convert To String ${put_resp.status_code}
70 Should Match Regexp ${status_string} ^(204|400)$
71
DR695Hccff30b2017-02-17 18:44:24 -050072Get Tenants
jf98603b22a2d2017-03-01 19:43:28 -050073 [Documentation] Return list of tenants for this cloud owner/region
74 [Arguments] ${cloud_owner} ${cloud_region_id}
DR695Hccff30b2017-02-17 18:44:24 -050075 ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants
jf98603b22a2d2017-03-01 19:43:28 -050076 ${dict}= Create Dictionary
DR695Hccff30b2017-02-17 18:44:24 -050077 ${status} ${value}= Run Keyword And Ignore Error Should Be Equal As Strings ${resp.status_code} 200
jf98603b22a2d2017-03-01 19:43:28 -050078 Run Keyword If '${status}' == 'PASS' Update Tenant Dictionary ${dict} ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -050079 [Return] ${dict}
80
jf986075010a42017-02-22 16:52:54 -050081Get Cloud Region
jf98603b22a2d2017-03-01 19:43:28 -050082 [Documentation] Returns the Cloud Region if it exists
83 [Arguments] ${cloud_owner} ${cloud_region_id}
jf986075010a42017-02-22 16:52:54 -050084 ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
85 [Return] ${resp}
86
DR695Hccff30b2017-02-17 18:44:24 -050087Update Tenant Dictionary
88 [Arguments] ${dict} ${json}
89 ${list}= Evaluate ${json}['tenant']
DR695H910097e2019-05-08 13:55:32 -040090 :FOR ${map} IN @{list}
DR695Hccff30b2017-02-17 18:44:24 -050091 \ ${status} ${tenant_id}= Run Keyword And Ignore Error Get From Dictionary ${map} tenant-id
jf98603b22a2d2017-03-01 19:43:28 -050092 \ Run Keyword If '${status}' == 'PASS' Set To Dictionary ${dict} ${tenant_id}=${map}
DR695Hccff30b2017-02-17 18:44:24 -050093 Log ${dict}
DR695Hccff30b2017-02-17 18:44:24 -050094
jf98603b22a2d2017-03-01 19:43:28 -050095
96