| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 1 | # 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 *** |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 14 | Documentation Library with sol003 keywords and variables . |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 15 | |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 16 | Library RequestsLibrary |
| 17 | Library JsonValidator |
| 18 | Library yaml |
| 19 | Library JSONLibrary |
| 20 | Library String |
| 21 | Library OperatingSystem |
| garciadeblas | a351dd2 | 2023-06-27 12:07:08 +0200 | [diff] [blame^] | 22 | |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 23 | Resource %{ROBOT_DEVOPS_FOLDER}/lib/vim_lib.robot |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 24 | |
| 25 | *** Variables *** |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 26 | @{success_status_code_list} 200 201 202 204 |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 27 | ${auth_token_uri} /osm/admin/v1/tokens |
| 28 | ${HOST} ${EMPTY} |
| garciadeblas | a351dd2 | 2023-06-27 12:07:08 +0200 | [diff] [blame^] | 29 | ${osm_user} %{OSM_USER=admin} |
| 30 | ${osm_password} %{OSM_PASSWORD=admin} |
| 31 | ${osm_project} %{OSM_PROJECT=admin} |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 32 | |
| 33 | *** Keywords *** |
| 34 | Get Auth Token |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 35 | [Tags] auth_token |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 36 | Get Hostname |
| garciadeblas | 43f3448 | 2023-02-23 17:37:47 +0100 | [diff] [blame] | 37 | Create Session osmhit ${HOST} disable_warnings=1 |
| dhanasekaran | d90c14a | 2022-06-21 07:19:17 +0000 | [diff] [blame] | 38 | &{headers} Create Dictionary Content-Type=application/json Accept=application/json |
| Guillermo Calvino | b3d11c0 | 2022-11-22 13:34:31 +0100 | [diff] [blame] | 39 | &{data} Create Dictionary username=${osm_user} password=${osm_password} project-id=${osm_project} |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 40 | ${resp}= Post On Session osmhit ${auth_token_uri} json=${data} headers=${headers} |
| garciadeblas | 321726f | 2022-12-21 11:43:06 +0100 | [diff] [blame] | 41 | Log ${resp} |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 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 |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 48 | |
| 49 | Set Dockerized Host |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 50 | [Arguments] ${env_host} |
| 51 | Set Suite Variable ${HOST} https://${env_host} |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 52 | |
| 53 | Set Standalone Host |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 54 | [Arguments] ${env_host} |
| 55 | Set Suite Variable ${HOST} https://${env_host}:9999 |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 56 | |
| 57 | Read Directory |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 58 | [Documentation] To Read Current Direct ory |
| 59 | ${Directory}= Replace String ${CURDIR} lib resources/ |
| 60 | ${json_path}= Set Variable ${Directory} |
| 61 | [Return] ${JsonPath} |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 62 | |
| 63 | Post Api Request |
| 64 | [Arguments] ${PostApi} |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 65 | [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} |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 72 | |
| garciadeblas | 68eac4a | 2023-06-27 11:21:05 +0200 | [diff] [blame] | 73 | Get Hostname |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 74 | [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} |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 79 | |
| 80 | Get ID |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 81 | [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} |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 86 | |
| dhanasekaran | 6f0aed3 | 2022-05-17 14:12:40 +0200 | [diff] [blame] | 87 | Get Api Request |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 88 | [Arguments] ${uri} |
| 89 | [Documentation] Keyword to Get API Request |
| 90 | Create Session Session ${HOST} |
| 91 | &{headers} Create Dictionary Content-Type=application/json Accept=application/json Authorization=Bearer ${access_token} |
| 92 | ${request_response}= Get On Session Session ${uri} headers=${Headers} |
| 93 | Set Suite Variable ${request_response} |
| 94 | ${response_statuscode} Convert To String ${request_response.status_code} |
| 95 | Set Suite Variable ${response_statuscode} |