Initial checkin of EopenECOMP testsuite
[testsuite.git] / robot / resources / aai / create_tenant.robot
1 *** Settings ***
2 Documentation     Create A&AI Customer API.
3 ...
4 ...                   Create A&AI Customer API
5
6 Resource    ../json_templater.robot
7 Resource    aai_interface.robot
8 Library    OperatingSystem
9 Library    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 ***    
21 Inventory 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         
28 Inventory 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}       
31     ${data_template}=    OperatingSystem.Get File    ${AAI_ADD_TENANT_BODY}
32     ${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}       
33     ${data}=    Fill JSON Template    ${data_template}    ${arguments}        
34         ${put_resp}=    Run A&AI Put Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}     ${data}
35     Should Be Equal As Strings  ${put_resp.status_code}         201   
36         [Return]  ${put_resp.status_code}
37
38 Delete Tenant
39     [Documentation]    Removes both Tenant 
40     [Arguments]    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}
41     ${get_resp}=    Run A&AI Get Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id}      
42     Run Keyword If    '${get_resp.status_code}' == '200'    Delete Tenant Exists    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}    ${get_resp.json()['resource-version']}
43
44 Delete Tenant Exists
45     [Arguments]    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}    ${resource_version}
46     ${put_resp}=    Run A&AI Delete Request    ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id}    ${resource_version} 
47     Should Be Equal As Strings  ${put_resp.status_code}         204   
48   
49 Delete Cloud Region
50     [Documentation]    Removes both Tenant and Cloud Region in A&AI
51     [Arguments]    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}
52     ${get_resp}=    Run A&AI Get Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}    
53         Run Keyword If    '${get_resp.status_code}' == '200'    Delete Cloud Region Exists   ${tenant_id}    ${cloud_owner}    ${cloud_region_id}    ${get_resp.json()['resource-version']}
54         
55 Delete Cloud Region Exists
56     [Arguments]    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}    ${resource_version}
57     ${put_resp}=    Run A&AI Delete Request    ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}   ${resource_version}
58     Should Be Equal As Strings  ${put_resp.status_code}         204     
59     
60 Get Tenants
61     [Documentation]   Return list of tenants for this cloud owner/region    
62     [Arguments]    ${cloud_owner}    ${cloud_region_id} 
63         ${resp}=    Run A&AI Get Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants
64         ${dict}=    Create Dictionary    
65     ${status}    ${value}=    Run Keyword And Ignore Error    Should Be Equal As Strings        ${resp.status_code}     200
66     Run Keyword If    '${status}' == 'PASS'    Update Tenant Dictionary    ${dict}    ${resp.json()}      
67         [Return]  ${dict}
68
69 Update Tenant Dictionary
70     [Arguments]    ${dict}    ${json}
71     ${list}=    Evaluate    ${json}['tenant']
72     :for   ${map}    in    @{list}
73     \    ${status}    ${tenant_id}=     Run Keyword And Ignore Error    Get From Dictionary    ${map}    tenant-id
74     \    Run Keyword If    '${status}' == 'PASS'    Set To Dictionary    ${dict}    ${tenant_id}=${map}    
75     Log    ${dict}
76     
77     
78
79