Release image version 1.12.2
[testsuite.git] / robot / resources / so / add_service_recipe.robot
1 *** Settings ***
2 Documentation      Creates a macro service recipe in SO Catalog DB
3
4 Library    OperatingSystem
5 Library    Collections
6 Library    ONAPLibrary.SO    WITH NAME    SO
7 Library    ONAPLibrary.Templating    WITH NAME    Templating
8 Resource    ../global_properties.robot
9
10 *** Variables ***
11 ${SERVICE_RECIPE_PATH}    /serviceRecipe
12
13 ${SYSTEM USER}    robot-ete
14 ${SO_ADD_SERVICE_RECIPE}   so/service_recipe.jinja
15
16
17
18 *** Keywords ***
19 Add Service Recipe
20     [Documentation]    Creates a macro service recipe in SO Catalog DB
21     [Arguments]    ${service_model_UUID}  ${orchestrationUri}
22     ${id}=  Get First Free Service Recipe Id
23     ${arguments}=    Create Dictionary     service_model_UUID=${service_model_UUID}  orchestrationUri=${orchestrationUri}   id=${id}
24     Templating.Create Environment    so    ${GLOBAL_TEMPLATE_FOLDER}
25     ${data}=    Templating.Apply Template    so    ${SO_ADD_SERVICE_RECIPE}     ${arguments}
26     ${auth}=  Create List  ${GLOBAL_SO_CATDB_USERNAME}    ${GLOBAL_SO_PASSWORD}
27     ${get_resp}=   SO.Run Post Request   ${GLOBAL_SO_CATDB_ENDPOINT}    ${SERVICE_RECIPE_PATH}   ${data}    auth=${auth}
28     Should Be Equal As Strings  ${get_resp.status_code}     201
29     [Return]  ${id}
30
31 Get Service Recipe
32     [Documentation]    Gets service recipe/s in SO
33     [Arguments]    ${service_id}=
34     ${auth}=  Create List  ${GLOBAL_SO_CATDB_USERNAME}    ${GLOBAL_SO_PASSWORD}
35     ${get_resp}=    SO.Run Get Request    ${GLOBAL_SO_CATDB_ENDPOINT}    ${SERVICE_RECIPE_PATH}/${service_id}   auth=${auth}
36     Should Be Equal As Strings  ${get_resp.status_code}     200
37     [Return]   ${get_resp}
38
39 Get First Free Service Recipe Id
40     [Documentation]    Gets first free service recipe id in SO
41     ${get_resp}=  Get Service Recipe
42     ${source data}=   Set Variable  ${get_resp.json()}
43     Log  ${source data}
44     ${serviceRecipes}=    Set Variable     ${source data['_embedded']['serviceRecipe']}
45     ${ids}=    Create List
46     :FOR    ${recipe}     IN      @{serviceRecipes}
47     \    ${id}=    Get From Dictionary   ${recipe}     id
48     \    Append To List    ${ids}    ${id}
49     Sort list  ${ids}
50     ${biggest_id}=  Get From List  ${ids}  -1
51     Log  Biggest id is ${biggest_id} first free is ${biggest_id+1}
52     [Return]  ${biggest_id+1}
53
54 Delete Service Recipe
55      [Documentation]    Deletes service recipe/s in SO
56      [Arguments]    ${service_id}
57      ${auth}=  Create List  ${GLOBAL_SO_CATDB_USERNAME}    ${GLOBAL_SO_PASSWORD}
58      ${get_resp}=   SO.Run Delete Request   ${GLOBAL_SO_CATDB_ENDPOINT}    ${SERVICE_RECIPE_PATH}/${service_id}      auth=${auth}
59      Should Be Equal As Strings  ${get_resp.status_code}     204