Feature 10915: SOL003 STD Support for OSM - Robot Support
[osm/tests.git] / robot-systest / lib / sol003_common_lib.robot
1 #   Licensed under the Apache License, Version 2.0 (the "License");\r
2 #   you may not use this file except in compliance with the License.\r
3 #   You may obtain a copy of the License at\r
4 #\r
5 #       http://www.apache.org/licenses/LICENSE-2.0\r
6 #\r
7 #   Unless required by applicable law or agreed to in writing, software\r
8 #   distributed under the License is distributed on an "AS IS" BASIS,\r
9 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
10 #   See the License for the specific language governing permissions and\r
11 #   limitations under the License\r
12 \r
13 *** Settings ***\r
14 Documentation     Library with sol003 keywords and variables .\r
15 \r
16 Library           RequestsLibrary\r
17 Library           HttpLibrary.HTTP\r
18 Library           JsonValidator\r
19 Library           yaml\r
20 Library           JSONLibrary\r
21 Library           String\r
22 Library           OperatingSystem\r
23 Resource          %{ROBOT_DEVOPS_FOLDER}/lib/vim_lib.robot\r
24 Variables         %{ROBOT_DEVOPS_FOLDER}/resources/basic_01-crud_operations_on_vim_targets_data.py\r
25 \r
26 *** Variables ***\r
27 &{HEADERS}        Content-Type=application/json    Accept=application/json\r
28 &{data}           username=admin    password=admin    project-id=admin\r
29 @{success_status_code_list}    200    201    202    204\r
30 ${descriptor_content_type_gzip}    application/gzip\r
31 ${auth_token_uri}    /osm/admin/v1/tokens\r
32 ${HOST}           ${EMPTY}\r
33 ${vnf_instance_uri}    /osm/vnflcm/v1/vnf_instances\r
34 ${vnf_instantiate_uri}    /osm/vnflcm/v1/vnf_instances\r
35 ${vnf_instance_lcm_ops}    /osm/vnflcm/v1/vnf_lcm_op_occs\r
36 \r
37 *** Keywords ***\r
38 Get Auth Token\r
39     [Tags]    auth_token\r
40     Get Hostname\r
41     Create Session    osmhit    ${HOST}    verify=${FALSE}    debug=1    data=${data}    headers=${HEADERS}\r
42     Log Many    ${auth_token_uri}    @{data}    ${data}\r
43     ${resp}=    Post Request    osmhit    ${auth_token_uri}    data=${data}\r
44     log    ${resp}\r
45     Pass Execution If    ${resp.status_code} in ${success_status_code_list}    Get Auth Token completed\r
46     Set Suite Variable    ${token_status_code}    ${resp.status_code}\r
47     ${access_token}=    Get Value From Json    ${resp.json()}    $..id\r
48     Set Suite Variable    ${access_token}    ${access_token[0]}\r
49     Set Suite Variable    ${token_response}    ${resp}\r
50     sleep    2s\r
51 \r
52 Set Dockerized Host\r
53     [Arguments]    ${env_host}\r
54     Set Suite Variable    ${HOST}    https://${env_host}\r
55 \r
56 Set Standalone Host\r
57     [Arguments]    ${env_host}\r
58     Set Suite Variable    ${HOST}    https://${env_host}:9999\r
59 \r
60 Create VIM\r
61     [Documentation]    Create a VIM Target only with the mandatory parameters.\r
62     Pass Execution If    '${vim_account_type}' != 'openstack'    Not applicable for ${vim_account_type} VIM\r
63     ${rand}=    Generate Random String    6    [NUMBERS]\r
64     ${vim_name}=    Catenate    SEPARATOR=_    ${vim_name_prefix}    ${rand}\r
65     Set Suite Variable    ${vim_name}\r
66     ${created_vim_account_id}=    Create VIM Target    ${vim_name}    ${vim_user}    ${vim_password}    ${vim_auth_url}    ${vim_tenant}\r
67     ...    ${vim_account_type}\r
68     Set Suite Variable    ${created_vim_account_id}\r
69     Check VIM Target Operational State    ${vim_name}\r
70 \r
71 Read Directory\r
72     [Documentation]    To Read Current Direct ory\r
73     ${Directory}=    Replace String    ${CURDIR}    testsuite    \\resources/\r
74     ${json_path}=    Set Variable    ${Directory}\r
75     [Return]    ${JsonPath}\r
76 \r
77 Post Api Request\r
78     [Arguments]   ${PostApi}\r
79     [Documentation]    Keword to Post API Request\r
80     Create Session    APISession    ${HOST}\r
81     &{headers}    Create Dictionary    Content-Type=application/json    Accept=application/json    Authorization=Bearer ${access_token}\r
82     ${request_response}=    Post Request    APISession    ${PostApi}    data=${updated_json_obj}    headers=${headers}\r
83     Set Suite Variable    ${request_response}\r
84     ${response_statuscode}    Convert To String    ${request_response.status_code}\r
85     Set Suite Variable    ${response_statuscode}\r
86 \r
87 Get HostName\r
88     [Documentation]    Keyword to get the default osm Hostname\r
89     ${nbi_host}=    Get Environment Variable    OSM_HOSTNAME\r
90     ${passed}=    Run Keyword And Return Status    Should Contain    ${nbi_host}    :\r
91     Run Keyword If    ${passed}    Set Dockerized Host    ${nbi_host}\r
92     ...    ELSE    Set Standalone Host    ${nbi_host}\r
93 \r
94 Get ID\r
95     [Arguments]    ${Key}\r
96     Pass Execution If    ${request_response.status_code} in ${success_status_code_list}    Get Auth Token completed\r
97     ${id}=    Get Value From Json    ${request_response.json()}    $..${Key}\r
98     Set Suite Variable    ${value}    ${id[0]}\r
99     [Return]    ${value}\r
100 \r
101 Update Json Value\r
102     [Arguments]    ${JsonInput}    ${key}\r
103     ${json_path}=    Read Directory\r
104     ${json_obj}=    Load JSON From File    ${json_path}/${JsonInput}\r
105     ${updated_json_obj}    JSONLibrary.Update Value To Json    ${json_obj}    $..${key}    ${created_vim_account_id}\r
106     Set Suite Variable    ${updated_json_obj}\r
107 \r
108 Get Api Request\r
109     [Arguments]    ${uri}\r
110     [Documentation]    Keyword to Get API Request\r
111     Create Session    Session    ${HOST}\r
112     &{headers}    Create Dictionary    Content-Type=application/json    Accept=application/json    Authorization=Bearer ${access_token}\r
113     ${request_response}=    Get Request    Session    ${uri}    headers=${Headers}\r
114     Set Suite Variable    ${request_response}\r
115     ${response_statuscode}    Convert To String    ${request_response.status_code}\r
116     Set Suite Variable    ${response_statuscode}\r