summaryrefslogtreecommitdiffstats
path: root/robot/resources/consul_interface.robot
blob: 5b6f948f669dcce947eb5e898818af049800a71e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
*** Settings ***
Documentation     The main interface for interacting with Consul.
Library           RequestsLibrary
Library           Collections
Library           String
Resource          global_properties.robot

*** Variables ***
${CONSUL_ENDPOINT}              http://consul.onap:8500


*** Keywords ***
Run Consul Get Request
    [Documentation]    Runs Consul Tcagen2 Get Request
    [Arguments]    ${data_path}
    ${session}=    Create Session      consul  ${CONSUL_ENDPOINT}
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
    ${resp}=   Get Request     consul  ${data_path}     headers=${headers}
    Log    Received response from tcagen2 ${resp.text}
    Should Be Equal As Strings         ${resp.status_code}     200
    [Return]   ${resp}

Run Consul Put Request
    [Documentation]    Runs Consul Tcagen2 Put request
    [Arguments]    ${data_path}  ${data}
    ${session}=    Create Session      consul  ${CONSUL_ENDPOINT}
    ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
    ${resp}=   Put Request     consul  ${data_path}     data=${data}    headers=${headers}
    Log    Received response from consul ${resp.text}
    [Return]    ${resp}

Update Tca ControlLoopName
    [Arguments]   ${resource_id}
    ${closedLoopControlName}=    Set Variable    ControlLoop-vFirewall-${resource_id}
    Log    Obtained closedLoopControlName ${closedLoopControlName}
    ${resp}=   Run Consul Get Request   /v1/kv/dcae-tcagen2
    Should Be Equal As Strings  ${resp.status_code}     200
    ${base64Obj}=   Set Variable    ${resp.json()[0]["Value"]}
    ${binObj}=   Evaluate   base64.b64decode("${base64Obj}")   modules=base64
    ${escaped}=   Replace String    ${binObj}   \\   \\\\
    ${dict}=    Evaluate   json.loads('${escaped}')    json
    ${tca_policy}=    Set Variable    ${dict['tca.policy']}
    ${mdf_tca_policy}=    Replace String Using Regexp   ${tca_policy}    ControlLoop-vFirewall[^"]*    ${closedLoopControlName}
    #Set To Dictionary    ${dict['app_preferences']}    tca_policy=${mdf_tca_policy}
    Set To Dictionary    ${dict}    tca.policy=${mdf_tca_policy}
    ${json}=   Evaluate   json.dumps(${dict})     json
    ${resp}=   Run Consul Put Request   /v1/kv/dcae-tcagen2    data=${json}
    Should Be Equal As Strings  ${resp.status_code}     200