Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame^] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | *** Settings *** |
| 16 | Documentation Library for interacting with XOS |
| 17 | Library String |
| 18 | Library RequestsLibrary |
| 19 | |
| 20 | *** Keywords *** |
| 21 | CORD Get |
| 22 | [Documentation] Make a GET call to XOS |
| 23 | [Arguments] ${service} |
| 24 | ${resp}= Get Request ${server_ip} ${service} |
| 25 | Log ${resp.content} |
| 26 | Should Be Equal As Strings ${resp.status_code} 200 |
| 27 | [Return] ${resp} |
| 28 | |
| 29 | CORD Post |
| 30 | [Documentation] Make a POST call to XOS |
| 31 | [Arguments] ${service} ${data} |
| 32 | ${data}= Evaluate json.dumps(${data}) json |
| 33 | ${resp}= Post Request ${SERVER_IP} uri=${service} data=${data} |
| 34 | Log ${resp.content} |
| 35 | Should Be Equal As Strings ${resp.status_code} 200 |
| 36 | [Return] ${resp} |
| 37 | |
| 38 | CORD Put |
| 39 | [Documentation] Make a PUT call to XOS |
| 40 | [Arguments] ${service} ${data} ${data_id} |
| 41 | ${data}= Evaluate json.dumps(${data}) json |
| 42 | ${resp}= Put Request ${SERVER_IP} uri=${service}/${data_id} data=${data} |
| 43 | Log ${resp.content} |
| 44 | Should Be Equal As Strings ${resp.status_code} 200 |
| 45 | ${id}= Get From Dictionary ${resp.json()} id |
| 46 | Set Suite Variable ${id} |
| 47 | [Return] ${resp} |
| 48 | |
| 49 | CORD Delete |
| 50 | [Documentation] Make a DELETE call to XOS |
| 51 | [Arguments] ${service} ${data_id} |
| 52 | ${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id} |
| 53 | Log ${resp.content} |
| 54 | Should Be Equal As Strings ${resp.status_code} 200 |
| 55 | [Return] ${resp} |
| 56 | |
| 57 | Get Service Owner Id |
| 58 | [Documentation] Find the id of owner of an XOS service |
| 59 | [Arguments] ${service} |
| 60 | ${resp}= CORD Get ${service} |
| 61 | ${jsondata}= To Json ${resp.content} |
| 62 | log ${jsondata} |
| 63 | ${length}= Get Length ${jsondata['items']} |
| 64 | # FIXME: should this break after finding the first item? |
| 65 | FOR ${INDEX} IN RANGE 0 ${length} |
| 66 | ${value}= Get From List ${jsondata['items']} ${INDEX} |
| 67 | ${id}= Get From Dictionary ${value} id |
| 68 | END |
| 69 | [Return] ${id} |
| 70 | |
| 71 | Clean Up Objects |
| 72 | [Documentation] Delete all objects in XOS data model |
| 73 | [Arguments] ${model_api} |
| 74 | @{ids}= Create List |
| 75 | ${resp}= CORD Get ${model_api} |
| 76 | ${jsondata}= To Json ${resp.content} |
| 77 | Log ${jsondata} |
| 78 | ${length}= Get Length ${jsondata['items']} |
| 79 | FOR ${INDEX} IN RANGE 0 ${length} |
| 80 | ${value}= Get From List ${jsondata['items']} ${INDEX} |
| 81 | ${id}= Get From Dictionary ${value} id |
| 82 | Append To List ${ids} ${id} |
| 83 | END |
| 84 | FOR ${i} IN @{ids} |
| 85 | CORD Delete ${model_api} ${i} |
| 86 | END |