upgrade to python3 libraries
[testsuite.git] / robot / resources / vid / vid_interface.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with VID. It handles low level stuff like managing the selenium request library and VID required steps
3 Library             SeleniumLibrary
4 Library    Collections
5 Library         String
6 Library               RequestsLibrary
7 Library           UUID
8 Resource        ../global_properties.robot
9 Resource        ../browser_setup.robot
10
11 *** Variables ***
12 ${VID_ENV}            /vid
13 ${VID_ENDPOINT}    ${GLOBAL_VID_SERVER_PROTOCOL}://${GLOBAL_INJECTED_VID_IP_ADDR}:${GLOBAL_VID_SERVER_PORT}
14 ${VID_LOGIN_URL}                ${VID_ENDPOINT}${VID_ENV}/login.htm
15 ${VID_HEALTHCHECK_PATH}    ${VID_ENV}/healthCheck
16 ${VID_HOME_URL}                ${VID_ENDPOINT}${VID_ENV}/welcome.htm
17 ${VID_SERVICE_MODELS_URL}                ${VID_ENDPOINT}${VID_ENV}/serviceModels.htm#/models/services
18
19 *** Keywords ***
20 Run VID Health Check
21     [Documentation]   Logs in to VID GUI
22     ${resp}=    Run VID Get Request    ${VID_HEALTHCHECK_PATH}
23     Should Be Equal As Strings  ${resp.status_code}     200
24     Should Be String    ${resp.json()['detailedMsg']}
25
26 Run VID Get Request
27     [Documentation]    Runs an VID get request
28     [Arguments]    ${data_path}
29     ${auth}=  Create List  ${GLOBAL_VID_HEALTH_USERNAME}    ${GLOBAL_VID_HEALTH_PASSWORD}
30     Log    Creating session ${VID_ENDPOINT}
31     ${session}=    Create Session       vid     ${VID_ENDPOINT}    auth=${auth}
32     ${uuid}=    Generate UUID
33     ${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}
34     ${resp}=    Get Request     vid     ${data_path}     headers=${headers}
35     Log    Received response from vid ${resp.text}
36     [Return]    ${resp}
37
38 Login To VID GUI
39     [Documentation]   Logs in to VID GUI
40     # Setup Browser Now being managed by test case
41     ##Setup Browser
42     Go To    ${VID_LOGIN_URL}
43     #Maximize Browser Window
44     Set Selenium Speed    ${GLOBAL_SELENIUM_DELAY}
45     Set Browser Implicit Wait    ${GLOBAL_SELENIUM_BROWSER_IMPLICIT_WAIT}
46     Log    Logging in to ${VID_ENDPOINT}${VID_ENV}
47     Handle Proxy Warning
48     Title Should Be    Login
49     Input Text    xpath=//input[@id='loginId']    ${GLOBAL_VID_USERNAME}
50     Input Password    xpath=//input[@id='password']    ${GLOBAL_VID_PASSWORD}
51     Click Button    xpath=//input[@id='loginBtn']
52     Wait Until Page Contains  Welcome to VID    ${GLOBAL_SELENIUM_BROWSER_WAIT_TIMEOUT}
53     Select From List By Label    //select[@id='selectTestApi']    VNF_API (old)
54     Log    Logged in to ${VID_ENDPOINT}${VID_ENV}
55
56 Go To VID HOME
57     [Documentation]    Naviage to VID Home
58     Go To    ${VID_HOME_URL}
59     Wait Until Page Contains  Welcome to VID    ${GLOBAL_SELENIUM_BROWSER_WAIT_TIMEOUT}
60
61 Go To VID Browse Service Models
62     [Documentation]    Naviage to VID Browse Service Models
63     Go To    ${VID_SERVICE_MODELS_URL}
64     Wait Until Page Contains   Browse SDC Service Models   ${GLOBAL_SELENIUM_BROWSER_WAIT_TIMEOUT}
65
66 Click On Button When Enabled
67     [Arguments]     ${xpath}    ${timeout}=${GLOBAL_VID_UI_TIMEOUT_MEDIUM}
68     Wait Until Page Contains Element    xpath=${xpath}    ${timeout}
69     Wait Until Element Is Enabled    xpath=${xpath}    ${timeout}
70     Click Button      xpath=${xpath}
71
72 Click On Element When Visible
73     [Arguments]     ${xpath}    ${timeout}=${GLOBAL_VID_UI_TIMEOUT_MEDIUM}
74     Wait Until Page Contains Element    xpath=${xpath}    ${timeout}
75     Wait Until Element Is Visible    xpath=${xpath}    ${timeout}
76     Click Element      xpath=${xpath}
77
78 Select From List When Enabled
79     [Arguments]     ${xpath}    ${value}    ${timeout}=${GLOBAL_VID_UI_TIMEOUT_MEDIUM}
80     Wait Until Page Contains Element    xpath=${xpath}    ${timeout}
81     Wait Until Element Is Enabled    xpath=${xpath}    ${timeout}
82     Select From List     xpath=${xpath}    ${value}
83
84 Input Text When Enabled
85     [Arguments]     ${xpath}    ${value}    ${timeout}=${GLOBAL_VID_UI_TIMEOUT_MEDIUM}
86     Wait Until Page Contains Element    xpath=${xpath}    ${timeout}
87     Wait Until Element Is Enabled    xpath=${xpath}    ${timeout}
88     Input Text    xpath=${xpath}    ${value}
89
90 Parse Request Id
91     [Arguments]    ${mso_response_text}
92         ${request_list}=     Split String    ${mso_response_text}    202)\n    1
93         ${clean_string}=    Replace String    ${request_list[1]}    \n    ${empty}
94     ${json}=    To Json    ${clean_string}
95     ${request_id}=    Catenate    ${json['requestReferences']['requestId']}
96     [Return]    ${request_id}
97
98 Parse Instance Id
99     [Arguments]    ${mso_response_text}
100         ${request_list}=     Split String    ${mso_response_text}    202)\n    1
101     ${json}=    To Json    ${request_list[1]}
102     ${request_id}=    Catenate    ${json['requestReferences']['instanceId']}
103     [Return]    ${request_id}
104
105 Get Model UUID from VID
106     [Documentation]    Must use UI since rest call get redirect to portal and get DNS error
107     ...    Search all services and match on the invariantUUID
108     [Arguments]   ${invariantUUID}
109     Go To     ${VID_ENDPOINT}${VID_ENV}/rest/models/services
110     ${resp}=   Get Text   xpath=//body/pre
111     ${json}=   To Json    ${resp}
112     ${services}=   Get From Dictionary    ${json}   services
113     :FOR   ${dict}  IN  @{services}
114     \    ${uuid}=   Get From DIctionary   ${dict}   uuid
115     \    ${inv}=   Get From DIctionary   ${dict}    invariantUUID
116     \    Return From Keyword If   "${invariantUUID}" == "${inv}"   ${uuid}
117     [Return]    ""
118
119
120 Get Module Names from VID
121     [Documentation]    Must use UI since rest call get redirect to portal and get DNS error
122     ...    Given the invariantUUID of the model, mock up the vf_modules list passed to Preload VNF
123     [Arguments]   ${invariantUUID}
124     ${id}=   Get Model UUID from VID    ${invariantUUID}
125     Go To     ${VID_ENDPOINT}${VID_ENV}/rest/models/services/${id}
126     ${resp}=   Get Text   xpath=//body/pre
127     ${json}=   To Json    ${resp}
128     ${modules}=   Create List
129     ${vnfs}=   Get From Dictionary    ${json}   vnfs
130     ${keys}=   Get Dictionary Keys    ${vnfs}
131     :FOR   ${key}  IN  @{keys}
132     \    Add VFModule   ${vnfs['${key}']}   ${modules}
133     [Return]    ${modules}
134
135 Add VFModule
136     [Documentation]   Dig the vf module names from the VID service model
137     [Arguments]   ${vnf}   ${modules}
138     ${vfModules}=   Get From Dictionary    ${vnf}   vfModules
139     ${keys}=   Get Dictionary Keys    ${vfModules}
140     :FOR   ${key}  IN  @{keys}
141     \    ${module}=   Get From Dictionary    ${vfModules}   ${key}
142     \    ${dict}=    Create Dictionary   name=${module['name']}
143     \    Append to List   ${modules}   ${dict}