blob: 6f48e4fce32b28c03bb695e83047377e1ac39086 [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}
55
56Run Policy Delete Request
57 [Documentation] Runs Policy Delete request
58 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040059 Log Creating session ${POLICY_ENDPOINT}
60 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050061 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH} Environment=TEST
62 ${resp}= Delete Request policy ${data_path} data=${data} headers=${headers}
63 Log Received response from policy ${resp.text}
64 [Return] ${resp}
65
66Run Policy Get Configs Request
67 [Documentation] Runs Policy Get Configs 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}
72 ${resp}= Post Request policy ${data_path} data=${data} headers=${headers}
73 Log Received response from policy ${resp.text}
Gary Wu76bc74f2018-03-22 13:25:49 -070074 [Return] ${resp}
75
76
77
78Update vVFWCL Policy
79 [Arguments] ${resource_id}
Brian Freemanca5e32e2018-07-23 12:47:21 -050080 Run Keyword and Ignore Error Delete vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -070081 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -050082 Log To Console Create vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -070083 Create vFWCL Policy ${resource_id}
84 Sleep 5s
Brian Freemand65e2aa2018-07-26 11:13:46 -050085 Log To Console Push vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -070086 Push vFWCL Policy
87 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -050088 Log To Console Reboot Drools
Gary Wu76bc74f2018-03-22 13:25:49 -070089 Reboot Drools
90 Sleep 20s
Brian Freemand65e2aa2018-07-26 11:13:46 -050091 Log To Console Validate vFWCL Policy
Gary Wu76bc74f2018-03-22 13:25:49 -070092 Validate the vFWCL Policy
93
94Delete vFWCL Policy
95 ${data}= OperatingSystem.Get File ${POLICY_TEMPLATES}/FirewallPolicy_delete.template
96 ${resp}= Run Policy Delete Request /pdp/api/deletePolicy ${data}
97 Should Be Equal As Strings ${resp.status_code} 200
98
99Create vFWCL Policy
100 [Arguments] ${resource_id}
101 ${dict}= Create Dictionary RESOURCE_ID=${resource_id}
102 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/FirewallPolicy_update.template ${dict}
103 ${resp}= Run Policy Put Request /pdp/api/updatePolicy ${data}
104 Should Be Equal As Strings ${resp.status_code} 200
105
106Push vFWCL Policy
107 ${dict}= Create Dictionary
108 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/FirewallPolicy_push.template ${dict}
109 ${resp}= Run Policy Put Request /pdp/api/pushPolicy ${data}
110 Should Be Equal As Strings ${resp.status_code} 200
111
112Reboot Drools
113 ${stop}= Catenate docker exec -t -u policy drools bash -c "source /opt/app/policy/etc/profile.d/env.sh; policy stop"
114 ${start}= Catenate docker exec -t -u policy drools bash -c "source /opt/app/policy/etc/profile.d/env.sh; policy start"
115 Wait Until Keyword Succeeds 120 5 sec Open Connection And Log In ${GLOBAL_INJECTED_POLICY_IP_ADDR} root ${GLOBAL_VM_PRIVATE_KEY}
116 Write ${stop}
117 ${status} ${stdout}= Run Keyword And Ignore Error SSHLibrary.Read Until Regexp has stopped
118 Log ${status}: stdout=${stdout}
119 ${ctrlc}= Evaluate '\x03'
120 Run Keyword If '${status}' == 'FAIL' Write ${ctrlc}
121 Sleep 5s
122 Write ${start}
123 ${stdout}= SSHLibrary.Read Until Regexp is running
124 Log stdout=${stdout}
125 Should Contain ${stdout} is running
126
127Validate the vFWCL Policy
128 ${resp}= Run Drools Get Request /policy/pdp/engine/controllers/amsterdam/drools
129 Should Be Equal As Strings ${resp.status_code} 200
130 ${resp}= Run Drools Get Request /policy/pdp/engine/controllers/amsterdam/drools/facts/closedloop-amsterdam/org.onap.policy.controlloop.Params
131 Should Be Equal As Strings ${resp.status_code} 200