blob: 5b6f948f669dcce947eb5e898818af049800a71e [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
Brian Freemanfcfe34d2020-12-01 15:38:15 -050014 [Documentation] Runs Consul Tcagen2 Get Request
Michal Ptacek6880b652019-07-08 16:13:02 +020015 [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}
Brian Freemanfcfe34d2020-12-01 15:38:15 -050019 Log Received response from tcagen2 ${resp.text}
Michal Ptacek6880b652019-07-08 16:13:02 +020020 Should Be Equal As Strings ${resp.status_code} 200
21 [Return] ${resp}
22
23Run Consul Put Request
Brian Freemanfcfe34d2020-12-01 15:38:15 -050024 [Documentation] Runs Consul Tcagen2 Put request
Michal Ptacek6880b652019-07-08 16:13:02 +020025 [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}
Brian Freemanfcfe34d2020-12-01 15:38:15 -050036 ${resp}= Run Consul Get Request /v1/kv/dcae-tcagen2
Michal Ptacek6880b652019-07-08 16:13:02 +020037 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
Brian Freemanfcfe34d2020-12-01 15:38:15 -050042 ${tca_policy}= Set Variable ${dict['tca.policy']}
Michal Ptacek6880b652019-07-08 16:13:02 +020043 ${mdf_tca_policy}= Replace String Using Regexp ${tca_policy} ControlLoop-vFirewall[^"]* ${closedLoopControlName}
Brian Freemanfcfe34d2020-12-01 15:38:15 -050044 #Set To Dictionary ${dict['app_preferences']} tca_policy=${mdf_tca_policy}
45 Set To Dictionary ${dict} tca.policy=${mdf_tca_policy}
Michal Ptacek6880b652019-07-08 16:13:02 +020046 ${json}= Evaluate json.dumps(${dict}) json
Brian Freemanfcfe34d2020-12-01 15:38:15 -050047 ${resp}= Run Consul Put Request /v1/kv/dcae-tcagen2 data=${json}
Michal Ptacek6880b652019-07-08 16:13:02 +020048 Should Be Equal As Strings ${resp.status_code} 200