blob: 00f4334bebd134d5ca5e405281523b75039d51b8 [file] [log] [blame]
Michal Ptacek6880b652019-07-08 16:13:02 +02001*** Settings ***
2Documentation The main interface for interacting with Consul.
3Library RequestsLibrary
4
5Resource global_properties.robot
6
7*** Variables ***
8${CONSUL_ENDPOINT} http://consul.onap:8500
9
10
11*** Keywords ***
12Run Consul Get Request
13 [Documentation] Runs Consul Get Request
14 [Arguments] ${data_path}
15 ${session}= Create Session consul ${CONSUL_ENDPOINT}
16 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json
17 ${resp}= Get Request consul ${data_path} headers=${headers}
18 Log Received response from policy ${resp.text}
19 Should Be Equal As Strings ${resp.status_code} 200
20 [Return] ${resp}
21
22Run Consul Put Request
23 [Documentation] Runs Consul Put request
24 [Arguments] ${data_path} ${data}
25 ${session}= Create Session consul ${CONSUL_ENDPOINT}
26 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json
27 ${resp}= Put Request consul ${data_path} data=${data} headers=${headers}
28 Log Received response from consul ${resp.text}
29 [Return] ${resp}
30
31Update Tca ControlLoopName
32 [Arguments] ${resource_id}
33 ${closedLoopControlName}= Set Variable ControlLoop-vFirewall-${resource_id}
34 Log Obtained closedLoopControlName ${closedLoopControlName}
35 ${resp}= Run Consul Get Request /v1/kv/dcae-tca-analytics
36 Should Be Equal As Strings ${resp.status_code} 200
37 ${base64Obj}= Set Variable ${resp.json()[0]["Value"]}
38 ${binObj}= Evaluate base64.b64decode("${base64Obj}") modules=base64
39 ${escaped}= Replace String ${binObj} \\ \\\\
40 ${dict}= Evaluate json.loads('${escaped}') json
41 ${tca_policy}= Set Variable ${dict['app_preferences']['tca_policy']}
42 ${mdf_tca_policy}= Replace String Using Regexp ${tca_policy} ControlLoop-vFirewall[^"]* ${closedLoopControlName}
43 Set To Dictionary ${dict['app_preferences']} tca_policy=${mdf_tca_policy}
44 ${json}= Evaluate json.dumps(${dict}) json
45 ${resp}= Run Consul Put Request /v1/kv/dcae-tca-analytics data=${json}
46 Should Be Equal As Strings ${resp.status_code} 200
47