Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation The main interface for interacting with Consul. |
| 3 | Library RequestsLibrary |
DR695H | d979465 | 2019-07-19 18:20:40 -0400 | [diff] [blame] | 4 | Library Collections |
| 5 | Library String |
Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 6 | Resource global_properties.robot |
| 7 | |
| 8 | *** Variables *** |
| 9 | ${CONSUL_ENDPOINT} http://consul.onap:8500 |
| 10 | |
| 11 | |
| 12 | *** Keywords *** |
| 13 | Run Consul Get Request |
Brian Freeman | fcfe34d | 2020-12-01 15:38:15 -0500 | [diff] [blame] | 14 | [Documentation] Runs Consul Tcagen2 Get Request |
Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 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} |
Brian Freeman | fcfe34d | 2020-12-01 15:38:15 -0500 | [diff] [blame] | 19 | Log Received response from tcagen2 ${resp.text} |
Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 20 | Should Be Equal As Strings ${resp.status_code} 200 |
| 21 | [Return] ${resp} |
| 22 | |
| 23 | Run Consul Put Request |
Brian Freeman | fcfe34d | 2020-12-01 15:38:15 -0500 | [diff] [blame] | 24 | [Documentation] Runs Consul Tcagen2 Put request |
Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 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} |
Brian Freeman | fcfe34d | 2020-12-01 15:38:15 -0500 | [diff] [blame] | 36 | ${resp}= Run Consul Get Request /v1/kv/dcae-tcagen2 |
Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 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 |
Brian Freeman | fcfe34d | 2020-12-01 15:38:15 -0500 | [diff] [blame] | 42 | ${tca_policy}= Set Variable ${dict['tca.policy']} |
Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 43 | ${mdf_tca_policy}= Replace String Using Regexp ${tca_policy} ControlLoop-vFirewall[^"]* ${closedLoopControlName} |
Brian Freeman | fcfe34d | 2020-12-01 15:38:15 -0500 | [diff] [blame] | 44 | #Set To Dictionary ${dict['app_preferences']} tca_policy=${mdf_tca_policy} |
| 45 | Set To Dictionary ${dict} tca.policy=${mdf_tca_policy} |
Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 46 | ${json}= Evaluate json.dumps(${dict}) json |
Brian Freeman | fcfe34d | 2020-12-01 15:38:15 -0500 | [diff] [blame] | 47 | ${resp}= Run Consul Put Request /v1/kv/dcae-tcagen2 data=${json} |
Michal Ptacek | 6880b65 | 2019-07-08 16:13:02 +0200 | [diff] [blame] | 48 | Should Be Equal As Strings ${resp.status_code} 200 |