aboutsummaryrefslogtreecommitdiffstats
path: root/robot/resources/sdngc_interface.robot
blob: f1100a68f19960ab4ff08deb67384b74dcb035e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
*** Settings ***
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
Library         RequestsLibrary
Library           ONAPLibrary.Utilities
Library    OperatingSystem
Library       SeleniumLibrary
Library         Collections
Library      String
Library      StringTemplater
Library           ONAPLibrary.ServiceMapping

Resource          global_properties.robot
Resource          ../resources/json_templater.robot
Resource        browser_setup.robot


*** Variables ***
${PRELOAD_VNF_TOPOLOGY_OPERATION_PATH}  /operations/VNF-API:preload-vnf-topology-operation
${PRELOAD_VNF_CONFIG_PATH}  /config/VNF-API:preload-vnfs/vnf-preload-list
${PRELOAD_VNF_TOPOLOGY_OPERATION_BODY}  robot/assets/templates/sdnc/
${SDNGC_INDEX_PATH}    /restconf
${SDNCGC_HEALTHCHECK_OPERATION_PATH}  /operations/SLI-API:healthcheck
${SDNGC_REST_ENDPOINT}    ${GLOBAL_SDNGC_SERVER_PROTOCOL}://${GLOBAL_INJECTED_SDNC_IP_ADDR}:${GLOBAL_SDNGC_REST_PORT}
${SDNGC_ADMIN_ENDPOINT}    ${GLOBAL_SDNGC_SERVER_PROTOCOL}://${GLOBAL_INJECTED_SDNC_PORTAL_IP_ADDR}:${GLOBAL_SDNGC_ADMIN_PORT}
${SDNGC_ADMIN_SIGNUP_URL}    ${SDNGC_ADMIN_ENDPOINT}/signup
${SDNGC_ADMIN_LOGIN_URL}    ${SDNGC_ADMIN_ENDPOINT}/login
${SDNGC_ADMIN_VNF_PROFILE_URL}    ${SDNGC_ADMIN_ENDPOINT}/mobility/getVnfProfile

*** Keywords ***
Run SDNGC Health Check
    [Documentation]    Runs an SDNGC healthcheck
  ${resp}=    Run SDNGC Post Request     ${SDNGC_INDEX PATH}${SDNCGC_HEALTHCHECK_OPERATION_PATH}     ${None}
    Should Be Equal As Strings  ${resp.status_code}   200
    Should Be Equal As Strings  ${resp.json()['output']['response-code']}   200

Run SDNGC Get Request
    [Documentation]    Runs an SDNGC get request
    [Arguments]    ${data_path}
    ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
    Log    Creating session ${SDNGC_REST_ENDPOINT}
    ${session}=    Create Session   sdngc   ${SDNGC_REST_ENDPOINT}    auth=${auth}
    ${uuid}=    Generate UUID4
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
    ${resp}=  Get Request   sdngc   ${data_path}     headers=${headers}
    Log    Received response from sdngc ${resp.text}
    [Return]    ${resp}

Run SDNGC Put Request
    [Documentation]    Runs an SDNGC put request
    [Arguments]    ${data_path}    ${data}
    ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
    Log    Creating session ${SDNGC_REST_ENDPOINT}
    ${session}=    Create Session   sdngc   ${SDNGC_REST_ENDPOINT}    auth=${auth}
    ${uuid}=    Generate UUID4
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
    ${resp}=  Put Request   sdngc   ${data_path}     data=${data}    headers=${headers}
    Log    Received response from sdngc ${resp.text}
    [Return]    ${resp}

Run SDNGC Post Request
    [Documentation]    Runs an SDNGC post request
    [Arguments]    ${data_path}    ${data}
    ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
    Log    Creating session ${SDNGC_REST_ENDPOINT}
    ${session}=    Create Session   sdngc   ${SDNGC_REST_ENDPOINT}    auth=${auth}
    ${uuid}=    Generate UUID4
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
    ${resp}=  Post Request  sdngc   ${data_path}     data=${data}    headers=${headers}
    Log    Received response from sdngc ${resp.text}
    [Return]    ${resp}

Run SDNGC Delete Request
    [Documentation]    Runs an SDNGC delete request
    [Arguments]    ${data_path}
    ${auth}=  Create List  ${GLOBAL_SDNGC_USERNAME}    ${GLOBAL_SDNGC_PASSWORD}
    Log    Creating session ${SDNGC_REST_ENDPOINT}
    ${session}=    Create Session   sdngc   ${SDNGC_REST_ENDPOINT}    auth=${auth}
    ${uuid}=    Generate UUID4
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
    ${resp}=  Delete Request  sdngc   ${data_path}        headers=${headers}
    Log    Received response from sdngc ${resp.text}
    [Return]    ${resp}


Preload Vnf
    [Arguments]    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}     ${vf_module_name}    ${vf_modules}    ${service}   ${uuid}
    ${base_vf_module_type}=    Catenate
    ${closedloop_vf_module}=    Create Dictionary
    Set Directory    default    ./demo/service_mapping
    ${templates}=    Get Service Template Mapping    default    ${service}    ${generic_vnf_type}
    :FOR    ${vf_module}    IN      @{vf_modules}
    \       ${vf_module_type}=    Get From Dictionary    ${vf_module}    name
    #     need to pass in vnf_index if non-zero
    \       ${dict}   Run Keyword If    "${generic_vnf_name}".endswith('0')      Get From Mapping With Index    ${templates}    ${vf_module}   0
    \       ...    ELSE IF  "${generic_vnf_name}".endswith('1')      Get From Mapping With Index    ${templates}    ${vf_module}   1
    \       ...    ELSE IF  "${generic_vnf_name}".endswith('2')      Get From Mapping With Index    ${templates}    ${vf_module}   2
    \       ...    ELSE   Get From Mapping    ${templates}    ${vf_module}
    #     skip this iteration if no template 
    \       ${test_dict_length} =  Get Length  ${dict}
    \       Continue For Loop If   ${test_dict_length} == 0
    \       ${filename}=    Get From Dictionary    ${dict}    template
    \       ${base_vf_module_type}=   Set Variable If    '${dict['isBase']}' == 'true'     ${vf_module_type}    ${base_vf_module_type}
    \       ${closedloop_vf_module}=   Set Variable If    '${dict['isBase']}' == 'false'     ${vf_module}    ${closedloop_vf_module}
    \       ${vf_name}=     Update Module Name    ${dict}    ${vf_module_name}
    #    Admin portal update no longer 
    #\       Preload Vnf Profile    ${vf_module_type}
    \       Preload One Vnf Topology    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}     ${vf_name}    ${vf_module_type}    ${service}    ${filename}   ${uuid}
    [Return]    ${base_vf_module_type}   ${closedloop_vf_module}


Update Module Name
    [Arguments]    ${dict}    ${vf_module_name}
    Return From Keyword If    'prefix' not in ${dict}    ${vf_module_name}
    Return From Keyword If    '${dict['prefix']}' == ''    ${vf_module_name}
    ${name}=    Replace String   ${vf_module_name}   Vfmodule_    ${dict['prefix']}
    [Return]    ${name}

Get From Mapping With Index
    [Documentation]    Retrieve the appropriate prelad template entry for the passed vf_module
    [Arguments]    ${templates}    ${vf_module}   ${vnf_index}=0
    ${vf_module_name}=    Get From DIctionary    ${vf_module}    name
    :FOR    ${template}   IN   @{templates}
    \    Return From Keyword If    '${template['name_pattern']}' in '${vf_module_name}' and ('${template['vnf_index']}' == '${vnf_index}')     ${template}
    ${result}=    Create Dictionary
    [Return]    ${result}

Get From Mapping
    [Documentation]    Retrieve the appropriate prelad template entry for the passed vf_module
    [Arguments]    ${templates}    ${vf_module}
    ${vf_module_name}=    Get From DIctionary    ${vf_module}    name
    :FOR    ${template}   IN   @{templates}
    \    Return From Keyword If    '${template['name_pattern']}' in '${vf_module_name}'     ${template}
    ${result}=    Create Dictionary
    [Return]    ${result}

Preload One Vnf Topology
    [Arguments]    ${service_type_uuid}    ${generic_vnf_name}    ${generic_vnf_type}       ${vf_module_name}    ${vf_module_type}    ${service}    ${filename}   ${uuid}
    Return From Keyword If    '${filename}' == ''
    ${data_template}=    OperatingSystem.Get File    ${PRELOAD_VNF_TOPOLOGY_OPERATION_BODY}/preload.template
    ${parameters}=    Get Template Parameters    ${generic_vnf_name}    ${filename}   ${uuid}
    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}
    ${data}=  Fill JSON Template    ${data_template}    ${parameters}
  ${put_resp}=    Run SDNGC Post Request     ${SDNGC_INDEX_PATH}${PRELOAD_VNF_TOPOLOGY_OPERATION_PATH}     ${data}
    Should Be Equal As Strings  ${put_resp.json()['output']['response-code']}   200
    ${get_resp}=  Run SDNGC Get Request  ${SDNGC_INDEX_PATH}${PRELOAD_VNF_CONFIG_PATH}/${vf_module_name}/${vf_module_type}
    Should Be Equal As Strings  ${get_resp.status_code}   200

Get Template Parameters
    [Arguments]   ${generic_vnf_name}    ${template}    ${uuid}
    ${rest}   ${suite}=    Split String From Right    ${SUITE NAME}   .   1
    ${uuid}=    Catenate    ${uuid}
    ${hostid}=    Get Substring    ${uuid}    -4
    ${ecompnet}=    Evaluate    (${GLOBAL_BUILD_NUMBER}%128)+128


    # Initialize the value map with the properties generated from the Robot VM /opt/config folder
    ${valuemap}=   Copy Dictionary    ${GLOBAL_INJECTED_PROPERTIES}

    # These should be deprecated by the above....
    Set To Dictionary   ${valuemap}   artifacts_version=${GLOBAL_INJECTED_ARTIFACTS_VERSION}
    Set To Dictionary   ${valuemap}   network=${GLOBAL_INJECTED_NETWORK}
    Set To Dictionary   ${valuemap}   public_net_id=${GLOBAL_INJECTED_PUBLIC_NET_ID}
    Set To Dictionary   ${valuemap}   cloud_env=${GLOBAL_INJECTED_CLOUD_ENV}
    Set To Dictionary   ${valuemap}   install_script_version=${GLOBAL_INJECTED_SCRIPT_VERSION}
    Set To Dictionary   ${valuemap}   vm_image_name=${GLOBAL_INJECTED_VM_IMAGE_NAME}
    Set To Dictionary   ${valuemap}   vm_flavor_name=${GLOBAL_INJECTED_VM_FLAVOR}


    # update the value map with unique values.
    Set To Dictionary   ${valuemap}   uuid=${uuid}   hostid=${hostid}    ecompnet=${ecompnet}    generic_vnf_name=${generic_vnf_name}

    #
    # Mash together the defaults dict with the test case dict to create the set of
    # preload parameters
    #
    ${suite_templates}=    Get From Dictionary    ${GLOBAL_PRELOAD_PARAMETERS}    ${suite}
    ${template}=    Get From Dictionary    ${suite_templates}    ${template}
    ${defaults}=    Get From Dictionary    ${GLOBAL_PRELOAD_PARAMETERS}    defaults
    # add all of the defaults to template...
    @{keys}=    Get Dictionary Keys    ${defaults}
    :FOR   ${key}   IN   @{keys}
    \    ${value}=   Get From Dictionary    ${defaults}    ${key}
    \    Set To Dictionary    ${template}  ${key}    ${value}

    #
    # Get the vnf_parameters to preload
    #
    ${vnf_parameters}=   Resolve VNF Parameters Into Array   ${valuemap}   ${template}
    ${vnf_parameters_json}=   Evaluate    json.dumps(${vnf_parameters})    json
    ${parameters}=   Create Dictionary   vnf_parameters=${vnf_parameters_json}
    [Return]    ${parameters}

Resolve Values Into Dictionary
    [Arguments]   ${valuemap}    ${from}    ${to}
    ${keys}=    Get Dictionary Keys    ${from}
    :FOR   ${key}   IN  @{keys}
    \    ${value}=    Get From Dictionary    ${from}   ${key}
    \    ${value}=    Template String    ${value}    ${valuemap}
    \    Set To Dictionary    ${to}    ${key}    ${value}

Resolve VNF Parameters Into Array
    [Arguments]   ${valuemap}    ${from}
    ${vnf_parameters}=   Create List
    ${keys}=    Get Dictionary Keys    ${from}
    :FOR   ${key}   IN  @{keys}
    \    ${value}=    Get From Dictionary    ${from}   ${key}
    \    ${value}=    Template String    ${value}    ${valuemap}
    \    ${parameter}=   Create Dictionary   vnf-parameter-name=${key}    vnf-parameter-value=${value}
    \    Append To List    ${vnf_parameters}   ${parameter}
    [Return]   ${vnf_parameters}

Preload Vnf Profile
    [Arguments]    ${vnf_name}
    Login To SDNGC Admin GUI
    Go To    ${SDNGC_ADMIN_VNF_PROFILE_URL}
    Click Button    xpath=//button[@data-target='#add_vnf_profile']
    Input Text    xpath=//input[@id='nf_vnf_type']    ${vnf_name}
    Input Text    xpath=//input[@id='nf_availability_zone_count']    999
    Input Text    xpath=//input[@id='nf_equipment_role']    robot-ete-test
    Click Button    xpath=//button[contains(.,'Submit')]
    Page Should Contain  VNF Profile
    Input Text    xpath=//div[@id='vnf_profile_filter']//input    ${vnf_name}
    Page Should Contain  ${vnf_name}

Delete Vnf Profile
    [Arguments]    ${vnf_name}
    Login To SDNGC Admin GUI
    Go To    ${SDNGC_ADMIN_VNF_PROFILE_URL}
    Page Should Contain  VNF Profile
    Input Text    xpath=//div[@id='vnf_profile_filter']//input    ${vnf_name}
    Page Should Contain  ${vnf_name}
    Click Button    xpath=//button[contains(@onclick, '${vnf_name}')]
    Page Should Contain    Are you sure you want to delete VNF_PROFILE
    Click Button    xpath=//button[contains(text(), 'Yes')]
    Page Should Not Contain  ${vnf_name}

Login To SDNGC Admin GUI
    [Documentation]   Login To SDNGC Admin GUI
    ## Setup Browser is now being managed by the test case
    ## Setup Browser
    Go To    ${SDNGC_ADMIN_SIGNUP_URL}
    ##Maximize Browser Window
    Set Selenium Speed    ${GLOBAL_SELENIUM_DELAY}
    Set Browser Implicit Wait    ${GLOBAL_SELENIUM_BROWSER_IMPLICIT_WAIT}
    Log    Logging in to ${SDNGC_ADMIN_LOGIN_URL}
    Handle Proxy Warning
    Title Should Be    AdminPortal
    ${uuid}=    Generate UUID4
    ${shortened_uuid}=     Evaluate    str("${uuid}")[:12]
    ${email}=        Catenate    ${shortened_uuid}@robotete.com
    Input Text    xpath=//input[@id='nf_email']    ${email}
    Input Password    xpath=//input[@id='nf_password']    ${shortened_uuid}
    Click Button    xpath=//button[@type='submit']
    Wait Until Page Contains    User created   20s
    Go To    ${SDNGC_ADMIN_LOGIN_URL}
    Input Text    xpath=//input[@id='email']    ${email}
    Input Password    xpath=//input[@id='password']    ${shortened_uuid}
    Click Button    xpath=//button[@type='submit']
    Title Should Be    SDN-C AdminPortal
    Log    Logged in to ${SDNGC_ADMIN_LOGIN_URL}