removing servicemapping.py
[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           UUID
5 Library    OperatingSystem
6 Library             SeleniumLibrary
7 Library         Collections
8 Library      String
9 Library      StringTemplater
10 Library           ONAPLibrary.ServiceMapping
11
12 Resource          global_properties.robot
13 Resource          ../resources/json_templater.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_VNF_CONFIG_PATH}  /config/VNF-API:preload-vnfs/vnf-preload-list
20 ${PRELOAD_VNF_TOPOLOGY_OPERATION_BODY}  robot/assets/templates/sdnc/
21 ${SDNGC_INDEX_PATH}    /restconf
22 ${SDNCGC_HEALTHCHECK_OPERATION_PATH}  /operations/SLI-API:healthcheck
23 ${SDNGC_REST_ENDPOINT}    ${GLOBAL_SDNGC_SERVER_PROTOCOL}://${GLOBAL_INJECTED_SDNC_IP_ADDR}:${GLOBAL_SDNGC_REST_PORT}
24 ${SDNGC_ADMIN_ENDPOINT}    ${GLOBAL_SDNGC_SERVER_PROTOCOL}://${GLOBAL_INJECTED_SDNC_PORTAL_IP_ADDR}:${GLOBAL_SDNGC_ADMIN_PORT}
25 ${SDNGC_ADMIN_SIGNUP_URL}    ${SDNGC_ADMIN_ENDPOINT}/signup
26 ${SDNGC_ADMIN_LOGIN_URL}    ${SDNGC_ADMIN_ENDPOINT}/login
27 ${SDNGC_ADMIN_VNF_PROFILE_URL}    ${SDNGC_ADMIN_ENDPOINT}/mobility/getVnfProfile
28
29 *** Keywords ***
30 Run SDNGC Health Check
31     [Documentation]    Runs an SDNGC healthcheck
32         ${resp}=    Run SDNGC Post Request     ${SDNGC_INDEX PATH}${SDNCGC_HEALTHCHECK_OPERATION_PATH}     ${None}
33     Should Be Equal As Strings  ${resp.status_code}     200
34     Should Be Equal As Strings  ${resp.json()['output']['response-code']}       200
35
36 Run SDNGC Get Request
37     [Documentation]    Runs an SDNGC get request
38     [Arguments]    ${data_path}
39     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
40     Log    Creating session ${SDNGC_REST_ENDPOINT}
41     ${session}=    Create Session       sdngc   ${SDNGC_REST_ENDPOINT}    auth=${auth}
42     ${uuid}=    Generate UUID
43     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
44     ${resp}=    Get Request     sdngc   ${data_path}     headers=${headers}
45     Log    Received response from sdngc ${resp.text}
46     [Return]    ${resp}
47
48 Run SDNGC Put Request
49     [Documentation]    Runs an SDNGC put request
50     [Arguments]    ${data_path}    ${data}
51     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
52     Log    Creating session ${SDNGC_REST_ENDPOINT}
53     ${session}=    Create Session       sdngc   ${SDNGC_REST_ENDPOINT}    auth=${auth}
54     ${uuid}=    Generate UUID
55     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
56     ${resp}=    Put Request     sdngc   ${data_path}     data=${data}    headers=${headers}
57     Log    Received response from sdngc ${resp.text}
58     [Return]    ${resp}
59
60 Run SDNGC Post Request
61     [Documentation]    Runs an SDNGC post request
62     [Arguments]    ${data_path}    ${data}
63     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
64     Log    Creating session ${SDNGC_REST_ENDPOINT}
65     ${session}=    Create Session       sdngc   ${SDNGC_REST_ENDPOINT}    auth=${auth}
66     ${uuid}=    Generate UUID
67     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
68     ${resp}=    Post Request    sdngc   ${data_path}     data=${data}    headers=${headers}
69     Log    Received response from sdngc ${resp.text}
70     [Return]    ${resp}
71
72 Run SDNGC Delete Request
73     [Documentation]    Runs an SDNGC delete request
74     [Arguments]    ${data_path}
75     ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
76     Log    Creating session ${SDNGC_REST_ENDPOINT}
77     ${session}=    Create Session       sdngc   ${SDNGC_REST_ENDPOINT}    auth=${auth}
78     ${uuid}=    Generate UUID
79     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
80     ${resp}=    Delete Request  sdngc   ${data_path}        headers=${headers}
81     Log    Received response from sdngc ${resp.text}
82     [Return]    ${resp}
83
84
85 Preload Vnf
86     [Arguments]    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}     ${vf_module_name}    ${vf_modules}    ${service}   ${uuid}
87     ${base_vf_module_type}=    Catenate
88     ${closedloop_vf_module}=    Create Dictionary
89     Set Directory    default    ./demo/service_mapping
90     ${templates}=    Get Service Template Mapping    default    ${service}    ${generic_vnf_type}
91     :FOR    ${vf_module}    IN      @{vf_modules}
92     \       ${vf_module_type}=    Get From Dictionary    ${vf_module}    name
93     #     need to pass in vnf_index if non-zero
94     \       ${dict}   Run Keyword If    "${generic_vnf_name}".endswith('0')      Get From Mapping With Index    ${templates}    ${vf_module}   0
95     \       ...    ELSE IF  "${generic_vnf_name}".endswith('1')      Get From Mapping With Index    ${templates}    ${vf_module}   1
96     \       ...    ELSE IF  "${generic_vnf_name}".endswith('2')      Get From Mapping With Index    ${templates}    ${vf_module}   2
97     \       ...    ELSE   Get From Mapping    ${templates}    ${vf_module}
98     #     skip this iteration if no template 
99     \       ${test_dict_length} =  Get Length  ${dict}
100     \       Continue For Loop If   ${test_dict_length} == 0
101     \       ${filename}=    Get From Dictionary    ${dict}    template
102     \       ${base_vf_module_type}=   Set Variable If    '${dict['isBase']}' == 'true'     ${vf_module_type}    ${base_vf_module_type}
103     \       ${closedloop_vf_module}=   Set Variable If    '${dict['isBase']}' == 'false'     ${vf_module}    ${closedloop_vf_module}
104     \       ${vf_name}=     Update Module Name    ${dict}    ${vf_module_name}
105     #    Admin portal update no longer 
106     #\       Preload Vnf Profile    ${vf_module_type}
107     \       Preload One Vnf Topology    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}     ${vf_name}    ${vf_module_type}    ${service}    ${filename}   ${uuid}
108     [Return]    ${base_vf_module_type}   ${closedloop_vf_module}
109
110
111 Update Module Name
112     [Arguments]    ${dict}    ${vf_module_name}
113     Return From Keyword If    'prefix' not in ${dict}    ${vf_module_name}
114     Return From Keyword If    '${dict['prefix']}' == ''    ${vf_module_name}
115     ${name}=    Replace String   ${vf_module_name}   Vfmodule_    ${dict['prefix']}
116     [Return]    ${name}
117
118 Get From Mapping With Index
119     [Documentation]    Retrieve the appropriate prelad template entry for the passed vf_module
120     [Arguments]    ${templates}    ${vf_module}   ${vnf_index}=0
121     ${vf_module_name}=    Get From DIctionary    ${vf_module}    name
122     :FOR    ${template}   IN   @{templates}
123     \    Return From Keyword If    '${template['name_pattern']}' in '${vf_module_name}' and ('${template['vnf_index']}' == '${vnf_index}')     ${template}
124     ${result}=    Create Dictionary
125     [Return]    ${result}
126
127 Get From Mapping
128     [Documentation]    Retrieve the appropriate prelad template entry for the passed vf_module
129     [Arguments]    ${templates}    ${vf_module}
130     ${vf_module_name}=    Get From DIctionary    ${vf_module}    name
131     :FOR    ${template}   IN   @{templates}
132     \    Return From Keyword If    '${template['name_pattern']}' in '${vf_module_name}'     ${template}
133     ${result}=    Create Dictionary
134     [Return]    ${result}
135
136 Preload One Vnf Topology
137     [Arguments]    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}       ${vf_module_name}    ${vf_module_type}    ${service}    ${filename}   ${uuid}
138     Return From Keyword If    '${filename}' == ''
139     ${data_template}=    OperatingSystem.Get File    ${PRELOAD_VNF_TOPOLOGY_OPERATION_BODY}/preload.template
140     ${parameters}=    Get Template Parameters    ${generic_vnf_name}    ${filename}   ${uuid}
141     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}
142     ${data}=    Fill JSON Template    ${data_template}    ${parameters}
143         ${put_resp}=    Run SDNGC Post Request     ${SDNGC_INDEX_PATH}${PRELOAD_VNF_TOPOLOGY_OPERATION_PATH}     ${data}
144     Should Be Equal As Strings  ${put_resp.json()['output']['response-code']}   200
145     ${get_resp}=  Run SDNGC Get Request  ${SDNGC_INDEX_PATH}${PRELOAD_VNF_CONFIG_PATH}/${vf_module_name}/${vf_module_type}
146     Should Be Equal As Strings  ${get_resp.status_code}         200
147
148 Get Template Parameters
149     [Arguments]   ${generic_vnf_name}    ${template}    ${uuid}
150     ${rest}   ${suite}=    Split String From Right    ${SUITE NAME}   .   1
151     ${uuid}=    Catenate    ${uuid}
152     ${hostid}=    Get Substring    ${uuid}    -4
153     ${ecompnet}=    Evaluate    (${GLOBAL_BUILD_NUMBER}%128)+128
154
155
156     # Initialize the value map with the properties generated from the Robot VM /opt/config folder
157     ${valuemap}=   Copy Dictionary    ${GLOBAL_INJECTED_PROPERTIES}
158
159     # These should be deprecated by the above....
160     Set To Dictionary   ${valuemap}   artifacts_version=${GLOBAL_INJECTED_ARTIFACTS_VERSION}
161     Set To Dictionary   ${valuemap}   network=${GLOBAL_INJECTED_NETWORK}
162     Set To Dictionary   ${valuemap}   public_net_id=${GLOBAL_INJECTED_PUBLIC_NET_ID}
163     Set To Dictionary   ${valuemap}   cloud_env=${GLOBAL_INJECTED_CLOUD_ENV}
164     Set To Dictionary   ${valuemap}   install_script_version=${GLOBAL_INJECTED_SCRIPT_VERSION}
165     Set To Dictionary   ${valuemap}   vm_image_name=${GLOBAL_INJECTED_VM_IMAGE_NAME}
166     Set To Dictionary   ${valuemap}   vm_flavor_name=${GLOBAL_INJECTED_VM_FLAVOR}
167
168
169     # update the value map with unique values.
170     Set To Dictionary   ${valuemap}   uuid=${uuid}   hostid=${hostid}    ecompnet=${ecompnet}    generic_vnf_name=${generic_vnf_name}
171
172     #
173     # Mash together the defaults dict with the test case dict to create the set of
174     # preload parameters
175     #
176     ${suite_templates}=    Get From Dictionary    ${GLOBAL_PRELOAD_PARAMETERS}    ${suite}
177     ${template}=    Get From Dictionary    ${suite_templates}    ${template}
178     ${defaults}=    Get From Dictionary    ${GLOBAL_PRELOAD_PARAMETERS}    defaults
179     # add all of the defaults to template...
180     @{keys}=    Get Dictionary Keys    ${defaults}
181     :FOR   ${key}   IN   @{keys}
182     \    ${value}=   Get From Dictionary    ${defaults}    ${key}
183     \    Set To Dictionary    ${template}  ${key}    ${value}
184
185     #
186     # Get the vnf_parameters to preload
187     #
188     ${vnf_parameters}=   Resolve VNF Parameters Into Array   ${valuemap}   ${template}
189     ${vnf_parameters_json}=   Evaluate    json.dumps(${vnf_parameters})    json
190     ${parameters}=   Create Dictionary   vnf_parameters=${vnf_parameters_json}
191     [Return]    ${parameters}
192
193 Resolve Values Into Dictionary
194     [Arguments]   ${valuemap}    ${from}    ${to}
195     ${keys}=    Get Dictionary Keys    ${from}
196     :FOR   ${key}   IN  @{keys}
197     \    ${value}=    Get From Dictionary    ${from}   ${key}
198     \    ${value}=    Template String    ${value}    ${valuemap}
199     \    Set To Dictionary    ${to}    ${key}    ${value}
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 UUID
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}