blob: 8bbbb62a8e92c601300d9ee22f298bc759409afb [file] [log] [blame]
DR695Hccff30b2017-02-17 18:44:24 -05001*** Settings ***
2Documentation The main interface for interacting with Policy. It handles low level stuff like managing the http request library and Policy required fields
3Library RequestsClientCert
4Library RequestsLibrary
5Library String
6Library JSONUtils
7Library Collections
8Resource global_properties.robot
9
10*** Variables ***
11${POLICY_HEALTH_CHECK_PATH} /healthcheck
DR695Hbf5a3a32017-06-30 13:09:57 -040012${POLICY_ENDPOINT} ${GLOBAL_POLICY_SERVER_PROTOCOL}://${GLOBAL_INJECTED_POLICY_IP_ADDR}:${GLOBAL_POLICY_SERVER_PORT}
Gary Wu251aa682018-07-30 15:22:20 -070013${POLICY_HEALTHCHECK_ENDPOINT} ${GLOBAL_POLICY_SERVER_PROTOCOL}://${GLOBAL_INJECTED_POLICY_HEALTHCHECK_IP_ADDR}:${GLOBAL_POLICY_HEALTHCHECK_PORT}
Brian Freemanca5e32e2018-07-23 12:47:21 -050014${POLICY_TEMPLATES} robot/assets/templates/policy
Brian Freemand65e2aa2018-07-26 11:13:46 -050015${DROOLS_ENDPOINT} ${GLOBAL_POLICY_SERVER_PROTOCOL}://${GLOBAL_INJECTED_POLICY_IP_ADDR}:${GLOBAL_DROOLS_SERVER_PORT}
DR695Hccff30b2017-02-17 18:44:24 -050016
17*** Keywords ***
18
19Run Policy Health Check
20 [Documentation] Runs Policy Health check
21 ${auth}= Create List ${GLOBAL_POLICY_USERNAME} ${GLOBAL_POLICY_PASSWORD}
DR695Hbf5a3a32017-06-30 13:09:57 -040022 Log Creating session ${POLICY_ENDPOINT}
23 ${session}= Create Session policy ${POLICY_HEALTHCHECK_ENDPOINT} auth=${auth}
DR695Hccff30b2017-02-17 18:44:24 -050024 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json
25 ${resp}= Get Request policy ${POLICY_HEALTH_CHECK_PATH} headers=${headers}
26 Log Received response from policy ${resp.text}
27 Should Be Equal As Strings ${resp.status_code} 200
28 Should Be True ${resp.json()['healthy']}
29 @{ITEMS}= Copy List ${resp.json()['details']}
30 :FOR ${ELEMENT} IN @{ITEMS}
31 \ Should Be Equal As Strings ${ELEMENT['code']} 200
32 \ Should Be True ${ELEMENT['healthy']}
33
Brian Freemand65e2aa2018-07-26 11:13:46 -050034Run Drools Get Request
35 [Documentation] Runs Drools Get Request
36 [Arguments] ${data_path}
37 ${auth}= Create List ${GLOBAL_DROOLS_USERNAME} ${GLOBAL_DROOLS_PASSWORD}
38 Log Creating session ${POLICY_ENDPOINT}
39 ${session}= Create Session policy ${DROOLS_ENDPOINT} auth=${auth}
40 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json
41 ${resp}= Get Request policy ${data_path} headers=${headers}
42 Log Received response from policy ${resp.text}
43 Should Be Equal As Strings ${resp.status_code} 200
44 [Return] ${resp}
45
DR695Hccff30b2017-02-17 18:44:24 -050046Run Policy Put Request
47 [Documentation] Runs Policy Put request
48 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040049 Log Creating session ${POLICY_ENDPOINT}
50 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050051 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH} Environment=TEST
52 ${resp}= Put Request policy ${data_path} data=${data} headers=${headers}
53 Log Received response from policy ${resp.text}
54 [Return] ${resp}
Brian Freemane14d2572019-04-29 16:20:21 -050055
56Run Policy Post Request
57 [Documentation] Runs Policy Post request
58 [Arguments] ${data_path} ${data}
59 Log Creating session ${POLICY_ENDPOINT}
60 ${session}= Create Session policy ${POLICY_ENDPOINT}
61 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH} Environment=TEST
62 ${resp}= Post Request policy ${data_path} data=${data} headers=${headers}
63 Log Received response from policy ${resp.text}
64 [Return] ${resp}
DR695Hccff30b2017-02-17 18:44:24 -050065
66Run Policy Delete Request
67 [Documentation] Runs Policy Delete request
68 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040069 Log Creating session ${POLICY_ENDPOINT}
70 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050071 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH} Environment=TEST
72 ${resp}= Delete Request policy ${data_path} data=${data} headers=${headers}
73 Log Received response from policy ${resp.text}
74 [Return] ${resp}
75
76Run Policy Get Configs Request
77 [Documentation] Runs Policy Get Configs request
78 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040079 Log Creating session ${POLICY_ENDPOINT}
80 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050081 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH}
82 ${resp}= Post Request policy ${data_path} data=${data} headers=${headers}
83 Log Received response from policy ${resp.text}
Gary Wu76bc74f2018-03-22 13:25:49 -070084 [Return] ${resp}
85
86
87
88Update vVFWCL Policy
89 [Arguments] ${resource_id}
Brian Freemanca5e32e2018-07-23 12:47:21 -050090 Run Keyword and Ignore Error Delete vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -070091 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -050092 Log To Console Create vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -070093 Create vFWCL Policy ${resource_id}
94 Sleep 5s
Brian Freemand65e2aa2018-07-26 11:13:46 -050095 Log To Console Push vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -070096 Push vFWCL Policy
97 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -050098 Log To Console Reboot Drools
Gary Wu76bc74f2018-03-22 13:25:49 -070099 Reboot Drools
100 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -0500101 Log To Console Validate vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -0700102 Validate the vFWCL Policy
103
104Delete vFWCL Policy
105 ${data}= OperatingSystem.Get File ${POLICY_TEMPLATES}/FirewallPolicy_delete.template
106 ${resp}= Run Policy Delete Request /pdp/api/deletePolicy ${data}
107 Should Be Equal As Strings ${resp.status_code} 200
108
109Create vFWCL Policy
110 [Arguments] ${resource_id}
111 ${dict}= Create Dictionary RESOURCE_ID=${resource_id}
112 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/FirewallPolicy_update.template ${dict}
113 ${resp}= Run Policy Put Request /pdp/api/updatePolicy ${data}
114 Should Be Equal As Strings ${resp.status_code} 200
115
116Push vFWCL Policy
117 ${dict}= Create Dictionary
118 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/FirewallPolicy_push.template ${dict}
119 ${resp}= Run Policy Put Request /pdp/api/pushPolicy ${data}
120 Should Be Equal As Strings ${resp.status_code} 200
121
122Reboot Drools
123 ${stop}= Catenate docker exec -t -u policy drools bash -c "source /opt/app/policy/etc/profile.d/env.sh; policy stop"
124 ${start}= Catenate docker exec -t -u policy drools bash -c "source /opt/app/policy/etc/profile.d/env.sh; policy start"
125 Wait Until Keyword Succeeds 120 5 sec Open Connection And Log In ${GLOBAL_INJECTED_POLICY_IP_ADDR} root ${GLOBAL_VM_PRIVATE_KEY}
126 Write ${stop}
127 ${status} ${stdout}= Run Keyword And Ignore Error SSHLibrary.Read Until Regexp has stopped
128 Log ${status}: stdout=${stdout}
129 ${ctrlc}= Evaluate '\x03'
130 Run Keyword If '${status}' == 'FAIL' Write ${ctrlc}
131 Sleep 5s
132 Write ${start}
133 ${stdout}= SSHLibrary.Read Until Regexp is running
134 Log stdout=${stdout}
135 Should Contain ${stdout} is running
136
137Validate the vFWCL Policy
138 ${resp}= Run Drools Get Request /policy/pdp/engine/controllers/amsterdam/drools
139 Should Be Equal As Strings ${resp.status_code} 200
140 ${resp}= Run Drools Get Request /policy/pdp/engine/controllers/amsterdam/drools/facts/closedloop-amsterdam/org.onap.policy.controlloop.Params
141 Should Be Equal As Strings ${resp.status_code} 200
Brian Freemane14d2572019-04-29 16:20:21 -0500142
143
144Create vFirewall Monitoring Policy
145 ${dict}= Create Dictionary
146 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/vFirewall_policy_monitoring_input_tosca.template ${dict}
147 ${resp}= Run Policy Post Request /policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies ${data}
148 Should Be Equal As Strings ${resp.status_code} 200
149
150
151Create vFirewall Operational Policy
152 [Arguments] ${resource_id}
153 ${dict}= Create Dictionary RESOURCE_ID=${resource_id}
154 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/vFirewall_policy_operational_input.template ${dict}
155 ${resp}= Run Policy Post Request /policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies ${data}
156 Should Be Equal As Strings ${resp.status_code} 200
157
158
159Push vFirewall Policies To PDP Group
160 ${dict}= Create Dictionary
161 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/vFirewall_push.template ${dict}
162 ${resp}= Run Policy Post Request /policy/pap/v1/pdps/policies ${data}
163 Should Be Equal As Strings ${resp.status_code} 200
164