blob: e5a559667a79f8154e76d4c32d4b734afc449f74 [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 ***
14${INDEX PATH} /aai/v8
15${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
20*** Keywords ***
21Inventory Tenant If Not Exists
22 [Documentation] Creates a service in A&AI if it doesn't exist
23 [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}
25 ${status} ${value}= Run Keyword And Ignore Error Dictionary Should Contain Key ${dict} ${tenant_id}
26 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}
27
28Inventory Tenant
29 [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}
jf986075010a42017-02-22 16:52:54 -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}
DR695Hccff30b2017-02-17 18:44:24 -050034 ${data}= Fill JSON Template ${data_template} ${arguments}
35 ${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}
37 Should Match Regexp ${status_string} ^(201|200)$
38
39Get Resource Version If Exists
40 [Documentation] Creates a service in A&AI if it doesn't exist
41 [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()}
46 ${resource_version}= Catenate ${json['resource-version']}
47 [Return] "resource-version":"${resource_version}",
48
DR695Hccff30b2017-02-17 18:44:24 -050049
50Delete Tenant
51 [Documentation] Removes both Tenant
52 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
53 ${get_resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id}
54 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}
58 ${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
61Delete Cloud Region
62 [Documentation] Removes both Tenant and Cloud Region in A&AI
63 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id}
64 ${get_resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
65 Run Keyword If '${get_resp.status_code}' == '200' Delete Cloud Region Exists ${tenant_id} ${cloud_owner} ${cloud_region_id} ${get_resp.json()['resource-version']}
66
67Delete Cloud Region Exists
68 [Arguments] ${tenant_id} ${cloud_owner} ${cloud_region_id} ${resource_version}
69 ${put_resp}= Run A&AI Delete Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id} ${resource_version}
70 Should Be Equal As Strings ${put_resp.status_code} 204
71
72Get Tenants
73 [Documentation] Return list of tenants for this cloud owner/region
74 [Arguments] ${cloud_owner} ${cloud_region_id}
75 ${resp}= Run A&AI Get Request ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants
76 ${dict}= Create Dictionary
77 ${status} ${value}= Run Keyword And Ignore Error Should Be Equal As Strings ${resp.status_code} 200
78 Run Keyword If '${status}' == 'PASS' Update Tenant Dictionary ${dict} ${resp.json()}
79 [Return] ${dict}
80
jf986075010a42017-02-22 16:52:54 -050081Get Cloud Region
82 [Documentation] Returns the Cloud Region if it exists
83 [Arguments] ${cloud_owner} ${cloud_region_id}
84 ${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']
90 :for ${map} in @{list}
91 \ ${status} ${tenant_id}= Run Keyword And Ignore Error Get From Dictionary ${map} tenant-id
92 \ Run Keyword If '${status}' == 'PASS' Set To Dictionary ${dict} ${tenant_id}=${map}
93 Log ${dict}
94
95
96
97