[ROBOT] ADD HTTPS based BULKPM test cases that use helm based components
[testsuite.git] / robot / resources / consul_interface.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with Consul.
3 Library           RequestsLibrary
4 Library           Collections
5 Library           String
6 Resource          global_properties.robot
7
8 *** Variables ***
9 ${CONSUL_ENDPOINT}              http://consul-server-ui:8500
10 #${CONSUL_ENDPOINT}              ${GLOBAL_CONSUL_SERVER_PROTOCOL}://${GLOBAL_CONSUL_SERVER_NAME}:${GLOBAL_CONSUL_SERVER_PORT}
11
12
13
14 *** Keywords ***
15 Run Consul Get Request
16     [Documentation]    Runs Consul Tcagen2 Get Request
17     [Arguments]    ${data_path}
18     ${session}=    Create Session      consul  ${CONSUL_ENDPOINT}
19     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
20     ${resp}=   Get Request     consul  ${data_path}     headers=${headers}
21     Log    Received response from tcagen2 ${resp.text}
22     Should Be Equal As Strings         ${resp.status_code}     200
23     [Return]   ${resp}
24
25 Run Consul Put Request
26     [Documentation]    Runs Consul Tcagen2 Put request
27     [Arguments]    ${data_path}  ${data}
28     ${session}=    Create Session      consul  ${CONSUL_ENDPOINT}
29     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
30     ${resp}=   Put Request     consul  ${data_path}     data=${data}    headers=${headers}
31     Log    Received response from consul ${resp.text}
32     [Return]    ${resp}
33
34 Update Tca ControlLoopName
35     [Arguments]   ${resource_id}
36     ${closedLoopControlName}=    Set Variable    ControlLoop-vFirewall-${resource_id}
37     Log    Obtained closedLoopControlName ${closedLoopControlName}
38     ${resp}=   Run Consul Get Request   /v1/kv/dcae-tcagen2
39     Should Be Equal As Strings  ${resp.status_code}     200
40     ${base64Obj}=   Set Variable    ${resp.json()[0]["Value"]}
41     ${binObj}=   Evaluate   base64.b64decode("${base64Obj}")   modules=base64
42     ${escaped}=   Replace String    ${binObj}   \\   \\\\
43     ${dict}=    Evaluate   json.loads('${escaped}')    json
44     ${tca_policy}=    Set Variable    ${dict['tca.policy']}
45     ${mdf_tca_policy}=    Replace String Using Regexp   ${tca_policy}    ControlLoop-vFirewall[^"]*    ${closedLoopControlName}
46     #Set To Dictionary    ${dict['app_preferences']}    tca_policy=${mdf_tca_policy}
47     Set To Dictionary    ${dict}    tca.policy=${mdf_tca_policy}
48     ${json}=   Evaluate   json.dumps(${dict})     json
49     ${resp}=   Run Consul Put Request   /v1/kv/dcae-tcagen2    data=${json}
50     Should Be Equal As Strings  ${resp.status_code}     200