remove some global variables
[testsuite.git] / robot / resources / sdngc_interface.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with SDN-GC. It handles low level stuff like managing the http request library and SDN-GC required fields
3 Library               RequestsLibrary
4 Library           ONAPLibrary.Utilities
5 Library             SeleniumLibrary
6 Library        OperatingSystem
7 Library         Collections
8 Library      String
9 Library           ONAPLibrary.ServiceMapping    WITH NAME     ServiceMapping
10 Library           ONAPLibrary.PreloadData    WITH NAME     Preload
11 Library           ONAPLibrary.Templating
12 Library           ONAPLibrary.SDNC
13 Resource          global_properties.robot
14 Resource        browser_setup.robot
15
16
17 *** Variables ***
18 ${PRELOAD_VNF_TOPOLOGY_OPERATION_PATH}  /operations/VNF-API:preload-vnf-topology-operation
19 ${PRELOAD_NETWORK_TOPOLOGY_OPERATION_PATH}  /operations/VNF-API:preload-network-topology-operation
20 ${PRELOAD_GR_TOPOLOGY_OPERATION_PATH}     /operations/GENERIC-RESOURCE-API:preload-vf-module-topology-operation
21 ${PRELOAD_VNF_CONFIG_PATH}  /config/VNF-API:preload-vnfs/vnf-preload-list
22 ${PRELOAD_TOPOLOGY_OPERATION_BODY}  sdnc
23 ${SDNGC_INDEX_PATH}    /restconf
24 ${SDNCGC_HEALTHCHECK_OPERATION_PATH}  /operations/SLI-API:healthcheck
25 ${SDNGC_REST_ENDPOINT}    ${GLOBAL_SDNGC_SERVER_PROTOCOL}://${GLOBAL_INJECTED_SDNC_IP_ADDR}:${GLOBAL_SDNGC_REST_PORT}
26 ${SDNGC_ADMIN_ENDPOINT}    ${GLOBAL_SDNGC_SERVER_PROTOCOL}://${GLOBAL_INJECTED_SDNC_PORTAL_IP_ADDR}:${GLOBAL_SDNGC_ADMIN_PORT}
27 ${SDNGC_ADMIN_SIGNUP_URL}    ${SDNGC_ADMIN_ENDPOINT}/signup
28 ${SDNGC_ADMIN_LOGIN_URL}    ${SDNGC_ADMIN_ENDPOINT}/login
29 ${SDNGC_ADMIN_VNF_PROFILE_URL}    ${SDNGC_ADMIN_ENDPOINT}/mobility/getVnfProfile
30 ${VNF_KEYPAIR_SSH_KEY}    robot/assets/keys/onap_dev_public.txt
31
32 *** Keywords ***
33 Run SDNGC Health Check
34     [Documentation]    Runs an SDNGC healthcheck
35     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
36     ${resp}=    Run Post Request        ${SDNGC_REST_ENDPOINT}  ${SDNGC_INDEX PATH}${SDNCGC_HEALTHCHECK_OPERATION_PATH}     data=${None}    auth=${auth}
37     Should Be Equal As Strings  ${resp.status_code}     200
38     Should Be Equal As Strings  ${resp.json()['output']['response-code']}       200
39
40 Preload Vcpe Networks
41     Preload Network    cpe_public    10.2.0.2    10.2.0.1
42     Preload Network    cpe_signal    10.4.0.2    10.4.0.1
43     Preload Network    brg_bng    10.3.0.2    10.3.0.1
44     Preload Network    bng_mux    10.1.0.10    10.1.0.1
45     Preload Network    mux_gw    10.5.0.10    10.5.0.1
46
47 Preload Network
48     [Arguments]    ${network_role}     ${subnet_start_ip}    ${subnet_gateway}
49     ${name_suffix}=    Generate Timestamp
50     ${network_name}=     Catenate    SEPARATOR=_    net     ${network_role}         ${name_suffix}
51     ${subnet_name}=     Catenate    SEPARATOR=_    net      ${network_role}         subnet    ${name_suffix}
52     ${parameters}=     Create Dictionary    network_role=${network_role}    service_type=vCPE    network_type=Generic NeutronNet    network_name=${network_name}    subnet_start_ip=${subnet_start_ip}    subnet_gateway=${subnet_gateway}
53     Create Environment    sdnc    ${GLOBAL_TEMPLATE_FOLDER}
54     ${data}=   Apply Template    sdnc   ${PRELOAD_TOPOLOGY_OPERATION_BODY}/template.network.jinja   ${parameters}
55     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
56     ${post_resp}=       Run Post Request        ${SDNGC_REST_ENDPOINT}  ${SDNGC_INDEX_PATH}${PRELOAD_NETWORK_TOPOLOGY_OPERATION_PATH}     data=${data}    auth=${auth}
57     [Return]    ${network_name}   ${subnet_name}
58
59 Preload Vcpe vGW
60     [Arguments]    ${brg_mac}    ${cpe_network_name}   ${cpe_subnet_name}    ${mux_gw_net}    ${mux_gw_subnet}
61     ${name_suffix}=    Generate Timestamp
62     ${ssh_key}=    OperatingSystem.Get File     ${VNF_KEYPAIR_SSH_KEY}
63     ${parameters}=     Create Dictionary    pub_key=${ssh_key}    brg_mac=${brg_mac}    cpe_public_net=${cpe_network_name}     cpe_public_subnet=${cpe_subnet_name}    mux_gw_net=${mux_gw_net} mux_gw_subnet=${mux_gw_subnet}    suffix=${name_suffix}    oam_onap_net=oam_network_2No2        oam_onap_subnet=oam_network_2No2        public_net_id=${GLOBAL_INJECTED_PUBLIC_NET_ID}
64     Create Environment    sdnc    ${GLOBAL_TEMPLATE_FOLDER}
65     ${data}=   Apply Template    sdnc   ${PRELOAD_TOPOLOGY_OPERATION_BODY}/template.vcpe_vgw_vfmodule.jinja   ${parameters}
66     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
67     ${post_resp}=       Run Post Request        ${SDNGC_REST_ENDPOINT}  ${SDNGC_INDEX_PATH}${PRELOAD_VNF_TOPOLOGY_OPERATION_PATH}     data=${data}    auth=${auth}
68
69 Preload Vcpe vGW Gra
70     [Arguments]    ${brg_mac}   ${cpe_public_network_name}   ${cpe_public_subnet_name}    ${mux_gw_net}    ${mux_gw_subnet}
71     ${name_suffix}=    Generate Timestamp
72     ${ssh_key}=    OperatingSystem.Get File     ${VNF_KEYPAIR_SSH_KEY}
73     ${parameters}=     Create Dictionary    pub_key=${ssh_key}    brg_mac=${brg_mac}    cpe_public_net=${cpe_public_network_name}     cpe_public_subnet=${cpe_public_subnet_name}    mux_gw_net=${mux_gw_net}   mux_gw_subnet=${mux_gw_subnet}    suffix=${name_suffix}    oam_onap_net=oam_network_2No2        oam_onap_subnet=oam_network_2No2        public_net_id=${GLOBAL_INJECTED_PUBLIC_NET_ID}
74     Create Environment    sdnc    ${GLOBAL_TEMPLATE_FOLDER}
75     ${data}=   Apply Template    sdnc   ${PRELOAD_TOPOLOGY_OPERATION_BODY}/template.vcpe_gwgra_vfmodule.jinja   ${parameters}
76     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
77     ${post_resp}=       Run Post Request        ${SDNGC_REST_ENDPOINT}  ${SDNGC_INDEX_PATH}${PRELOAD_GR_TOPOLOGY_OPERATION_PATH}     data=${data}    auth=${auth}
78
79 Preload Generic VfModule
80     [Arguments]    ${service_instance_id}       ${vnf_model}   ${model_customization_name}    ${short_model_customization_name}     ${cpe_public_network_name}=None   ${cpe_public_subnet_name}=None   ${cpe_signal_network_name}=None   ${cpe_signal_subnet_name}=None
81     ${name_suffix}=    Generate Timestamp
82     ${ssh_key}=    OperatingSystem.Get File     ${VNF_KEYPAIR_SSH_KEY}
83     ${vfmodule_name}=     Catenate    SEPARATOR=_    vf     ${short_model_customization_name}       ${name_suffix}
84     #TODO this became a mess, need to fix
85     ${parameters}=     Create Dictionary    pub_key=${ssh_key}    suffix=${name_suffix}    mr_ip_addr=${GLOBAL_INJECTED_MR_IP_ADDR}    mr_ip_port=${GLOBAL_MR_SERVER_PORT}
86     Set To Dictionary    ${parameters}    oam_onap_net=oam_network_2No2        oam_onap_subnet=oam_network_2No2    cpe_public_net=${cpe_public_network_name}     cpe_public_subnet=${cpe_public_subnet_name}    
87     Set To Dictionary    ${parameters}    cpe_signal_subnet=${cpe_signal_subnet_name}    cpe_signal_net=${cpe_signal_network_name}    public_net_id=${GLOBAL_INJECTED_PUBLIC_NET_ID}
88     # vnf_type and generic_vnf_type are identical
89     Set To Dictionary    ${parameters}    vnf_type=${model_customization_name}    generic_vnf_type=${model_customization_name}    generic_vnf_name=${model_customization_name}    vnf_name=${vfmodule_name}    
90     Set To Dictionary    ${parameters}    service_type=${service_instance_id}    sdnc_oam_ip=${GLOBAL_INJECTED_SDNC_IP_ADDR}
91         ${post_resp}=    Preload Vfmodule    ${SDNGC_REST_ENDPOINT}    ${SDNGC_INDEX_PATH}${PRELOAD_VNF_TOPOLOGY_OPERATION_PATH}    ${GLOBAL_TEMPLATE_FOLDER}    ${PRELOAD_TOPOLOGY_OPERATION_BODY}/template.vcpe_infra_vfmodule.jinja    ${parameters}
92     [Return]    ${post_resp}
93             
94 Preload Vnf
95     [Arguments]    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}     ${vf_module_name}    ${vf_modules}    ${service}   ${uuid}
96     ${base_vf_module_type}=    Catenate
97     ${closedloop_vf_module}=    Create Dictionary
98     ServiceMapping.Set Directory    default    ./demo/service_mapping
99     ${templates}=    Get Service Template Mapping    default    ${service}    ${generic_vnf_type}
100     :FOR    ${vf_module}    IN      @{vf_modules}
101     \       ${vf_module_type}=    Get From Dictionary    ${vf_module}    name
102     #     need to pass in vnf_index if non-zero
103     \       ${dict}   Run Keyword If    "${generic_vnf_name}".endswith('0')      Get From Mapping With Index    ${templates}    ${vf_module}   0
104     \       ...    ELSE IF  "${generic_vnf_name}".endswith('1')      Get From Mapping With Index    ${templates}    ${vf_module}   1
105     \       ...    ELSE IF  "${generic_vnf_name}".endswith('2')      Get From Mapping With Index    ${templates}    ${vf_module}   2
106     \       ...    ELSE   Get From Mapping    ${templates}    ${vf_module}
107     #     skip this iteration if no template 
108     \       ${test_dict_length} =  Get Length  ${dict}
109     \       Continue For Loop If   ${test_dict_length} == 0
110     \       ${filename}=    Get From Dictionary    ${dict}    template
111     \       ${base_vf_module_type}=   Set Variable If    '${dict['isBase']}' == 'true'     ${vf_module_type}    ${base_vf_module_type}
112     \       ${closedloop_vf_module}=   Set Variable If    '${dict['isBase']}' == 'false'     ${vf_module}    ${closedloop_vf_module}
113     \       ${vf_name}=     Update Module Name    ${dict}    ${vf_module_name}
114     #    Admin portal update no longer 
115     #\       Preload Vnf Profile    ${vf_module_type}
116     \       Preload One Vnf Topology    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}     ${vf_name}    ${vf_module_type}    ${service}    ${filename}   ${uuid}
117     [Return]    ${base_vf_module_type}   ${closedloop_vf_module}
118
119 Update Module Name
120     [Arguments]    ${dict}    ${vf_module_name}
121     Return From Keyword If    'prefix' not in ${dict}    ${vf_module_name}
122     Return From Keyword If    '${dict['prefix']}' == ''    ${vf_module_name}
123     ${name}=    Replace String   ${vf_module_name}   Vfmodule_    ${dict['prefix']}
124     [Return]    ${name}
125
126 Get From Mapping With Index
127     [Documentation]    Retrieve the appropriate prelad template entry for the passed vf_module
128     [Arguments]    ${templates}    ${vf_module}   ${vnf_index}=0
129     ${vf_module_name}=    Get From DIctionary    ${vf_module}    name
130     :FOR    ${template}   IN   @{templates}
131     \    Return From Keyword If    '${template['name_pattern']}' in '${vf_module_name}' and ('${template['vnf_index']}' == '${vnf_index}')     ${template}
132     ${result}=    Create Dictionary
133     [Return]    ${result}
134
135 Get From Mapping
136     [Documentation]    Retrieve the appropriate prelad template entry for the passed vf_module
137     [Arguments]    ${templates}    ${vf_module}
138     ${vf_module_name}=    Get From DIctionary    ${vf_module}    name
139     :FOR    ${template}   IN   @{templates}
140     \    Return From Keyword If    '${template['name_pattern']}' in '${vf_module_name}'     ${template}
141     ${result}=    Create Dictionary
142     [Return]    ${result}
143
144 Preload One Vnf Topology
145     [Arguments]    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}       ${vf_module_name}    ${vf_module_type}    ${service}    ${filename}   ${uuid}
146     Return From Keyword If    '${filename}' == ''
147     ${parameters}=    Get Template Parameters    ${generic_vnf_name}    ${filename}   ${uuid}    ${service}
148     Set To Dictionary   ${parameters}   generic_vnf_name=${generic_vnf_name}     generic_vnf_type=${generic_vnf_type}  service_type=${service_type_uuid}    vf_module_name=${vf_module_name}    vf_module_type=${vf_module_type}
149     Create Environment    sdnc    ${GLOBAL_TEMPLATE_FOLDER}
150     ${data}=   Apply Template    sdnc   ${PRELOAD_TOPOLOGY_OPERATION_BODY}/preload.jinja    ${parameters}
151     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
152     ${post_resp}=       Run Post Request        ${SDNGC_REST_ENDPOINT}  ${SDNGC_INDEX_PATH}${PRELOAD_VNF_TOPOLOGY_OPERATION_PATH}     data=${data}    auth=${auth}
153     Should Be Equal As Strings  ${post_resp.json()['output']['response-code']}  200
154     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
155     ${get_resp}=        Run Get Request         ${SDNGC_REST_ENDPOINT}    ${SDNGC_INDEX_PATH}${PRELOAD_VNF_CONFIG_PATH}/${vf_module_name}/${vf_module_type}     auth=${auth}
156
157 Get Template Parameters
158     [Arguments]   ${generic_vnf_name}    ${template}    ${uuid}    ${service}
159     ${uuid}=    Catenate    ${uuid}
160     ${hostid}=    Get Substring    ${uuid}    -4
161     ${ecompnet}=    Evaluate    (${GLOBAL_BUILD_NUMBER}%128)+128
162
163
164     # Initialize the value map with the properties generated from the Robot VM /opt/config folder
165     ${valuemap}=   Copy Dictionary    ${GLOBAL_INJECTED_PROPERTIES}
166
167     # These should be deprecated by the above....
168     Set To Dictionary   ${valuemap}   artifacts_version=${GLOBAL_INJECTED_ARTIFACTS_VERSION}
169     Set To Dictionary   ${valuemap}   network=${GLOBAL_INJECTED_NETWORK}
170     Set To Dictionary   ${valuemap}   public_net_id=${GLOBAL_INJECTED_PUBLIC_NET_ID}
171     Set To Dictionary   ${valuemap}   cloud_env=${GLOBAL_INJECTED_CLOUD_ENV}
172     Set To Dictionary   ${valuemap}   install_script_version=${GLOBAL_INJECTED_SCRIPT_VERSION}
173     Set To Dictionary   ${valuemap}   vm_image_name=${GLOBAL_INJECTED_VM_IMAGE_NAME}
174     Set To Dictionary   ${valuemap}   vm_flavor_name=${GLOBAL_INJECTED_VM_FLAVOR}
175
176
177     # update the value map with unique values.
178     Set To Dictionary   ${valuemap}   uuid=${uuid}   hostid=${hostid}    ecompnet=${ecompnet}    generic_vnf_name=${generic_vnf_name}
179
180     #
181     # Mash together the defaults dict with the test case dict to create the set of
182     # preload parameters
183     #
184     Preload.Set Directory    preload    ./demo/preload_data
185     ${defaults}=       Get Default Preload Data    preload
186     ${template}=    Get Preload Data    preload    ${service}    ${template}
187     # add all of the defaults to template...
188     @{keys}=    Get Dictionary Keys    ${defaults}
189     :FOR   ${key}   IN   @{keys}
190     \    ${value}=   Get From Dictionary    ${defaults}    ${key}
191     \    Set To Dictionary    ${template}  ${key}    ${value}
192
193     #
194     # Get the vnf_parameters to preload
195     #
196     ${vnf_parameters}=   Resolve VNF Parameters Into Array   ${valuemap}   ${template}
197     ${vnf_parameters_json}=   Evaluate    json.dumps(${vnf_parameters})    json
198     ${parameters}=   Create Dictionary   vnf_parameters=${vnf_parameters_json}
199     [Return]    ${parameters}
200
201 Resolve VNF Parameters Into Array
202     [Arguments]   ${valuemap}    ${from}
203     ${vnf_parameters}=   Create List
204     ${keys}=    Get Dictionary Keys    ${from}
205     :FOR   ${key}   IN  @{keys}
206     \    ${value}=    Get From Dictionary    ${from}   ${key}
207     \    ${value}=    Template String    ${value}    ${valuemap}
208     \    ${parameter}=   Create Dictionary   vnf-parameter-name=${key}    vnf-parameter-value=${value}
209     \    Append To List    ${vnf_parameters}   ${parameter}
210     [Return]   ${vnf_parameters}
211
212 Preload Vnf Profile
213     [Arguments]    ${vnf_name}
214     Login To SDNGC Admin GUI
215     Go To    ${SDNGC_ADMIN_VNF_PROFILE_URL}
216     Click Button    xpath=//button[@data-target='#add_vnf_profile']
217     Input Text    xpath=//input[@id='nf_vnf_type']    ${vnf_name}
218     Input Text    xpath=//input[@id='nf_availability_zone_count']    999
219     Input Text    xpath=//input[@id='nf_equipment_role']    robot-ete-test
220     Click Button    xpath=//button[contains(.,'Submit')]
221     Page Should Contain  VNF Profile
222     Input Text    xpath=//div[@id='vnf_profile_filter']//input    ${vnf_name}
223     Page Should Contain  ${vnf_name}
224
225 Delete Vnf Profile
226     [Arguments]    ${vnf_name}
227     Login To SDNGC Admin GUI
228     Go To    ${SDNGC_ADMIN_VNF_PROFILE_URL}
229     Page Should Contain  VNF Profile
230     Input Text    xpath=//div[@id='vnf_profile_filter']//input    ${vnf_name}
231     Page Should Contain  ${vnf_name}
232     Click Button    xpath=//button[contains(@onclick, '${vnf_name}')]
233     Page Should Contain    Are you sure you want to delete VNF_PROFILE
234     Click Button    xpath=//button[contains(text(), 'Yes')]
235     Page Should Not Contain  ${vnf_name}
236
237 Login To SDNGC Admin GUI
238     [Documentation]   Login To SDNGC Admin GUI
239     ## Setup Browser is now being managed by the test case
240     ## Setup Browser
241     Go To    ${SDNGC_ADMIN_SIGNUP_URL}
242     ##Maximize Browser Window
243     Set Selenium Speed    ${GLOBAL_SELENIUM_DELAY}
244     Set Browser Implicit Wait    ${GLOBAL_SELENIUM_BROWSER_IMPLICIT_WAIT}
245     Log    Logging in to ${SDNGC_ADMIN_LOGIN_URL}
246     Handle Proxy Warning
247     Title Should Be    AdminPortal
248     ${uuid}=    Generate UUID4
249     ${shortened_uuid}=     Evaluate    str("${uuid}")[:12]
250     ${email}=        Catenate    ${shortened_uuid}@robotete.com
251     Input Text    xpath=//input[@id='nf_email']    ${email}
252     Input Password    xpath=//input[@id='nf_password']    ${shortened_uuid}
253     Click Button    xpath=//button[@type='submit']
254     Wait Until Page Contains    User created   20s
255     Go To    ${SDNGC_ADMIN_LOGIN_URL}
256     Input Text    xpath=//input[@id='email']    ${email}
257     Input Password    xpath=//input[@id='password']    ${shortened_uuid}
258     Click Button    xpath=//button[@type='submit']
259     Title Should Be    SDN-C AdminPortal
260     Log    Logged in to ${SDNGC_ADMIN_LOGIN_URL}