b4e21bb070147a653a39501ccf61945d1e7e5a81
[testsuite.git] / robot / resources / aai / create_service.robot
1 *** Settings ***
2 Documentation     Create A&AI Customer API.
3
4 Resource    aai_interface.robot
5 Library    Collections
6 Library    ONAPLibrary.Utilities
7 Library    ONAPLibrary.Templating    WITH NAME    Templating
8 Library    ONAPLibrary.AAI    WITH NAME    AAI
9
10
11 *** Variables ***
12 ${INDEX PATH}     /aai/v11
13 ${ROOT_SERVICE_PATH}  /service-design-and-creation/services
14
15 ${SYSTEM USER}    robot-ete
16 ${AAI_ADD_SERVICE_BODY}=    aai/add_service_body.jinja
17
18 *** Keywords ***
19 Create Service If Not Exists
20     [Documentation]    Creates a service in A&AI if it doesn't exist
21     [Arguments]    ${service_type}
22     ${dict}=    Get Services
23     ${status}    ${value}=    Run Keyword And Ignore Error    Dictionary Should Contain Key    ${dict}    ${service_type}
24     Run Keyword If    '${status}' == 'FAIL'    Create Service    ${service_type}
25
26 Create Service
27     [Documentation]    Creates a service in A&AI
28     [Arguments]    ${service_type}
29     ${uuid}=    Generate UUID4
30     ${arguments}=    Create Dictionary    service_type=${service_type}    UUID=${uuid}
31     Templating.Create Environment    aai    ${GLOBAL_TEMPLATE_FOLDER}
32     ${data}=   Templating.Apply Template    aai   ${AAI_ADD_SERVICE_BODY}    ${arguments}
33     ${fullpath}=    Catenate         ${INDEX PATH}${ROOT_SERVICE_PATH}/service/${uuid}
34     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
35         ${put_resp}=    AAI.Run Put Request     ${AAI_FRONTEND_ENDPOINT}    ${fullpath}    ${data}        auth=${auth}
36     Should Be Equal As Strings  ${put_resp.status_code}         201
37         [Return]  ${put_resp.status_code}
38
39 Delete Service If Exists
40     [Documentation]    Deletes a service in A&AI if it exists
41     [Arguments]    ${service_type}
42     ${dict}=    Get Services
43     ${status}    ${value}=    Run Keyword And Ignore Error    Dictionary Should Contain Key    ${dict}    ${service_type}
44     Run Keyword If    '${status}' == 'PASS'    Delete Service    ${dict['${service_type}']}
45
46 Delete Service
47     [Documentation]    Delete  passed service in A&AI
48     [Arguments]    ${dict}
49     ${uuid}=    Get From Dictionary    ${dict}     service-id
50     ${resource_version}=    Get From Dictionary    ${dict}     resource-version
51     ${fullpath}=    Catenate         ${INDEX PATH}${ROOT_SERVICE_PATH}/service/${uuid}
52     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
53         ${resp}=    AAI.Run Delete Request    ${AAI_FRONTEND_ENDPOINT}    ${fullpath}    ${resource_version}        auth=${auth}
54     Should Be Equal As Strings  ${resp.status_code}     204
55
56 Get Services
57     [Documentation]    Creates a service in A&AI
58     ${auth}=  Create List  ${GLOBAL_AAI_USERNAME}    ${GLOBAL_AAI_PASSWORD}
59         ${resp}=    AAI.Run Get Request     ${AAI_FRONTEND_ENDPOINT}    ${INDEX PATH}${ROOT_SERVICE_PATH}        auth=${auth}
60         ${dict}=    Create Dictionary
61     ${status}    ${value}=    Run Keyword And Ignore Error    Should Be Equal As Strings        ${resp.status_code}     200
62     Run Keyword If    '${status}' == 'PASS'    Update Service Dictionary    ${dict}    ${resp.json()}
63         [Return]  ${dict}
64
65 Update Service Dictionary
66     [Arguments]    ${dict}    ${json}
67     @{list}=  Copy List   ${json['service']}
68     :FOR   ${map}    IN    @{list}
69     \    ${status}    ${service_type}=     Run Keyword And Ignore Error    Get From Dictionary    ${map}    service-description
70     \    Run Keyword If    '${status}' == 'PASS'    Set To Dictionary    ${dict}    ${service_type}=${map}
71     Log    ${dict}