blob: 6617e91ac2100b83d12161b1d9faad6e1e243034 [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
dhanasekaran6f0aed32022-05-17 14:12:40 +020023
24*** Variables ***
garciadeblasf4ebaa82022-06-23 13:33:26 +020025@{success_status_code_list} 200 201 202 204
26${descriptor_content_type_gzip} application/gzip
27${auth_token_uri} /osm/admin/v1/tokens
28${HOST} ${EMPTY}
29${vnf_instance_uri} /osm/vnflcm/v1/vnf_instances
30${vnf_instantiate_uri} /osm/vnflcm/v1/vnf_instances
31${vnf_instance_lcm_ops} /osm/vnflcm/v1/vnf_lcm_op_occs
dhanasekaran6f0aed32022-05-17 14:12:40 +020032
33*** Keywords ***
34Get Auth Token
garciadeblasf4ebaa82022-06-23 13:33:26 +020035 [Tags] auth_token
dhanasekaran6f0aed32022-05-17 14:12:40 +020036 Get Hostname
garciadeblasf4ebaa82022-06-23 13:33:26 +020037 Create Session osmhit ${HOST}
dhanasekarand90c14a2022-06-21 07:19:17 +000038 &{headers} Create Dictionary Content-Type=application/json Accept=application/json
garciadeblasf4ebaa82022-06-23 13:33:26 +020039 &{data} Create Dictionary username=admin password=admin project-id=admin
40 ${resp}= Post On Session osmhit ${auth_token_uri} json=${data} headers=${headers}
41 log ${resp}
42 Pass Execution If ${resp.status_code} in ${success_status_code_list} Get Auth Token completed
43 Set Suite Variable ${token_status_code} ${resp.status_code}
44 ${access_token}= Get Value From Json ${resp.json()} $..id
45 Set Test Variable ${access_token} ${access_token[0]}
46 Set Test Variable ${token_response} ${resp}
47 sleep 2s
dhanasekaran6f0aed32022-05-17 14:12:40 +020048
49Set Dockerized Host
garciadeblasf4ebaa82022-06-23 13:33:26 +020050 [Arguments] ${env_host}
51 Set Suite Variable ${HOST} https://${env_host}
dhanasekaran6f0aed32022-05-17 14:12:40 +020052
53Set Standalone Host
garciadeblasf4ebaa82022-06-23 13:33:26 +020054 [Arguments] ${env_host}
55 Set Suite Variable ${HOST} https://${env_host}:9999
dhanasekaran6f0aed32022-05-17 14:12:40 +020056
57Read Directory
garciadeblasf4ebaa82022-06-23 13:33:26 +020058 [Documentation] To Read Current Direct ory
59 ${Directory}= Replace String ${CURDIR} lib resources/
60 ${json_path}= Set Variable ${Directory}
61 [Return] ${JsonPath}
dhanasekaran6f0aed32022-05-17 14:12:40 +020062
63Post Api Request
64 [Arguments] ${PostApi}
garciadeblasf4ebaa82022-06-23 13:33:26 +020065 [Documentation] Keword to Post API Request
66 Create Session APISession ${HOST}
67 &{headers} Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${access_token}
68 ${request_response}= Post On Session APISession ${PostApi} json=${updated_json_obj} headers=${headers}
69 Set Suite Variable ${request_response}
70 ${response_statuscode} Convert To String ${request_response.status_code}
71 Set Suite Variable ${response_statuscode}
dhanasekaran6f0aed32022-05-17 14:12:40 +020072
73Get HostName
garciadeblasf4ebaa82022-06-23 13:33:26 +020074 [Documentation] Keyword to get the default osm Hostname
75 ${nbi_host}= Get Environment Variable OSM_HOSTNAME
76 ${passed}= Run Keyword And Return Status Should Contain ${nbi_host} :
77 Run Keyword If ${passed} Set Dockerized Host ${nbi_host}
78 ... ELSE Set Standalone Host ${nbi_host}
dhanasekaran6f0aed32022-05-17 14:12:40 +020079
80Get ID
garciadeblasf4ebaa82022-06-23 13:33:26 +020081 [Arguments] ${Key}
82 Pass Execution If ${request_response.status_code} in ${success_status_code_list} Get Auth Token completed
83 ${id}= Get Value From Json ${request_response.json()} $..${Key}
84 Set Suite Variable ${value} ${id[0]}
85 [Return] ${value}
dhanasekaran6f0aed32022-05-17 14:12:40 +020086
87Update Json Value
garciadeblasf4ebaa82022-06-23 13:33:26 +020088 [Arguments] ${JsonInput} ${key}
89 ${json_path}= Read Directory
90 ${json_obj}= Load JSON From File ${json_path}/${JsonInput}
91 ${updated_json_obj} JSONLibrary.Update Value To Json ${json_obj} $..${key} ${created_vim_account_id}
92 Set Suite Variable ${updated_json_obj}
dhanasekaran6f0aed32022-05-17 14:12:40 +020093
94Get Api Request
garciadeblasf4ebaa82022-06-23 13:33:26 +020095 [Arguments] ${uri}
96 [Documentation] Keyword to Get API Request
97 Create Session Session ${HOST}
98 &{headers} Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${access_token}
99 ${request_response}= Get On Session Session ${uri} headers=${Headers}
100 Set Suite Variable ${request_response}
101 ${response_statuscode} Convert To String ${request_response.status_code}
102 Set Suite Variable ${response_statuscode}