0584a2a1a1e4286399cde12dbacf669f2e4f63fc
[testsuite.git] / robot / resources / aai / create_service.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    Collections
9 Library           ONAPLibrary.Utilities
10
11
12
13 *** Variables ***
14 ${INDEX PATH}     /aai/v11
15 ${ROOT_SERVICE_PATH}  /service-design-and-creation/services
16
17 ${SYSTEM USER}    robot-ete
18 ${AAI_ADD_SERVICE_BODY}=    robot/assets/templates/aai/add_service_body.template
19
20 *** Keywords ***
21 Create Service If Not Exists
22     [Documentation]    Creates a service in A&AI if it doesn't exist
23     [Arguments]    ${service_type}
24     ${dict}=    Get Services
25     ${status}    ${value}=    Run Keyword And Ignore Error    Dictionary Should Contain Key    ${dict}    ${service_type}
26     Run Keyword If    '${status}' == 'FAIL'    Create Service    ${service_type}
27
28 Create Service
29     [Documentation]    Creates a service in A&AI
30     [Arguments]    ${service_type}
31     ${uuid}=    Generate UUID4
32     ${arguments}=    Create Dictionary    service_type=${service_type}    UUID=${uuid}
33     ${data}=    Fill JSON Template File    ${AAI_ADD_SERVICE_BODY}    ${arguments}
34     ${fullpath}=    Catenate         ${INDEX PATH}${ROOT_SERVICE_PATH}/service/${uuid}
35         ${put_resp}=    Run A&AI Put Request     ${fullpath}    ${data}
36     Should Be Equal As Strings  ${put_resp.status_code}         201
37         [Return]  ${put_resp.status_code}
38
39
40 Delete Service If Exists
41     [Documentation]    Deletes a service in A&AI if it exists
42     [Arguments]    ${service_type}
43     ${dict}=    Get Services
44     ${status}    ${value}=    Run Keyword And Ignore Error    Dictionary Should Contain Key    ${dict}    ${service_type}
45     Run Keyword If    '${status}' == 'PASS'    Delete Service    ${dict['${service_type}']}
46
47 Delete Service
48     [Documentation]    Delete  passed service in A&AI
49     [Arguments]    ${dict}
50     ${uuid}=    Get From Dictionary    ${dict}     service-id
51     ${resource_version}=    Get From Dictionary    ${dict}     resource-version
52     ${fullpath}=    Catenate         ${INDEX PATH}${ROOT_SERVICE_PATH}/service/${uuid}
53         ${resp}=    Run A&AI Delete Request    ${fullpath}    ${resource_version}
54     Should Be Equal As Strings  ${resp.status_code}     204
55
56
57 Get Services
58     [Documentation]    Creates a service in A&AI
59         ${resp}=    Run A&AI Get Request     ${INDEX PATH}${ROOT_SERVICE_PATH}
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}=    Evaluate    ${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}
72
73