blob: d5d4e8daa1407cf380be7411f8f3cd204a49f48d [file] [log] [blame]
Michal Ptacek6880b652019-07-08 16:13:02 +02001*** Settings ***
2Documentation The main interface for interacting with Consul.
3Library RequestsLibrary
DR695Hd9794652019-07-19 18:20:40 -04004Library Collections
5Library String
Michal Ptacek6880b652019-07-08 16:13:02 +02006Resource global_properties.robot
7
8*** Variables ***
9${CONSUL_ENDPOINT} http://consul.onap:8500
10
11
12*** Keywords ***
13Run Consul Get Request
14 [Documentation] Runs Consul 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 policy ${resp.text}
20 Should Be Equal As Strings ${resp.status_code} 200
21 [Return] ${resp}
22
23Run Consul Put Request
24 [Documentation] Runs Consul 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
32Update 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-tca-analytics
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['app_preferences']['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 ${json}= Evaluate json.dumps(${dict}) json
46 ${resp}= Run Consul Put Request /v1/kv/dcae-tca-analytics data=${json}
47 Should Be Equal As Strings ${resp.status_code} 200
48