blob: f05f26500cd9ce6988e687128d4d99f0883bb0a8 [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}
13${POLICY_HEALTHCHECK_ENDPOINT} ${GLOBAL_POLICY_SERVER_PROTOCOL}://${GLOBAL_INJECTED_POLICY_IP_ADDR}:${GLOBAL_POLICY_HEALTHCHECK_PORT}
DR695Hccff30b2017-02-17 18:44:24 -050014
15*** Keywords ***
16
17Run Policy Health Check
18 [Documentation] Runs Policy Health check
19 ${auth}= Create List ${GLOBAL_POLICY_USERNAME} ${GLOBAL_POLICY_PASSWORD}
DR695Hbf5a3a32017-06-30 13:09:57 -040020 Log Creating session ${POLICY_ENDPOINT}
21 ${session}= Create Session policy ${POLICY_HEALTHCHECK_ENDPOINT} auth=${auth}
DR695Hccff30b2017-02-17 18:44:24 -050022 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json
23 ${resp}= Get Request policy ${POLICY_HEALTH_CHECK_PATH} headers=${headers}
24 Log Received response from policy ${resp.text}
25 Should Be Equal As Strings ${resp.status_code} 200
26 Should Be True ${resp.json()['healthy']}
27 @{ITEMS}= Copy List ${resp.json()['details']}
28 :FOR ${ELEMENT} IN @{ITEMS}
29 \ Should Be Equal As Strings ${ELEMENT['code']} 200
30 \ Should Be True ${ELEMENT['healthy']}
31
32Run Policy Put Request
33 [Documentation] Runs Policy Put request
34 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040035 Log Creating session ${POLICY_ENDPOINT}
36 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050037 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH} Environment=TEST
38 ${resp}= Put Request policy ${data_path} data=${data} headers=${headers}
39 Log Received response from policy ${resp.text}
40 [Return] ${resp}
41
42Run Policy Delete Request
43 [Documentation] Runs Policy Delete request
44 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040045 Log Creating session ${POLICY_ENDPOINT}
46 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050047 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH} Environment=TEST
48 ${resp}= Delete Request policy ${data_path} data=${data} headers=${headers}
49 Log Received response from policy ${resp.text}
50 [Return] ${resp}
51
52Run Policy Get Configs Request
53 [Documentation] Runs Policy Get Configs request
54 [Arguments] ${data_path} ${data}
DR695Hbf5a3a32017-06-30 13:09:57 -040055 Log Creating session ${POLICY_ENDPOINT}
56 ${session}= Create Session policy ${POLICY_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -050057 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json Authorization=Basic ${GLOBAL_POLICY_AUTH} ClientAuth=${GLOBAL_POLICY_CLIENTAUTH}
58 ${resp}= Post Request policy ${data_path} data=${data} headers=${headers}
59 Log Received response from policy ${resp.text}
Gary Wu76bc74f2018-03-22 13:25:49 -070060 [Return] ${resp}
61
62
63
64Update vVFWCL Policy
65 [Arguments] ${resource_id}
66 Delete vFWCL Policy
67 Sleep 20s
68 Create vFWCL Policy ${resource_id}
69 Sleep 5s
70 Push vFWCL Policy
71 Sleep 20s
72 Reboot Drools
73 Sleep 20s
74 Validate the vFWCL Policy
75
76Delete vFWCL Policy
77 ${data}= OperatingSystem.Get File ${POLICY_TEMPLATES}/FirewallPolicy_delete.template
78 ${resp}= Run Policy Delete Request /pdp/api/deletePolicy ${data}
79 Should Be Equal As Strings ${resp.status_code} 200
80
81Create vFWCL Policy
82 [Arguments] ${resource_id}
83 ${dict}= Create Dictionary RESOURCE_ID=${resource_id}
84 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/FirewallPolicy_update.template ${dict}
85 ${resp}= Run Policy Put Request /pdp/api/updatePolicy ${data}
86 Should Be Equal As Strings ${resp.status_code} 200
87
88Push vFWCL Policy
89 ${dict}= Create Dictionary
90 ${data}= Fill JSON Template File ${POLICY_TEMPLATES}/FirewallPolicy_push.template ${dict}
91 ${resp}= Run Policy Put Request /pdp/api/pushPolicy ${data}
92 Should Be Equal As Strings ${resp.status_code} 200
93
94Reboot Drools
95 ${stop}= Catenate docker exec -t -u policy drools bash -c "source /opt/app/policy/etc/profile.d/env.sh; policy stop"
96 ${start}= Catenate docker exec -t -u policy drools bash -c "source /opt/app/policy/etc/profile.d/env.sh; policy start"
97 Wait Until Keyword Succeeds 120 5 sec Open Connection And Log In ${GLOBAL_INJECTED_POLICY_IP_ADDR} root ${GLOBAL_VM_PRIVATE_KEY}
98 Write ${stop}
99 ${status} ${stdout}= Run Keyword And Ignore Error SSHLibrary.Read Until Regexp has stopped
100 Log ${status}: stdout=${stdout}
101 ${ctrlc}= Evaluate '\x03'
102 Run Keyword If '${status}' == 'FAIL' Write ${ctrlc}
103 Sleep 5s
104 Write ${start}
105 ${stdout}= SSHLibrary.Read Until Regexp is running
106 Log stdout=${stdout}
107 Should Contain ${stdout} is running
108
109Validate the vFWCL Policy
110 ${resp}= Run Drools Get Request /policy/pdp/engine/controllers/amsterdam/drools
111 Should Be Equal As Strings ${resp.status_code} 200
112 ${resp}= Run Drools Get Request /policy/pdp/engine/controllers/amsterdam/drools/facts/closedloop-amsterdam/org.onap.policy.controlloop.Params
113 Should Be Equal As Strings ${resp.status_code} 200