3f146041008e3309eee35307d9aaa77950f22093
[it/test.git] / ric_robot_suite / robot / resources / appmgr / appmgr_interface.robot
1 *** Settings ***
2 Documentation  Keywords for interacting with the XApp Manager, including listing, deploying, and undeploying XApps
3
4 Library        RequestsLibrary
5
6 Resource       ../global_properties.robot
7
8 *** Variables ***
9 ${APPMGR_BASE_PATH}  /ric/v1/xapps
10 ${APPMGR_ENDPOINT}   ${GLOBAL_APPMGR_SERVER_PROTOCOL}://${GLOBAL_INJECTED_APPMGR_IP_ADDR}:${GLOBAL_APPMGR_SERVER_PORT}
11
12 *** Keywords ***
13 Run AppMgr Health Check
14      [Documentation]    Runs AppMgr Health check
15      Run Keyword        Get Deployed XApps
16
17 Get Deployed XApps
18      [Documentation]  Obtain the list of deployed XApps from the Appmgr
19      ${resp} =        Run AppMgr GET Request
20      [Return]         ${resp.json()}
21
22 Get Deployable XApps
23      [Documentation]  Obtain the list of deployed XApps from the Appmgr
24      ${resp} =        Run AppMgr GET Request  /search/
25      Should Be True   ${resp}
26      [Return]         ${resp.json()}
27
28 Get XApp By Name
29      [Documentation]  Get installed XApp from Appmgr given name
30      [Arguments]      ${xapp_name}
31      ${resp} =        Run AppMgr GET Request  /${xapp_name}
32      Should Be True   ${resp}
33      [Return]         ${resp.json()}
34
35 Get XApp By Name and ID
36      [Documentation]  Get installed XApp from Appmgr by name and ID
37      [Arguments]      ${xapp_name}  ${xapp_id}
38      ${resp}=         Run AppMgr GET Request  /${xapp_name}/${xapp_id}/
39      Should Be True   ${resp}
40      [Return]         ${resp.json()}
41
42 Deploy XApp
43      [Documentation]  Create Xapp
44      [Arguments]      ${xapp_name}
45      &{dict} =        Create Dictionary        name=${xapp_name}
46      ${data} =        Evaluate                 json.dumps(&{dict})  json
47      ${resp} =        Run AppMgr POST Request  ${EMPTY}             ${data}
48      Should Be True   ${resp}
49      [Return]         ${resp}
50
51 Deploy XApps
52      [Documentation]  Create one or more XApps
53      [Arguments]      @{xapp_names}
54      :FOR             ${xapp}  IN             @{xapp_names}
55      \                Deploy XApp   ${xapp}
56
57 Undeploy XApp
58      [Documentation]  Remove a deployed XApp
59      [Arguments]      ${xapp_name}
60      ${resp} =        Run AppMgr DELETE Request  /${xapp_name}
61      Should Be True   ${resp}
62      [Return]         ${resp}
63
64 Undeploy XApps
65      [Documentation]  Remove one or more deployed XApps
66      [Arguments]      @{xapp_names}
67      :FOR             ${xapp}  IN     @{xapp_names}
68      \                Undeploy XApp   ${xapp}
69
70 Deploy All Available XApps
71      [Documentation]  Attempt to deploy any not-currently-deployed XApp
72      @{d} =          Get Deployed XApps
73      @{deployed} =   Pluck               name          ${d}
74      @{available} =  Get Deployable XApps
75      @{toDeploy} =   Subtract From List  ${available}  ${deployed}
76      Deploy XApps    @{toDeploy}
77
78 Undeploy All Running XApps
79      [Documentation]  Undeploy any deployed XApps
80      @{d} =           Get Deployed XApps
81      @{deployed} =    Pluck  name  ${d}
82      Run Keyword If   ${deployed}  Undeploy XApps  @{deployed}
83
84 Run AppMgr GET Request
85      [Documentation]  Make an HTTP GET request against the XApp manager
86      [Arguments]   ${path}=${EMPTY}
87      ${session} =  Create Session     roboAppmgrGet                   ${APPMGR_ENDPOINT}
88      ${headers} =  Create Dictionary  Accept=application/json         Content-Type=application/json
89      ${resp} =     Get Request        roboAppmgrGet                   ${APPMGR_BASE_PATH}${path}  headers=${headers}
90      [Return]      ${resp}
91
92 Run AppMgr POST Request
93      [Documentation]    Make an HTTP POST request against the XApp manager
94      [Arguments]   ${path}=${EMPTY}   ${body}=${EMPTY}
95      ${session} =  Create Session     roboAppmgrPost                  ${APPMGR_ENDPOINT}
96      ${headers} =  Create Dictionary  Accept=application/json         Content-Type=application/json
97      ${resp} =     Post Request       roboAppmgrPost                  ${APPMGR_BASE_PATH}${path}  headers=${headers}  data=${body}
98      [Return]      ${resp}
99
100 Run AppMgr DELETE Request
101      [Documentation]  Make an HTTP DELETE request against the XApp manager
102      [Arguments]      ${path}
103      ${session} =     Create Session     roboAppmgrDelete                ${APPMGR_ENDPOINT}
104      ${headers} =     Create Dictionary  Accept=application/json         Content-Type=application/json
105      ${resp} =        Delete Request     roboAppmgrDelete                ${APPMGR_BASE_PATH}${path}  headers=${headers}
106      [Return]         ${resp}
107
108
109 # a few useful list routines that should probably live elsewhere
110 Pluck
111      [Documentation]  Get the values of a specific key from a list of dictionaries
112      [Arguments]      ${k}      ${l}
113      @{names} =       Evaluate  filter(lambda v: v != None, [i.get('${k}', None) for i in ${l}])
114      [Return]         ${names}
115
116 Subtract From List
117      [Documentation]  Remove the elements of the second argument from the first
118      [Arguments]      ${x}  ${y}
119      ${diff} =        Run Keyword If  ${y}
120      ...              Evaluate  filter(lambda v: v not in ${y}, ${x})
121      ...              ELSE
122      ...              Set Variable    ${x}
123      [Return]         ${diff}