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} |
Gary Wu | 251aa68 | 2018-07-30 15:22:20 -0700 | [diff] [blame] | 13 | ${POLICY_HEALTHCHECK_ENDPOINT} ${GLOBAL_POLICY_SERVER_PROTOCOL}://${GLOBAL_INJECTED_POLICY_HEALTHCHECK_IP_ADDR}:${GLOBAL_POLICY_HEALTHCHECK_PORT} |
Brian Freeman | ca5e32e | 2018-07-23 12:47:21 -0500 | [diff] [blame] | 14 | ${POLICY_TEMPLATES} robot/assets/templates/policy |
Brian Freeman | d65e2aa | 2018-07-26 11:13:46 -0500 | [diff] [blame] | 15 | ${DROOLS_ENDPOINT} ${GLOBAL_POLICY_SERVER_PROTOCOL}://${GLOBAL_INJECTED_POLICY_IP_ADDR}:${GLOBAL_DROOLS_SERVER_PORT} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 16 | |
| 17 | *** Keywords *** |
| 18 | |
| 19 | Run Policy Health Check |
| 20 | [Documentation] Runs Policy Health check |
| 21 | ${auth}= Create List ${GLOBAL_POLICY_USERNAME} ${GLOBAL_POLICY_PASSWORD} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 22 | Log Creating session ${POLICY_ENDPOINT} |
| 23 | ${session}= Create Session policy ${POLICY_HEALTHCHECK_ENDPOINT} auth=${auth} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 24 | ${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 Freeman | d65e2aa | 2018-07-26 11:13:46 -0500 | [diff] [blame] | 34 | Run 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 | |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 46 | Run Policy Put Request |
| 47 | [Documentation] Runs Policy Put request |
| 48 | [Arguments] ${data_path} ${data} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 49 | Log Creating session ${POLICY_ENDPOINT} |
| 50 | ${session}= Create Session policy ${POLICY_ENDPOINT} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 51 | ${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 | |
| 56 | Run Policy Delete Request |
| 57 | [Documentation] Runs Policy Delete request |
| 58 | [Arguments] ${data_path} ${data} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 59 | Log Creating session ${POLICY_ENDPOINT} |
| 60 | ${session}= Create Session policy ${POLICY_ENDPOINT} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 61 | ${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 | |
| 66 | Run Policy Get Configs Request |
| 67 | [Documentation] Runs Policy Get Configs request |
| 68 | [Arguments] ${data_path} ${data} |
DR695H | bf5a3a3 | 2017-06-30 13:09:57 -0400 | [diff] [blame] | 69 | Log Creating session ${POLICY_ENDPOINT} |
| 70 | ${session}= Create Session policy ${POLICY_ENDPOINT} |
DR695H | ccff30b | 2017-02-17 18:44:24 -0500 | [diff] [blame] | 71 | ${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 Wu | 76bc74f | 2018-03-22 13:25:49 -0700 | [diff] [blame] | 74 | [Return] ${resp} |
| 75 | |
| 76 | |
| 77 | |
| 78 | Update vVFWCL Policy |
| 79 | [Arguments] ${resource_id} |
Brian Freeman | ca5e32e | 2018-07-23 12:47:21 -0500 | [diff] [blame] | 80 | Run Keyword and Ignore Error Delete vFWCL Policy |
Gary Wu | 76bc74f | 2018-03-22 13:25:49 -0700 | [diff] [blame] | 81 | Sleep 20s |
Brian Freeman | d65e2aa | 2018-07-26 11:13:46 -0500 | [diff] [blame] | 82 | Log To Console Create vFWCL Policy |
Gary Wu | 76bc74f | 2018-03-22 13:25:49 -0700 | [diff] [blame] | 83 | Create vFWCL Policy ${resource_id} |
| 84 | Sleep 5s |
Brian Freeman | d65e2aa | 2018-07-26 11:13:46 -0500 | [diff] [blame] | 85 | Log To Console Push vFWCL Policy |
Gary Wu | 76bc74f | 2018-03-22 13:25:49 -0700 | [diff] [blame] | 86 | Push vFWCL Policy |
| 87 | Sleep 20s |
Brian Freeman | d65e2aa | 2018-07-26 11:13:46 -0500 | [diff] [blame] | 88 | Log To Console Reboot Drools |
Gary Wu | 76bc74f | 2018-03-22 13:25:49 -0700 | [diff] [blame] | 89 | Reboot Drools |
| 90 | Sleep 20s |
Brian Freeman | d65e2aa | 2018-07-26 11:13:46 -0500 | [diff] [blame] | 91 | Log To Console Validate vFWCL Policy |
Gary Wu | 76bc74f | 2018-03-22 13:25:49 -0700 | [diff] [blame] | 92 | Validate the vFWCL Policy |
| 93 | |
| 94 | Delete 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 | |
| 99 | Create 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 | |
| 106 | Push 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 | |
| 112 | Reboot 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 | |
| 127 | Validate 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 |