Issue-ID: RIC-149
[it/test.git] / ric_robot_suite / helm / nanobot / configmap-src / public / resources / a1mediator_interface.robot
1 *** Settings *** 
2 Documentation  Keywords for interacting with the A1 interface, including policy creation, instantiaton, and deletion 
3  
4 Library        RequestsLibrary 
5  
6 Resource       /robot/resources/global_properties.robot 
7  
8 Resource       /robot/resources/ric/ric_utils.robot 
9  
10 *** Variables *** 
11 ${A1MEDIATOR_BASE_PATH}  /a1-p/policytypes 
12 ${A1MEDIATOR_ENDPOINT}   ${GLOBAL_A1MEDIATOR_SERVER_PROTOCOL}://${GLOBAL_INJECTED_A1MEDIATOR_IP_ADDR}:${GLOBAL_A1MEDIATOR_SERVER_PORT} 
13  
14 *** Keywords *** 
15  
16 Run A1Mediator Health Check 
17      [Documentation]    Runs A1Mediator Health check 
18      Log To Console     Entering a1mediator 
19      ${resp} =  Run A1mediator GET Request 
20      Log To Console     ${resp} 
21  
22 Create A1 Policy Type 
23      [Documentation]  Create a new policy via the A1 Mediator. 
24      [Arguments]      ${type}  ${name}  ${description}  ${properties}  ${required}=@{EMPTY} 
25      ${typeID} =        Convert To Integer  ${type} 
26      Should Be True     ${type} > 0         Policy type must be an integer > 0 
27      ${createSchema} =  Create Dictionary 
28      ...                $schema=http://json-schema.org/draft-07/schema# 
29      ...                type=object 
30      ...                properties=${properties} 
31      ...                required=@{required} 
32      ${createBody} =    Create Dictionary 
33      ...                name=${name} 
34      ...                policy_type_id=${typeID} 
35      ...                description=${description} 
36      ...                create_schema=${createSchema} 
37      ${createJSON} =    Evaluate                    json.dumps(&{createBody})  json,uuid 
38      ${resp} =          Run A1Mediator PUT Request  /${type}  body=${createJSON} 
39      [Return]           ${resp} 
40  
41 Instantiate A1 Policy 
42      [Documentation]  Create a new instance of an A1 policy 
43      [Arguments]      ${type}  ${instance}  ${properties}=${EMPTY} 
44      ${typeID} =        Convert To Integer  ${type} 
45      Should Be True     ${type} > 0         Policy type must be an integer > 0 
46      ${instanceJSON} =  Evaluate            json.dumps(&{properties})  json,uuid 
47      ${resp} =          Run A1Mediator PUT Request  /${type}/policies/${instance}  body=${instanceJSON} 
48      [Return]           ${resp} 
49  
50 Delete A1 Instance 
51      [Documentation]  Remove an A1 policy instance 
52      [Arguments]      ${type}  ${instance} 
53      ${typeID} =        Convert To Integer  ${type} 
54      Should Be True     ${type} > 0         Policy type must be an integer > 0 
55      ${resp} =          Run A1Mediator DELETE Request  /${type}/policies/${instance} 
56      [Return]           ${resp} 
57  
58 Delete A1 Policy 
59      [Documentation]  Remove an A1 policy type 
60      [Arguments]      ${type} 
61      ${typeID} =        Convert To Integer  ${type} 
62      Should Be True     ${type} > 0         Policy type must be an integer > 0 
63      ${resp} =          Run A1Mediator DELETE Request  /${type} 
64      [Return]           ${resp} 
65  
66 Retrieve A1 Policy 
67      [Documentation]  Get a defined policy from A1 
68      [Arguments]      ${type} 
69      ${typeID} =        Convert To Integer  ${type} 
70      Should Be True     ${type} > 0         Policy type must be an integer > 0 
71      ${resp} =          Run A1Mediator GET Request  /${type} 
72      [Return]           ${resp} 
73  
74 Retrieve A1 Instance 
75      [Documentation]  Get a defined policy from A1.  If no instance is specified, retrieve all instances. 
76      [Arguments]      ${type}  ${instance}=${EMPTY} 
77      ${typeID} =        Convert To Integer  ${type} 
78      Should Be True     ${type} > 0         Policy type must be an integer > 0 
79      ${resp} =          Run Keyword If              "${instance}" != "${EMPTY}" 
80      ...                Run A1Mediator GET Request  /${type}/policies/${instance} 
81      ...                ELSE 
82      ...                Run A1Mediator GET Request  /${type}/policies 
83      [Return]           ${resp} 
84  
85 Retrieve A1 Instance Status 
86      [Documentation]  Get policy instance status 
87      [Arguments]      ${type}  ${instance}=${EMPTY} 
88      ${typeID} =        Convert To Integer  ${type} 
89      Should Be True     ${type} > 0         Policy type must be an integer > 0 
90      ${resp} =          Run A1Mediator GET Request                /${type}/policies/${instance}/status 
91      [Return]           ${resp} 
92  
93 Run A1mediator GET Request 
94      [Documentation]  Make an HTTP GET request against the XApp manager 
95      [Arguments]   ${path}=${EMPTY} 
96      ${session} =  Create Session     roboA1mediatorGet           ${A1MEDIATOR_ENDPOINT} 
97      ${headers} =  Create Dictionary  Accept=application/json     Content-Type=application/json 
98      ${resp} =     Get Request        roboA1mediatorGet           ${A1MEDIATOR_BASE_PATH}${path}  headers=${headers} 
99      [Return]      ${resp} 
100  
101 Run A1mediator PUT Request 
102      [Documentation]    Make an HTTP PUT request against the XApp manager 
103      [Arguments]   ${path}=${EMPTY}   ${body}=${EMPTY} 
104      ${session} =  Create Session     roboA1mediatorPut           ${A1MEDIATOR_ENDPOINT} 
105      ${headers} =  Create Dictionary  Accept=application/json     Content-Type=application/json 
106      ${resp} =     PUT Request        roboA1mediatorPut           ${A1MEDIATOR_BASE_PATH}${path} 
107      ...                                                           headers=${headers} 
108      ...                                                           data=${body} 
109      [Return]      ${resp} 
110  
111 Run A1mediator POST Request 
112      [Documentation]    Make an HTTP POST request against the XApp manager 
113      [Arguments]   ${path}=${EMPTY}   ${body}=${EMPTY} 
114      ${session} =  Create Session     roboA1mediatorPost          ${A1MEDIATOR_ENDPOINT} 
115      ${headers} =  Create Dictionary  Accept=application/json     Content-Type=application/json 
116      ${resp} =     POST Request       roboA1mediatorPost          ${A1MEDIATOR_BASE_PATH}${path} 
117      ...                                                           headers=${headers} 
118      ...                                                           data=${body} 
119      [Return]      ${resp} 
120  
121 Run A1mediator DELETE Request 
122      [Documentation]  Make an HTTP DELETE request against the XApp manager 
123      [Arguments]      ${path} 
124      ${session} =     Create Session     roboA1mediatorDelete     ${A1MEDIATOR_ENDPOINT} 
125      ${headers} =     Create Dictionary  Accept=application/json  Content-Type=application/json 
126      ${resp} =        Delete Request     roboA1mediatorDelete     ${A1MEDIATOR_BASE_PATH}${path}  headers=${headers} 
127      [Return]         ${resp} 
128