move rest of stirngtemplating off old format
[testsuite.git] / robot / resources / aai / create_tenant.robot
1 *** Settings ***
2 Documentation     Create A&AI Customer API.
3
4 Resource    aai_interface.robot
5 Library    Collections
6 Library    ONAPLibrary.Templating
7
8
9 *** Variables ***
10 ${INDEX PATH}     /aai/v11
11 ${ROOT_TENANT_PATH}  /cloud-infrastructure/cloud-regions/cloud-region/
12
13 ${AAI_ADD_TENANT_BODY}=    aai/add_tenant_body.jinja
14
15 *** Keywords ***
16 Inventory Tenant If Not Exists
17     [Documentation]    Creates a service in A&AI if it doesn't exist
18     [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}
20     ${status}    ${value}=    Run Keyword And Ignore Error    Dictionary Should Contain Key    ${dict}    ${tenant_id}
21     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}
22
23 Inventory Tenant
24     [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}
26     ${json_resource_version}=   Get Resource Version If Exists   ${cloud_owner}  ${cloud_region_id}  ${cloud_type}    ${owner_defined_type}    ${cloud_region_version}    ${cloud_zone}
27     ${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}
28     Create Environment    aai    ${GLOBAL_TEMPLATE_FOLDER}
29     ${data}=   Apply Template    aai   ${AAI_ADD_TENANT_BODY}    ${arguments}
30         ${put_resp}=    Run A&AI Put Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}     ${data}
31     ${status_string}=    Convert To String    ${put_resp.status_code}
32     Should Match Regexp    ${status_string}     ^(201|200)$
33
34 Get Resource Version If Exists
35     [Documentation]    Creates a service in A&AI if it doesn't exist
36     [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()}
41     ${resource_version}=   Catenate   ${json['resource-version']}
42     [Return]   "resource-version":"${resource_version}",
43
44
45 Delete Tenant
46     [Documentation]    Removes both Tenant
47     [Arguments]    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}
48     ${get_resp}=    Run A&AI Get Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants/tenant/${tenant_id}
49     Run Keyword If    '${get_resp.status_code}' == '200'    Delete Tenant Exists    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}    ${get_resp.json()['resource-version']}
50
51 Delete Tenant Exists
52     [Arguments]    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}    ${resource_version}
53     ${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
56 Delete Cloud Region
57     [Documentation]    Removes both Tenant and Cloud Region in A&AI
58     [Arguments]    ${tenant_id}    ${cloud_owner}    ${cloud_region_id}
59     ${get_resp}=    Run A&AI Get Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
60         Run Keyword If    '${get_resp.status_code}' == '200'    Delete Cloud Region Exists   ${tenant_id}    ${cloud_owner}    ${cloud_region_id}    ${get_resp.json()['resource-version']}
61
62 Delete Cloud Region Exists
63     [Documentation]   Delete may get status 400 (Bad Request) if the region is still referenced
64     [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}
66     ${status_string}=    Convert To String    ${put_resp.status_code}
67     Should Match Regexp    ${status_string}    ^(204|400)$
68
69 Get Tenants
70     [Documentation]   Return list of tenants for this cloud owner/region
71     [Arguments]    ${cloud_owner}    ${cloud_region_id}
72         ${resp}=    Run A&AI Get Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}/tenants
73         ${dict}=    Create Dictionary
74     ${status}    ${value}=    Run Keyword And Ignore Error    Should Be Equal As Strings        ${resp.status_code}     200
75     Run Keyword If    '${status}' == 'PASS'    Update Tenant Dictionary    ${dict}    ${resp.json()}
76         [Return]  ${dict}
77
78 Get Cloud Region
79     [Documentation]   Returns the Cloud Region if it exists
80     [Arguments]    ${cloud_owner}    ${cloud_region_id}
81         ${resp}=    Run A&AI Get Request     ${INDEX PATH}${ROOT_TENANT_PATH}${cloud_owner}/${cloud_region_id}
82         [Return]  ${resp}
83
84 Update Tenant Dictionary
85     [Arguments]    ${dict}    ${json}
86     ${list}=    Evaluate    ${json}['tenant']
87     :FOR   ${map}    IN    @{list}
88     \    ${status}    ${tenant_id}=     Run Keyword And Ignore Error    Get From Dictionary    ${map}    tenant-id
89     \    Run Keyword If    '${status}' == 'PASS'    Set To Dictionary    ${dict}    ${tenant_id}=${map}
90     Log    ${dict}
91
92
93