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
6 # http://www.apache.org/licenses/LICENSE-2.0
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
16 Documentation Library with sol003 keywords and variables .
19 Library OperatingSystem
20 Library RequestsLibrary
25 Resource ../lib/vim_lib.resource
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}
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.
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}
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}
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}
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
67 [Documentation] Read Current Directory and return it
68 ${Directory}= Replace String ${CURDIR} lib resources
69 ${json_path}= Set Variable ${Directory}
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}
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} :
88 Set Dockerized Host ${nbi_host}
90 Set Standalone Host ${nbi_host}
94 [Documentation] Examine a REQUEST_RESPONSE dictionary as JSON and return the requested key passed as argument.
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}
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.
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}