blob: 82c95d295e88318ffac00f24bec07cfa6d0cc944 [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}
64 Set Suite Variable ${REST_API_HOST} https://${env_host}:9999
65
66Read Directory
67 [Documentation] Read Current Directory and return it
rarik7d7628b2023-12-14 07:14:53 +000068 ${Directory}= Replace String ${CURDIR} lib resources
garciadeblas7a9e0312023-12-11 22:24:46 +010069 ${json_path}= Set Variable ${Directory}
70 RETURN ${json_path}
71
72Post Api Request
73 [Documentation] Send to OSM a POST API message to OSM to the given uri with the given json data,
74 ... and save response and status code in suite variables to be used later on.
75 [Arguments] ${PostApi} ${json_data}
76 Create Session APISession ${REST_API_HOST}
77 &{headers}= Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${ACCESS_TOKEN}
78 ${request_response}= Post On Session APISession ${PostApi} json=${json_data} headers=${headers}
79 Set Suite Variable ${REQUEST_RESPONSE} ${request_response}
80 ${response_statuscode}= Convert To String ${request_response.status_code}
81 Set Suite Variable ${RESPONSE_STATUSCODE} ${response_statuscode}
82
83Set REST API Host
84 [Documentation] Set the REST_API_HOST suite variable from OSM_HOSTNAME env variable
85 ${nbi_host}= Get Environment Variable OSM_HOSTNAME
86 ${passed}= Run Keyword And Return Status Should Contain ${nbi_host} :
87 IF ${passed}
88 Set Dockerized Host ${nbi_host}
89 ELSE
90 Set Standalone Host ${nbi_host}
91 END
92
93Get ID
94 [Documentation] Examine a REQUEST_RESPONSE dictionary as JSON and return the requested key passed as argument.
95 [Arguments] ${Key}
96 Pass Execution If ${REQUEST_RESPONSE.status_code} in ${SUCCESS_STATUS_CODE_LIST} Get Auth Token completed
97 ${id}= Get Value From Json ${REQUEST_RESPONSE.json()} $..${Key}
98 RETURN ${id[0]}
99
100Get Api Request
101 [Documentation] Send to OSM a GET API message to OSM to the given uri,
102 ... and save response and status code in suite variables to be used later on.
103 [Arguments] ${uri}
104 Create Session Session ${REST_API_HOST}
105 &{headers}= Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${ACCESS_TOKEN}
106 ${request_response}= Get On Session Session ${uri} headers=${headers}
107 Set Suite Variable ${REQUEST_RESPONSE} ${request_response}
108 ${response_statuscode}= Convert To String ${request_response.status_code}
109 Set Suite Variable ${RESPONSE_STATUSCODE} ${response_statuscode}