blob: 99d3a08d43ac8350c426bd6aba44f5f153d8d8b7 [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
8Library OperatingSystem
9Library Collections
10
11
12
13*** Variables ***
Jerry Flood8a6b0b52017-11-12 15:44:21 -050014${INDEX PATH} /aai/v11
DR695Hccff30b2017-02-17 18:44:24 -050015${ROOT_TENANT_PATH} /cloud-infrastructure/cloud-regions/cloud-region/
16
17${SYSTEM USER} robot-ete
18${AAI_ADD_TENANT_BODY}= robot/assets/templates/aai/add_tenant_body.template
19
jf98603b22a2d2017-03-01 19:43:28 -050020*** Keywords ***
DR695Hccff30b2017-02-17 18:44:24 -050021Inventory Tenant If Not Exists
jf98603b22a2d2017-03-01 19:43:28 -050022 [Documentation] Creates a service in A&AI if it doesn't exist
DR695Hccff30b2017-02-17 18:44:24 -050023 [Arguments] ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone} ${tenant_id} ${tenant_name}
24 ${dict}= Get Tenants ${cloud_owner} ${cloud_region_id}
jf98603b22a2d2017-03-01 19:43:28 -050025 ${status} ${value}= Run Keyword And Ignore Error Dictionary Should Contain Key ${dict} ${tenant_id}
DR695Hccff30b2017-02-17 18:44:24 -050026 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 -050027
DR695Hccff30b2017-02-17 18:44:24 -050028Inventory Tenant
jf98603b22a2d2017-03-01 19:43:28 -050029 [Documentation] Inventorys a Tenant in A&AI
30 [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 -050031 ${json_resource_version}= Get Resource Version If Exists ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone}
DR695Hccff30b2017-02-17 18:44:24 -050032 ${data_template}= OperatingSystem.Get File ${AAI_ADD_TENANT_BODY}
jf98603b22a2d2017-03-01 19:43:28 -050033 ${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}
34 ${data}= Fill JSON Template ${data_template} ${arguments}
DR695Hccff30b2017-02-17 18:44:24 -050035 ${put_resp}= Run A&AI Put Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${data}
jf986075010a42017-02-22 16:52:54 -050036 ${status_string}= Convert To String ${put_resp.status_code}
jf98603b22a2d2017-03-01 19:43:28 -050037 Should Match Regexp ${status_string} ^(201|200)$
jf986075010a42017-02-22 16:52:54 -050038
39Get Resource Version If Exists
jf98603b22a2d2017-03-01 19:43:28 -050040 [Documentation] Creates a service in A&AI if it doesn't exist
jf986075010a42017-02-22 16:52:54 -050041 [Arguments] ${cloud_owner} ${cloud_region_id} ${cloud_type} ${owner_defined_type} ${cloud_region_version} ${cloud_zone}
42 ${resource_version}= Set Variable
43 ${resp}= Get Cloud Region ${cloud_owner} ${cloud_region_id}
44 Return from Keyword if '${resp.status_code}' != '200' ${resource_version}
45 ${json}= Set Variable ${resp.json()}
jf98603b22a2d2017-03-01 19:43:28 -050046 ${resource_version}= Catenate ${json['resource-version']}
47 [Return] "resource-version":"${resource_version}",
48
DR695Hccff30b2017-02-17 18:44:24 -050049
50Delete Tenant
jf98603b22a2d2017-03-01 19:43:28 -050051 [Documentation] Removes both Tenant
DR695Hccff30b2017-02-17 18:44:24 -050052 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
jf98603b22a2d2017-03-01 19:43:28 -050053 ${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 -050054 Run Keyword If '${get_resp.status_code}' == '200' Delete Tenant Exists ${tenant_id} ${cloud_owner} ${cloud_region_id} ${get_resp.json()['resource-version']}
55
56Delete Tenant Exists
57 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version}
jf98603b22a2d2017-03-01 19:43:28 -050058 ${put_resp}= Run A&AI Delete Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id} ${resource_version}
59 Should Be Equal As Strings ${put_resp.status_code} 204
60
DR695Hccff30b2017-02-17 18:44:24 -050061Delete Cloud Region
62 [Documentation] Removes both Tenant and Cloud Region in A&AI
63 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
jf98603b22a2d2017-03-01 19:43:28 -050064 ${get_resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
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}
70 ${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 -050071 ${status_string}= Convert To String ${put_resp.status_code}
72 Should Match Regexp ${status_string} ^(204|400)$
73
DR695Hccff30b2017-02-17 18:44:24 -050074Get Tenants
jf98603b22a2d2017-03-01 19:43:28 -050075 [Documentation] Return list of tenants for this cloud owner/region
76 [Arguments] ${cloud_owner} ${cloud_region_id}
DR695Hccff30b2017-02-17 18:44:24 -050077 ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants
jf98603b22a2d2017-03-01 19:43:28 -050078 ${dict}= Create Dictionary
DR695Hccff30b2017-02-17 18:44:24 -050079 ${status} ${value}= Run Keyword And Ignore Error Should Be Equal As Strings ${resp.status_code} 200
jf98603b22a2d2017-03-01 19:43:28 -050080 Run Keyword If '${status}' == 'PASS' Update Tenant Dictionary ${dict} ${resp.json()}
DR695Hccff30b2017-02-17 18:44:24 -050081 [Return] ${dict}
82
jf986075010a42017-02-22 16:52:54 -050083Get Cloud Region
jf98603b22a2d2017-03-01 19:43:28 -050084 [Documentation] Returns the Cloud Region if it exists
85 [Arguments] ${cloud_owner} ${cloud_region_id}
jf986075010a42017-02-22 16:52:54 -050086 ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
87 [Return] ${resp}
88
DR695Hccff30b2017-02-17 18:44:24 -050089Update Tenant Dictionary
90 [Arguments] ${dict} ${json}
91 ${list}= Evaluate ${json}['tenant']
DR695H910097e2019-05-08 13:55:32 -040092 :FOR ${map} IN @{list}
DR695Hccff30b2017-02-17 18:44:24 -050093 \ ${status} ${tenant_id}= Run Keyword And Ignore Error Get From Dictionary ${map} tenant-id
jf98603b22a2d2017-03-01 19:43:28 -050094 \ Run Keyword If '${status}' == 'PASS' Set To Dictionary ${dict} ${tenant_id}=${map}
DR695Hccff30b2017-02-17 18:44:24 -050095 Log ${dict}
DR695Hccff30b2017-02-17 18:44:24 -050096
jf98603b22a2d2017-03-01 19:43:28 -050097
98