blob: 7541a52860515f2c2ce940eeb29ca3937addf5fb [file] [log] [blame]
dhanasekaran6f0aed32022-05-17 14:12:40 +02001# Licensed under the Apache License, Version 2.0 (the "License");
2# you may not use this file except in compliance with the License.
3# You may obtain a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10# See the License for the specific language governing permissions and
11# limitations under the License
12
13*** Settings ***
garciadeblasf4ebaa82022-06-23 13:33:26 +020014Documentation Library with sol003 keywords and variables .
dhanasekaran6f0aed32022-05-17 14:12:40 +020015
garciadeblasf4ebaa82022-06-23 13:33:26 +020016Library RequestsLibrary
17Library JsonValidator
18Library yaml
19Library JSONLibrary
20Library String
21Library OperatingSystem
22Resource %{ROBOT_DEVOPS_FOLDER}/lib/vim_lib.robot
Guillermo Calvinob3d11c02022-11-22 13:34:31 +010023Variables %{ROBOT_DEVOPS_FOLDER}/resources/sol003_01-vnf_lifecycle_management.py
dhanasekaran6f0aed32022-05-17 14:12:40 +020024
25*** Variables ***
garciadeblasf4ebaa82022-06-23 13:33:26 +020026@{success_status_code_list} 200 201 202 204
garciadeblasf4ebaa82022-06-23 13:33:26 +020027${auth_token_uri} /osm/admin/v1/tokens
28${HOST} ${EMPTY}
dhanasekaran6f0aed32022-05-17 14:12:40 +020029
30*** Keywords ***
31Get Auth Token
garciadeblasf4ebaa82022-06-23 13:33:26 +020032 [Tags] auth_token
dhanasekaran6f0aed32022-05-17 14:12:40 +020033 Get Hostname
garciadeblas43f34482023-02-23 17:37:47 +010034 Create Session osmhit ${HOST} disable_warnings=1
dhanasekarand90c14a2022-06-21 07:19:17 +000035 &{headers} Create Dictionary Content-Type=application/json Accept=application/json
Guillermo Calvinob3d11c02022-11-22 13:34:31 +010036 &{data} Create Dictionary username=${osm_user} password=${osm_password} project-id=${osm_project}
garciadeblasf4ebaa82022-06-23 13:33:26 +020037 ${resp}= Post On Session osmhit ${auth_token_uri} json=${data} headers=${headers}
garciadeblas321726f2022-12-21 11:43:06 +010038 Log ${resp}
garciadeblasf4ebaa82022-06-23 13:33:26 +020039 Pass Execution If ${resp.status_code} in ${success_status_code_list} Get Auth Token completed
40 Set Suite Variable ${token_status_code} ${resp.status_code}
41 ${access_token}= Get Value From Json ${resp.json()} $..id
42 Set Test Variable ${access_token} ${access_token[0]}
43 Set Test Variable ${token_response} ${resp}
44 sleep 2s
dhanasekaran6f0aed32022-05-17 14:12:40 +020045
46Set Dockerized Host
garciadeblasf4ebaa82022-06-23 13:33:26 +020047 [Arguments] ${env_host}
48 Set Suite Variable ${HOST} https://${env_host}
dhanasekaran6f0aed32022-05-17 14:12:40 +020049
50Set Standalone Host
garciadeblasf4ebaa82022-06-23 13:33:26 +020051 [Arguments] ${env_host}
52 Set Suite Variable ${HOST} https://${env_host}:9999
dhanasekaran6f0aed32022-05-17 14:12:40 +020053
54Read Directory
garciadeblasf4ebaa82022-06-23 13:33:26 +020055 [Documentation] To Read Current Direct ory
56 ${Directory}= Replace String ${CURDIR} lib resources/
57 ${json_path}= Set Variable ${Directory}
58 [Return] ${JsonPath}
dhanasekaran6f0aed32022-05-17 14:12:40 +020059
60Post Api Request
61 [Arguments] ${PostApi}
garciadeblasf4ebaa82022-06-23 13:33:26 +020062 [Documentation] Keword to Post API Request
63 Create Session APISession ${HOST}
64 &{headers} Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${access_token}
65 ${request_response}= Post On Session APISession ${PostApi} json=${updated_json_obj} headers=${headers}
66 Set Suite Variable ${request_response}
67 ${response_statuscode} Convert To String ${request_response.status_code}
68 Set Suite Variable ${response_statuscode}
dhanasekaran6f0aed32022-05-17 14:12:40 +020069
garciadeblas68eac4a2023-06-27 11:21:05 +020070Get Hostname
garciadeblasf4ebaa82022-06-23 13:33:26 +020071 [Documentation] Keyword to get the default osm Hostname
72 ${nbi_host}= Get Environment Variable OSM_HOSTNAME
73 ${passed}= Run Keyword And Return Status Should Contain ${nbi_host} :
74 Run Keyword If ${passed} Set Dockerized Host ${nbi_host}
75 ... ELSE Set Standalone Host ${nbi_host}
dhanasekaran6f0aed32022-05-17 14:12:40 +020076
77Get ID
garciadeblasf4ebaa82022-06-23 13:33:26 +020078 [Arguments] ${Key}
79 Pass Execution If ${request_response.status_code} in ${success_status_code_list} Get Auth Token completed
80 ${id}= Get Value From Json ${request_response.json()} $..${Key}
81 Set Suite Variable ${value} ${id[0]}
82 [Return] ${value}
dhanasekaran6f0aed32022-05-17 14:12:40 +020083
84Update Json Value
garciadeblasf4ebaa82022-06-23 13:33:26 +020085 [Arguments] ${JsonInput} ${key}
86 ${json_path}= Read Directory
87 ${json_obj}= Load JSON From File ${json_path}/${JsonInput}
garciadeblas43f34482023-02-23 17:37:47 +010088 ${updated_json_obj}= JSONLibrary.Update Value To Json ${json_obj} $..${key} ${created_vim_account_id}
garciadeblasf4ebaa82022-06-23 13:33:26 +020089 Set Suite Variable ${updated_json_obj}
dhanasekaran6f0aed32022-05-17 14:12:40 +020090
91Get Api Request
garciadeblasf4ebaa82022-06-23 13:33:26 +020092 [Arguments] ${uri}
93 [Documentation] Keyword to Get API Request
94 Create Session Session ${HOST}
95 &{headers} Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${access_token}
96 ${request_response}= Get On Session Session ${uri} headers=${Headers}
97 Set Suite Variable ${request_response}
98 ${response_statuscode} Convert To String ${request_response.status_code}
99 Set Suite Variable ${response_statuscode}