DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation The main interface for interacting with Policy. It handles low level stuff like managing the http request library and Policy required fields |
| 3 | Library RequestsClientCert |
| 4 | Library RequestsLibrary |
| 5 | Library String |
| 6 | Library JSONUtils |
| 7 | Library Collections |
| 8 | Resource global_properties.robot |
| 9 | |
| 10 | *** Variables *** |
| 11 | ${POLICY_HEALTH_CHECK_PATH} /healthcheck |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 12 | ${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} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 14 | |
| 15 | *** Keywords *** |
| 16 | |
| 17 | Run Policy Health Check |
| 18 | [Documentation] Runs Policy Health check |
| 19 | ${auth}= Create List ${GLOBAL_POLICY_USERNAME} ${GLOBAL_POLICY_PASSWORD} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 20 | Log Creating session ${POLICY_ENDPOINT} |
| 21 | ${session}= Create Session policy ${POLICY_HEALTHCHECK_ENDPOINT} auth=${auth} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 22 | ${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 | |
| 32 | Run Policy Put Request |
| 33 | [Documentation] Runs Policy Put request |
| 34 | [Arguments] ${data_path} ${data} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 35 | Log Creating session ${POLICY_ENDPOINT} |
| 36 | ${session}= Create Session policy ${POLICY_ENDPOINT} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 37 | ${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 | |
| 42 | Run Policy Delete Request |
| 43 | [Documentation] Runs Policy Delete request |
| 44 | [Arguments] ${data_path} ${data} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 45 | Log Creating session ${POLICY_ENDPOINT} |
| 46 | ${session}= Create Session policy ${POLICY_ENDPOINT} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 47 | ${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 | |
| 52 | Run Policy Get Configs Request |
| 53 | [Documentation] Runs Policy Get Configs request |
| 54 | [Arguments] ${data_path} ${data} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 55 | Log Creating session ${POLICY_ENDPOINT} |
| 56 | ${session}= Create Session policy ${POLICY_ENDPOINT} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 57 | ${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 Wu | 76bc74f | 2018-03-22 13:25:49 -0700 | [diff] [blame^] | 60 | [Return] ${resp} |
| 61 | |
| 62 | |
| 63 | |
| 64 | Update 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 | |
| 76 | Delete 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 | |
| 81 | Create 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 | |
| 88 | Push 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 | |
| 94 | Reboot 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 | |
| 109 | Validate 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 |