blob: 654290d2568f27998e5abeb5a0baaed8d7cf1803 [file] [log] [blame]
garciadeblas7a9e0312023-12-11 22:24:46 +01001*** Comments ***
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License
13
14
15*** Settings ***
16Documentation Library with sol003 keywords and variables .
17
18Library String
19Library OperatingSystem
20Library RequestsLibrary
21Library JsonValidator
22Library yaml
23Library JSONLibrary
24
25Resource ../lib/vim_lib.resource
26
27
28*** Variables ***
29@{SUCCESS_STATUS_CODE_LIST} 200 201 202 204
30${AUTH_TOKEN_URI} /osm/admin/v1/tokens
31${REST_API_HOST} ${EMPTY}
32${OSM_USER} %{OSM_USER=admin}
33${OSM_PASSWORD} %{OSM_PASSWORD=admin}
34${OSM_PROJECT} %{OSM_PROJECT=admin}
35
36
37*** Keywords ***
38Get Auth Token
39 [Documentation] Send a REST POST message to OSM to get an authentication token,
40 ... and store the authentication token in a suite variable to be used later on.
41 Set REST API Host
42 Create Session osmhit ${REST_API_HOST} disable_warnings=1
43 &{headers}= Create Dictionary Content-Type=application/json Accept=application/json
44 &{data}= Create Dictionary username=${OSM_USER} password=${OSM_PASSWORD} project-id=${OSM_PROJECT}
45 ${resp}= Post On Session osmhit ${AUTH_TOKEN_URI} json=${data} headers=${headers}
46 Log ${resp}
47 Pass Execution If ${resp.status_code} in ${SUCCESS_STATUS_CODE_LIST} Get Auth Token completed
48 Set Suite Variable ${TOKEN_STATUS_CODE} ${resp.status_code}
49 ${access_token}= Get Value From Json ${resp.json()} $..id
50 Set Test Variable ${ACCESS_TOKEN} ${access_token[0]}
51 Set Test Variable ${TOKEN_RESPONSE} ${resp}
52 Sleep 2s
53
54Set Dockerized Host
55 [Documentation] Set the suite variable REST_API_HOST to be used in this library and the testsuites using it.
56 ... This method must be used if the tests are run from a container in the same K8s cluster where OSM is running.
57 [Arguments] ${env_host}
58 Set Suite Variable ${REST_API_HOST} https://${env_host}
59
60Set Standalone Host
61 [Documentation] Set a suite variable REST_API_HOST to be used in this library and the testsuites using it.
62 ... This method must be used if the tests are run from any place outside the K8s cluster where OSM is running.
63 [Arguments] ${env_host}
garciadeblas4f3854b2025-07-16 16:50:20 +020064 Set Suite Variable ${REST_API_HOST} https://${env_host}:443
garciadeblas7a9e0312023-12-11 22:24:46 +010065
garciadeblas4f3854b2025-07-16 16:50:20 +020066Get Resource Directory
67 [Documentation] Return Directory corresponding to the resources folder
rarik7d7628b2023-12-14 07:14:53 +000068 ${Directory}= Replace String ${CURDIR} lib resources
garciadeblas00ab2242025-07-17 09:55:57 +020069 RETURN ${Directory}
garciadeblas7a9e0312023-12-11 22:24:46 +010070
71Post Api Request
72 [Documentation] Send to OSM a POST API message to OSM to the given uri with the given json data,
73 ... and save response and status code in suite variables to be used later on.
74 [Arguments] ${PostApi} ${json_data}
75 Create Session APISession ${REST_API_HOST}
76 &{headers}= Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${ACCESS_TOKEN}
77 ${request_response}= Post On Session APISession ${PostApi} json=${json_data} headers=${headers}
78 Set Suite Variable ${REQUEST_RESPONSE} ${request_response}
79 ${response_statuscode}= Convert To String ${request_response.status_code}
80 Set Suite Variable ${RESPONSE_STATUSCODE} ${response_statuscode}
81
82Set REST API Host
83 [Documentation] Set the REST_API_HOST suite variable from OSM_HOSTNAME env variable
84 ${nbi_host}= Get Environment Variable OSM_HOSTNAME
85 ${passed}= Run Keyword And Return Status Should Contain ${nbi_host} :
86 IF ${passed}
87 Set Dockerized Host ${nbi_host}
88 ELSE
89 Set Standalone Host ${nbi_host}
90 END
91
92Get ID
93 [Documentation] Examine a REQUEST_RESPONSE dictionary as JSON and return the requested key passed as argument.
94 [Arguments] ${Key}
95 Pass Execution If ${REQUEST_RESPONSE.status_code} in ${SUCCESS_STATUS_CODE_LIST} Get Auth Token completed
96 ${id}= Get Value From Json ${REQUEST_RESPONSE.json()} $..${Key}
97 RETURN ${id[0]}
98
99Get Api Request
100 [Documentation] Send to OSM a GET API message to OSM to the given uri,
101 ... and save response and status code in suite variables to be used later on.
102 [Arguments] ${uri}
103 Create Session Session ${REST_API_HOST}
104 &{headers}= Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${ACCESS_TOKEN}
105 ${request_response}= Get On Session Session ${uri} headers=${headers}
106 Set Suite Variable ${REQUEST_RESPONSE} ${request_response}
107 ${response_statuscode}= Convert To String ${request_response.status_code}
108 Set Suite Variable ${RESPONSE_STATUSCODE} ${response_statuscode}