blob: 91d0d98b41692b9cf71d66cdbb231afb98bd317b [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
Brian Freemanc967dd62019-04-30 09:47:44 -050056Run Policy Get Request
57 [Documentation] Runs Policy Get request
58 [Arguments] ${data_path}
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}= Get Request policy ${data_path} headers=${headers}
63 Log Received response from policy ${resp.text}
64
Brian Freemane14d2572019-04-29 16:20:21 -050065Run Policy Post Request
66 [Documentation] Runs Policy Post request
67 [Arguments] ${data_path} ${data}
68 Log Creating session ${POLICY_ENDPOINT}
69 ${session}= Create Session policy ${POLICY_ENDPOINT}
70 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH} Environment=TEST
71 ${resp}= Post Request policy ${data_path} data=${data} headers=${headers}
72 Log Received response from policy ${resp.text}
73 [Return] ${resp}
Brian Freemanc967dd62019-04-30 09:47:44 -050074
DR695Hccff30b2017-02-17 18:44:24 -050075Run Policy Delete Request
76 [Documentation] Runs Policy Delete request
77 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040078 Log Creating session ${POLICY_ENDPOINT}
79 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050080 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH} Environment=TEST
81 ${resp}= Delete Request policy ${data_path} data=${data} headers=${headers}
82 Log Received response from policy ${resp.text}
83 [Return] ${resp}
84
85Run Policy Get Configs Request
86 [Documentation] Runs Policy Get Configs request
87 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040088 Log Creating session ${POLICY_ENDPOINT}
89 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050090 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH}
91 ${resp}= Post Request policy ${data_path} data=${data} headers=${headers}
92 Log Received response from policy ${resp.text}
Gary Wu76bc74f2018-03-22 13:25:49 -070093 [Return] ${resp}
94
95
96
Brian Freemanc967dd62019-04-30 09:47:44 -050097Update vVFWCL Policy Old
Gary Wu76bc74f2018-03-22 13:25:49 -070098 [Arguments] ${resource_id}
Brian Freemanca5e32e2018-07-23 12:47:21 -050099 Run Keyword and Ignore Error Delete vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -0700100 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -0500101 Log To Console Create vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -0700102 Create vFWCL Policy ${resource_id}
103 Sleep 5s
Brian Freemand65e2aa2018-07-26 11:13:46 -0500104 Log To Console Push vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -0700105 Push vFWCL Policy
106 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -0500107 Log To Console Reboot Drools
Gary Wu76bc74f2018-03-22 13:25:49 -0700108 Reboot Drools
109 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -0500110 Log To Console Validate vFWCL Policy
Brian Freemanc967dd62019-04-30 09:47:44 -0500111 Validate the vFWCL Policy Old
112
113Update vVFWCL Policy
114 [Arguments] ${resource_id}
115 Log To Console Create vFWCL Monitoring Policy
116 Create vFirewall Monitoring Policy
117 Sleep 5s
118 Log To Console Create vFWCL Operational Policy
119 Create vFirewall Operational Policy ${resource_id}
120 Sleep 5s
121 Log To Console Push vFWCL To PDP Group
122 Push vFirewall Policies To PDP Group
123 Sleep 20s
124 Log To Console Validate vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -0700125 Validate the vFWCL Policy
126
Brian Freemanc967dd62019-04-30 09:47:44 -0500127
Gary Wu76bc74f2018-03-22 13:25:49 -0700128Delete vFWCL Policy
129 ${data}= OperatingSystem.Get File ${POLICY_TEMPLATES}/FirewallPolicy_delete.template
130 ${resp}= Run Policy Delete Request /pdp/api/deletePolicy ${data}
131 Should Be Equal As Strings ${resp.status_code} 200
132
133Create vFWCL Policy
134 [Arguments] ${resource_id}
135 ${dict}= Create Dictionary RESOURCE_ID=${resource_id}
136 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/FirewallPolicy_update.template ${dict}
137 ${resp}= Run Policy Put Request /pdp/api/updatePolicy ${data}
138 Should Be Equal As Strings ${resp.status_code} 200
139
140Push vFWCL Policy
141 ${dict}= Create Dictionary
142 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/FirewallPolicy_push.template ${dict}
143 ${resp}= Run Policy Put Request /pdp/api/pushPolicy ${data}
144 Should Be Equal As Strings ${resp.status_code} 200
145
146Reboot Drools
147 ${stop}= Catenate docker exec -t -u policy drools bash -c "source /opt/app/policy/etc/profile.d/env.sh; policy stop"
148 ${start}= Catenate docker exec -t -u policy drools bash -c "source /opt/app/policy/etc/profile.d/env.sh; policy start"
149 Wait Until Keyword Succeeds 120 5 sec Open Connection And Log In ${GLOBAL_INJECTED_POLICY_IP_ADDR} root ${GLOBAL_VM_PRIVATE_KEY}
150 Write ${stop}
151 ${status} ${stdout}= Run Keyword And Ignore Error SSHLibrary.Read Until Regexp has stopped
152 Log ${status}: stdout=${stdout}
153 ${ctrlc}= Evaluate '\x03'
154 Run Keyword If '${status}' == 'FAIL' Write ${ctrlc}
155 Sleep 5s
156 Write ${start}
157 ${stdout}= SSHLibrary.Read Until Regexp is running
158 Log stdout=${stdout}
159 Should Contain ${stdout} is running
160
Brian Freemanc967dd62019-04-30 09:47:44 -0500161Validate the vFWCL Policy Old
Gary Wu76bc74f2018-03-22 13:25:49 -0700162 ${resp}= Run Drools Get Request /policy/pdp/engine/controllers/amsterdam/drools
163 Should Be Equal As Strings ${resp.status_code} 200
164 ${resp}= Run Drools Get Request /policy/pdp/engine/controllers/amsterdam/drools/facts/closedloop-amsterdam/org.onap.policy.controlloop.Params
165 Should Be Equal As Strings ${resp.status_code} 200
Brian Freemane14d2572019-04-29 16:20:21 -0500166
Brian Freemanc967dd62019-04-30 09:47:44 -0500167Validate the vFWCL Policy
168 ${resp}= Run Policy Get Request /policy/pap/v1/pdps
169 Log Received response from policy ${resp.text}
170 Should Be Equal As Strings ${resp.status_code} 200
Brian Freemane14d2572019-04-29 16:20:21 -0500171
172Create vFirewall Monitoring Policy
173 ${dict}= Create Dictionary
174 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/vFirewall_policy_monitoring_input_tosca.template ${dict}
175 ${resp}= Run Policy Post Request /policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies ${data}
176 Should Be Equal As Strings ${resp.status_code} 200
177
178
179Create vFirewall Operational Policy
180 [Arguments] ${resource_id}
181 ${dict}= Create Dictionary RESOURCE_ID=${resource_id}
182 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/vFirewall_policy_operational_input.template ${dict}
183 ${resp}= Run Policy Post Request /policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies ${data}
184 Should Be Equal As Strings ${resp.status_code} 200
185
186
187Push vFirewall Policies To PDP Group
188 ${dict}= Create Dictionary
189 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/vFirewall_push.template ${dict}
190 ${resp}= Run Policy Post Request /policy/pap/v1/pdps/policies ${data}
191 Should Be Equal As Strings ${resp.status_code} 200
192