replace aai keywords with aai lib
[testsuite.git] / robot / resources / aai / service_instance.robot
1 *** Settings ***
2 Documentation     Validate A&AI Serivce Instance
3
4 Resource          aai_interface.robot
5 Library    Collections
6 Library    OperatingSystem
7 Library    RequestsLibrary
8 Library    ONAPLibrary.JSON
9 Library    ONAPLibrary.Templating    WITH NAME    Templating
10 Library    ONAPLibrary.AAI    WITH NAME    AAI
11 Resource          ../stack_validation/validate_vlb.robot
12 Resource          ../stack_validation/validate_vfw.robot
13 Resource          ../stack_validation/validate_vvg.robot
14 Resource          ../aai/aai_interface.robot
15
16 *** Variables ***
17 ${INDEX PATH}     /aai/v11
18 ${GENERIC_QUERY_PATH}  /search/generic-query?
19 ${SYSTEM USER}    robot-ete
20 ${CUSTOMER SPEC PATH}    /business/customers/customer/
21 ${SERVICE SUBSCRIPTIONS}    /service-subscriptions/service-subscription/
22 ${SERVICE INSTANCE}    /service-instances?service-instance-id=
23 ${SERVCE INSTANCE TEMPLATE}    aai/service_subscription.jinja
24
25 ${GENERIC_VNF_PATH_TEMPLATE}   /network/generic-vnfs/generic-vnf/\${vnf_id}/vf-modules/vf-module/\${vf_module_id}
26 ${GENERIC_VNF_QUERY_TEMPLATE}   /network/generic-vnfs/generic-vnf/\${vnf_id}/vf-modules/vf-module?vf-module-name=\${vf_module_name}
27 ${VLB_CLOSED_LOOP_HACK_BODY}    aai/vlb_closed_loop_hack.jinja
28
29 #*************** Test Case Variables *************
30 ${VLB_CLOSED_LOOP_DELETE}
31 ${VLB_CLOSED_LOOP_VNF_ID}
32
33 *** Keywords ***
34 Validate Service Instance
35     [Documentation]    Query and Validates A&AI Service Instance
36     [Arguments]    ${service_instance_name}    ${service_type}  ${customer_name}
37     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
38     ${cust_resp}=    AAI.Run Get Request      ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}/business/customers?subscriber-name=${customer_name}        auth=${auth
39         ${resp}=    AAI.Run Get Request      ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}${CUSTOMER SPEC PATH}${cust_resp.json()['customer'][0]['global-customer-id']}${SERVICE SUBSCRIPTIONS}${service_type}${SERVICE INSTANCE}${service_instance_name}        auth=${auth
40     Dictionary Should Contain Value     ${resp.json()['service-instance'][0]}    ${service_instance_name}
41
42 Validate Generic VNF
43     [Documentation]    Query and Validates A&AI Service Instance
44     [Arguments]    ${vnf_name}  ${vnf_type}    ${service_instance_id}
45     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
46     ${generic_vnf}=    AAI.Run Get Request      ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}/network/generic-vnfs/generic-vnf?vnf-name=${vnf_name}        auth=${auth
47     Dictionary Should Contain Value     ${generic_vnf.json()}    ${vnf_name}
48     ${returned_vnf_type}=    Get From Dictionary    ${generic_vnf.json()}    vnf-type
49     Should Contain      ${returned_vnf_type}    ${vnf_type}
50     ${vnf_id}=    Get From Dictionary    ${generic_vnf.json()}    vnf-id
51     ${generic_vnf}=    AAI.Run Get Request      ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}/network/generic-vnfs/generic-vnf/${vnf_id}?depth=all        auth=${auth
52     [Return]    ${generic_vnf.json()}
53
54 VLB Closed Loop Hack
55     [Arguments]    ${service}    ${generic_vnf}   ${closedloop_vf_module}
56     Return From Keyword If    '${service}' != 'vLB'
57     ${vnf_id}=     Get From Dictionary    ${generic_vnf}    vnf-id
58     ${vf_modules}=    Get From Dictionary    ${generic_vnf}    vf-modules
59     ${list}=    Get From Dictionary    ${vf_modules}   vf-module
60     ${vfmodule}=    Get From List    ${list}    0
61     ${persona_model_id}=    Get From Dictionary    ${closedloop_vf_module}    invariantUUID
62     ${persona_model_version}=   Get From Dictionary    ${closedloop_vf_module}    version
63     ${dummy}=    Catenate   dummy_${vnf_id}
64     ${dict}=    Create Dictionary   vnf_id=${vnf_id}   vf_module_id=${dummy}   persona_model_id=${persona_model_id}   persona_model_version=${persona_model_version}
65     ${datapath}=    Templating.Template String    ${GENERIC_VNF_PATH_TEMPLATE}    ${dict}
66     Templating.Create Environment    aai    ${GLOBAL_TEMPLATE_FOLDER}
67     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
68     ${data}=   Templating.Apply Template    aai   ${VLB_CLOSED_LOOP_HACK_BODY}    ${dict}
69         ${put_resp}=    AAI.Run Put Request     ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}${datapath}   ${data}        auth=${auth
70     ${status_string}=    Convert To String    ${put_resp.status_code}
71     Should Match Regexp    ${status_string}    ^(201|412)$
72     Set Test Variable   ${VLB_CLOSED_LOOP_DELETE}    ${datapath}
73     Set Test Variable   ${VLB_CLOSED_LOOP_VNF_ID}    ${vnf_id}
74
75 VLB Closed Loop Hack Update
76     [Documentation]   Update the A&AI vDNS scaling vf module to have persona-model-version 1 rather than 1.0
77     [Arguments]   ${stack_name}
78     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
79     ${dict}=    Create Dictionary   vnf_id=${VLB_CLOSED_LOOP_VNF_ID}   vf_module_name=${stack_name}
80     ${query}=   Templating.Template String   ${GENERIC_VNF_QUERY_TEMPLATE}   ${dict}
81     ${get_resp}=    AAI.Run Get Request     ${AAI_FRONTEND_ENDPOINT}    ${INDEX_PATH}${query}        auth=${auth
82     ${json}=   Set Variable   ${get_resp.json()}
83     Set to Dictionary    ${json}   persona-model-version   1
84     ${vf_module_id}=   Get From Dictionary   ${json}   vf-module-id
85     Set to Dictionary   ${dict}   vf_module_id=${vf_module_id}
86     ${uri}=   Templating.Template String   ${GENERIC_VNF_PATH_TEMPLATE}   ${dict}
87     ${resp}=   AAI.Run Put Request    ${AAI_FRONTEND_ENDPOINT}    ${INDEX_PATH}${uri}   ${json}        auth=${auth
88     ${get_resp}=    AAI.Run Get Request     ${AAI_FRONTEND_ENDPOINT}    ${INDEX_PATH}${query}        auth=${auth
89
90 Teardown VLB Closed Loop Hack
91     Return From Keyword If    ' ${VLB_CLOSED_LOOP_DELETE}' == ''
92         Delete A&AI Entity    ${VLB_CLOSED_LOOP_DELETE}
93
94 Validate VF Module
95     [Documentation]    Query and Validates A&AI Service Instance
96     [Arguments]    ${vf_module_name}    ${stack_type}
97         Run Keyword If    '${stack_type}'=='vLB'    Validate vLB Stack    ${vf_module_name}
98         Run Keyword If    '${stack_type}'=='vFW'    Validate Firewall Stack    ${vf_module_name}
99         Run Keyword If    '${stack_type}'=='vVG'    Validate vVG Stack    ${vf_module_name}