5b6f948f669dcce947eb5e898818af049800a71e
[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.onap:8500
10
11
12 *** Keywords ***
13 Run Consul Get Request
14     [Documentation]    Runs Consul Tcagen2 Get Request
15     [Arguments]    ${data_path}
16     ${session}=    Create Session      consul  ${CONSUL_ENDPOINT}
17     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
18     ${resp}=   Get Request     consul  ${data_path}     headers=${headers}
19     Log    Received response from tcagen2 ${resp.text}
20     Should Be Equal As Strings         ${resp.status_code}     200
21     [Return]   ${resp}
22
23 Run Consul Put Request
24     [Documentation]    Runs Consul Tcagen2 Put request
25     [Arguments]    ${data_path}  ${data}
26     ${session}=    Create Session      consul  ${CONSUL_ENDPOINT}
27     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
28     ${resp}=   Put Request     consul  ${data_path}     data=${data}    headers=${headers}
29     Log    Received response from consul ${resp.text}
30     [Return]    ${resp}
31
32 Update Tca ControlLoopName
33     [Arguments]   ${resource_id}
34     ${closedLoopControlName}=    Set Variable    ControlLoop-vFirewall-${resource_id}
35     Log    Obtained closedLoopControlName ${closedLoopControlName}
36     ${resp}=   Run Consul Get Request   /v1/kv/dcae-tcagen2
37     Should Be Equal As Strings  ${resp.status_code}     200
38     ${base64Obj}=   Set Variable    ${resp.json()[0]["Value"]}
39     ${binObj}=   Evaluate   base64.b64decode("${base64Obj}")   modules=base64
40     ${escaped}=   Replace String    ${binObj}   \\   \\\\
41     ${dict}=    Evaluate   json.loads('${escaped}')    json
42     ${tca_policy}=    Set Variable    ${dict['tca.policy']}
43     ${mdf_tca_policy}=    Replace String Using Regexp   ${tca_policy}    ControlLoop-vFirewall[^"]*    ${closedLoopControlName}
44     #Set To Dictionary    ${dict['app_preferences']}    tca_policy=${mdf_tca_policy}
45     Set To Dictionary    ${dict}    tca.policy=${mdf_tca_policy}
46     ${json}=   Evaluate   json.dumps(${dict})     json
47     ${resp}=   Run Consul Put Request   /v1/kv/dcae-tcagen2    data=${json}
48     Should Be Equal As Strings  ${resp.status_code}     200