[HV-VES] Improve hv-ves suite
[testsuite.git] / robot / resources / dcae / inventory.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with 5G Bulkpm.
3 Library               RequestsLibrary
4 Library           OperatingSystem
5 Library           String
6 Library           ONAPLibrary.Templating    WITH NAME    Templating
7 Resource          ../global_properties.robot
8
9
10 *** Variables ***
11 ${INVENTORY_SERVER}                 ${GLOBAL_INVENTORY_SERVER_PROTOCOL}://${GLOBAL_INVENTORY_SERVER_NAME}:${GLOBAL_INVENTORY_SERVER_PORT}
12 ${INVENTORY_ENDPOINT}               /dcae-service-types
13 ${BLUEPRINT_TEMPLATE}               ${EXECDIR}/robot/assets/cmpv2/blueprintTemplate.json
14 *** Keywords ***
15
16 Load Blueprint To Inventory
17     [Arguments]                         ${blueprint_path}                   ${typeName}
18     Disable Warnings
19     ${blueprint}=                       OperatingSystem.Get File            ${blueprint_path}
20     ${templatejson}=                    Load JSON From File                 ${BLUEPRINT_TEMPLATE}
21     ${templatejson}=                    Update Value To Json                ${templatejson}                            blueprintTemplate             ${blueprint}
22     ${templatejson}=                    Update Value To Json                ${templatejson}                            typeName                      ${typeName}
23     ${data}                             Convert JSON To String              ${templatejson}
24     ${headers}=                         Create Dictionary                   content-type=application/json
25     ${session}=                         Create Session                      inventory_session                           ${INVENTORY_SERVER}
26     ${resp}=                            Post Request                        inventory_session                           ${INVENTORY_ENDPOINT}           data=${data}             headers=${headers}
27     ${serviceTypeId}=                   Set Variable                        ${resp.json().get('typeId')}
28     [Return]                            ${serviceTypeId}
29
30 Delete Blueprint From Inventory
31     [Arguments]                         ${serviceTypeId}
32     Disable Warnings
33     ${session}=                         Create Session                      inventory_session                           ${INVENTORY_SERVER}
34     ${resp}=                            Delete Request                      inventory_session                           ${INVENTORY_ENDPOINT}/${serviceTypeId}
35     [Return]                            ${resp}
36
37 Get Blueprint From Inventory
38     [Arguments]                         ${typeName}
39     Disable Warnings
40     ${headers}=                         Create Dictionary                   content-type=application/json
41     ${session}=                         Create Session                      inventory_session                           ${INVENTORY_SERVER}
42     ${resp}=                            Get Request                         inventory_session                           ${INVENTORY_ENDPOINT}?typeName=${typeName}      headers=${headers}
43     Should Not Be Equal As Integers  ${resp.json().get('totalCount')}  0  msg=Blueprint ${typeName} does not exist in inventory!
44     [Return]                            ${resp}
45
46