aboutsummaryrefslogtreecommitdiffstats
path: root/robot/resources/vid/vid_interface.robot
blob: a9294c33595f3236eb671438aed08fa30f3e1ce2 (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
*** Settings ***
Documentation     The main interface for interacting with VID. It handles low level stuff like managing the selenium request library and VID required steps
Library       SeleniumLibrary
Library    Collections
Library         String
Library         RequestsLibrary
Library           ONAPLibrary.Utilities
Resource        ../global_properties.robot
Resource        ../browser_setup.robot

*** Variables ***
${VID_ENV}            /vid
${VID_ENDPOINT}    ${GLOBAL_VID_SERVER_PROTOCOL}://${GLOBAL_INJECTED_VID_IP_ADDR}:${GLOBAL_VID_SERVER_PORT}
${VID_LOGIN_URL}                ${VID_ENDPOINT}${VID_ENV}/login.htm
${VID_HEALTHCHECK_PATH}    ${VID_ENV}/healthCheck
${VID_HOME_URL}                ${VID_ENDPOINT}${VID_ENV}/welcome.htm
${VID_SERVICE_MODELS_URL}                ${VID_ENDPOINT}${VID_ENV}/serviceModels.htm#/models/services

*** Keywords ***
Run VID Health Check
    [Documentation]   Logs in to VID GUI
    ${resp}=    Run VID Get Request    ${VID_HEALTHCHECK_PATH}
    Should Be Equal As Strings  ${resp.status_code}   200
    Should Be String    ${resp.json()['detailedMsg']}

Run VID Get Request
    [Documentation]    Runs an VID get request
    [Arguments]    ${data_path}
    ${auth}=  Create List  ${GLOBAL_VID_HEALTH_USERNAME}    ${GLOBAL_VID_HEALTH_PASSWORD}
    Log    Creating session ${VID_ENDPOINT}
    ${session}=    Create Session   vid   ${VID_ENDPOINT}    auth=${auth}
    ${uuid}=    Generate UUID4
    ${headers}=  Create Dictionary     username=${GLOBAL_VID_HEALTH_USERNAME}    password=${GLOBAL_VID_HEALTH_PASSWORD}    Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
    ${resp}=  Get Request   vid   ${data_path}     headers=${headers}
    Log    Received response from vid ${resp.text}
    [Return]    ${resp}

Login To VID GUI
    [Documentation]   Logs in to VID GUI
    [Arguments]    ${api_type}=vnf_api
    # Setup Browser Now being managed by test case
    ##Setup Browser
    Go To    ${VID_LOGIN_URL}
    #Maximize Browser Window
    Set Selenium Speed    ${GLOBAL_SELENIUM_DELAY}
    Set Browser Implicit Wait    ${GLOBAL_SELENIUM_BROWSER_IMPLICIT_WAIT}
    Log    Logging in to ${VID_ENDPOINT}${VID_ENV}
    Handle Proxy Warning
    Title Should Be    Login
    Input Text    xpath=//input[@id='loginId']    ${GLOBAL_VID_USERNAME}
    Input Password    xpath=//input[@id='password']    ${GLOBAL_VID_PASSWORD}
    Click Button    xpath=//input[@id='loginBtn']
    Wait Until Page Contains  Welcome to VID    ${GLOBAL_SELENIUM_BROWSER_WAIT_TIMEOUT}
    Run Keyword If    "${api_type}"=="vnf_api"    Select From List By Label    //select[@id='selectTestApi']    VNF_API (old)
    Run Keyword If    "${api_type}"=="gr_api"    Select From List By Label    //select[@id='selectTestApi']    GR_API (new)
    Log    Logged in to ${VID_ENDPOINT}${VID_ENV}

Go To VID HOME
    [Documentation]    Naviage to VID Home
    Go To    ${VID_HOME_URL}
    Wait Until Page Contains  Welcome to VID    ${GLOBAL_SELENIUM_BROWSER_WAIT_TIMEOUT}

Go To VID Browse Service Models
    [Documentation]    Naviage to VID Browse Service Models
    Go To    ${VID_SERVICE_MODELS_URL}
    Wait Until Page Contains   Browse SDC Service Models   ${GLOBAL_SELENIUM_BROWSER_WAIT_TIMEOUT}

Click On Button When Enabled
    [Arguments]     ${xpath}    ${timeout}=${GLOBAL_VID_UI_TIMEOUT_MEDIUM}
    Wait Until Page Contains Element    xpath=${xpath}    ${timeout}
    Wait Until Element Is Visible    xpath=${xpath}    ${timeout}
    Wait Until Element Is Enabled    xpath=${xpath}    ${timeout}
    Click Button      xpath=${xpath}

Click On Element When Visible
    [Arguments]     ${xpath}    ${timeout}=${GLOBAL_VID_UI_TIMEOUT_MEDIUM}
    Wait Until Page Contains Element    xpath=${xpath}    ${timeout}
    Wait Until Element Is Visible    xpath=${xpath}    ${timeout}
    Click Element      xpath=${xpath}

Select From List When Enabled
    [Arguments]     ${xpath}    ${value}    ${timeout}=${GLOBAL_VID_UI_TIMEOUT_MEDIUM}
    Wait Until Page Contains Element    xpath=${xpath}    ${timeout}
    Wait Until Element Is Enabled    xpath=${xpath}    ${timeout}
    Select From List By Label     xpath=${xpath}    ${value}

Input Text When Enabled
    [Arguments]     ${xpath}    ${value}    ${timeout}=${GLOBAL_VID_UI_TIMEOUT_MEDIUM}
    Wait Until Page Contains Element    xpath=${xpath}    ${timeout}
    Wait Until Element Is Enabled    xpath=${xpath}    ${timeout}
    Input Text    xpath=${xpath}    ${value}

Parse Request Id
    [Arguments]    ${so_response_text}
  ${request_list}=     Split String    ${so_response_text}    202)\n    1
  ${clean_string}=    Replace String    ${request_list[1]}    \n    ${empty}
    ${json}=    To Json    ${clean_string}
    ${request_id}=    Catenate    ${json['requestReferences']['requestId']}
    [Return]    ${request_id}

Parse Instance Id
    [Arguments]    ${so_response_text}
  ${request_list}=     Split String    ${so_response_text}    202)\n    1
    ${json}=    To Json    ${request_list[1]}
    ${request_id}=    Catenate    ${json['requestReferences']['instanceId']}
    [Return]    ${request_id}

Get Model UUID from VID
    [Documentation]    Must use UI since rest call get redirect to portal and get DNS error
    ...    Search all services and match on the invariantUUID
    [Arguments]   ${invariantUUID}
    Go To     ${VID_ENDPOINT}${VID_ENV}/rest/models/services
    ${resp}=   Get Text   xpath=//body/pre
    ${json}=   To Json    ${resp}
    ${services}=   Get From Dictionary    ${json}   services
    :FOR   ${dict}  IN  @{services}
    \    ${uuid}=   Get From DIctionary   ${dict}   uuid
    \    ${inv}=   Get From DIctionary   ${dict}    invariantUUID
    \    Return From Keyword If   "${invariantUUID}" == "${inv}"   ${uuid}
    [Return]    ""


Get Module Names from VID
    [Documentation]    Must use UI since rest call get redirect to portal and get DNS error
    ...    Given the invariantUUID of the model, mock up the vf_modules list passed to Preload VNF
    [Arguments]   ${invariantUUID}
    ${id}=   Get Model UUID from VID    ${invariantUUID}
    Go To     ${VID_ENDPOINT}${VID_ENV}/rest/models/services/${id}
    ${resp}=   Get Text   xpath=//body/pre
    ${json}=   To Json    ${resp}
    ${modules}=   Create List
    ${vnfs}=   Get From Dictionary    ${json}   vnfs
    ${keys}=   Get Dictionary Keys    ${vnfs}
    :FOR   ${key}  IN  @{keys}
    \    Add VFModule   ${vnfs['${key}']}   ${modules}
    [Return]    ${modules}

Add VFModule
    [Documentation]   Dig the vf module names from the VID service model
    [Arguments]   ${vnf}   ${modules}
    ${vfModules}=   Get From Dictionary    ${vnf}   vfModules
    ${keys}=   Get Dictionary Keys    ${vfModules}
    :FOR   ${key}  IN  @{keys}
    \    ${module}=   Get From Dictionary    ${vfModules}   ${key}
    \    ${dict}=    Create Dictionary   name=${module['name']}
    \    Append to List   ${modules}   ${dict}