diff options
author | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2021-08-03 10:14:46 -0400 |
---|---|---|
committer | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2021-08-03 10:14:53 -0400 |
commit | ab96e4d634faa37999c73b968683d4133ab01faa (patch) | |
tree | fa0070f1c9a3d4b2f1e1cb82ed0ae3c921445b9d /csit/pap/tests/pap-test.robot | |
parent | 91888cb1352571e826ced84a9d79cab1f806e037 (diff) |
Refactor pap csit test cases
Refactored pap csit test cases to
* remove code duplication
* create methods for rest call
* improve assertions
* make it easy to add new test cases
Issue-ID: POLICY-3525
Change-Id: I60a5a9128ca6e97044d5de13fb14610d721c78d2
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
Diffstat (limited to 'csit/pap/tests/pap-test.robot')
-rw-r--r-- | csit/pap/tests/pap-test.robot | 252 |
1 files changed, 110 insertions, 142 deletions
diff --git a/csit/pap/tests/pap-test.robot b/csit/pap/tests/pap-test.robot index f31f2426..9b44fe77 100644 --- a/csit/pap/tests/pap-test.robot +++ b/csit/pap/tests/pap-test.robot @@ -1,169 +1,137 @@ *** Settings *** -Library Collections -Library RequestsLibrary -Library OperatingSystem -Library json +Library Collections +Library RequestsLibrary +Library OperatingSystem +Library json *** Test Cases *** LoadPolicy - [Documentation] Loads prerequisite Policy via API - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_API_IP}:6969 - ${session}= Create Session policy https://${POLICY_API_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${postjson}= Get file ${DATA}/vCPE.policy.monitoring.input.tosca.json - ${resp}= POST On Session policy /policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/policies data=${postjson} headers=${headers} - Log Received response from API ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 + [Documentation] Create a policy named 'onap.restart.tca' and version '1.0.0' using specific api + CreatePolicy /policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/policies 200 vCPE.policy.monitoring.input.tosca.json onap.restart.tca 1.0.0 Healthcheck - [Documentation] Verify policy pap health check - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= GET On Session policy /policy/pap/v1/healthcheck headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 - Should Be Equal As Strings ${resp.json()['code']} 200 + [Documentation] Verify policy pap health check + ${resp}= PeformGetRequest /policy/pap/v1/healthcheck 200 null + Should Be Equal As Strings ${resp.json()['code']} 200 Statistics - [Documentation] Verify policy pap statistics - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= GET On Session policy /policy/pap/v1/statistics headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 - Should Be Equal As Strings ${resp.json()['code']} 200 - -CreatePdpGroups - [Documentation] Runs Policy PAP Create PDP Groups - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${postjson}= Get file ${CURDIR}/data/create.group.request.json - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= POST On Session policy /policy/pap/v1/pdps/groups/batch data=${postjson} headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 + [Documentation] Verify policy pap statistics + ${resp}= PeformGetRequest /policy/pap/v1/statistics 200 null + Should Be Equal As Strings ${resp.json()['code']} 200 + +AddPdpGroup + [Documentation] Add a new PdpGroup named 'testGroup' in the policy database + PerformPostRequest ${POLICY_PAP_IP} /policy/pap/v1/pdps/groups/batch 200 create.group.request.json ${CURDIR}/data ActivatePdpGroup - [Documentation] Runs Policy PAP Change PDP Group State to ACTIVE - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= PUT On Session policy /policy/pap/v1/pdps/groups/create.group.request params=state=ACTIVE headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 + [Documentation] Change the state of PdpGroup named 'testGroup' to ACTIVE + PerformPutRequest /policy/pap/v1/pdps/groups/testGroup 200 ACTIVE -QueryPdpGroups - [Documentation] Runs Policy PAP Query PDP Groups - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= GET On Session policy /policy/pap/v1/pdps headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 - Should Be Equal As Strings ${resp.json()['groups'][0]['name']} create.group.request - Should Be Equal As Strings ${resp.json()['groups'][0]['pdpGroupState']} ACTIVE - Should Be Equal As Strings ${resp.json()['groups'][1]['name']} defaultGroup +QueryPdpGroupsAfterActivation + [Documentation] Verify PdpGroups after activation + QueryPdpGroups 2 0 DeployPdpGroups - [Documentation] Runs Policy PAP Deploy Policies to PDP Groups - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${postjson}= Get file ${CURDIR}/data/deploy.group.request.json - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= POST On Session policy /policy/pap/v1/pdps/deployments/batch data=${postjson} headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 202 + [Documentation] Deploy policies in PdpGroups + PerformPostRequest ${POLICY_PAP_IP} /policy/pap/v1/pdps/deployments/batch 202 deploy.group.request.json ${CURDIR}/data + +QueryPdpGroupsAfterDeploy + [Documentation] Verify PdpGroups after undeploy + QueryPdpGroups 2 1 QueryPolicyAuditAfterDeploy - [Documentation] Runs Policy PAP Query Policy Audit after Deploy - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= GET On Session policy /policy/pap/v1/policies/audit params=recordCount=1 headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 - Should Be Equal As Strings ${resp.json()[0]['pdpGroup']} create.group.request - Should Be Equal As Strings ${resp.json()[0]['pdpType']} pdpTypeA - Should Be Equal As Strings ${resp.json()[0]['policy']['name']} onap.restart.tca - Should Be Equal As Strings ${resp.json()[0]['policy']['version']} 1.0.0 - Should Be Equal As Strings ${resp.json()[0]['action']} DEPLOYMENT - Should Be Equal As Strings ${resp.json()[0]['user']} healthcheck + [Documentation] Verify policy audit record after deploy + QueryPolicyAudit /policy/pap/v1/policies/audit 200 DEPLOYMENT UndeployPolicy - [Documentation] Runs Policy PAP Undeploy a Policy from PDP Groups - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= DELETE On Session policy /policy/pap/v1/pdps/policies/onap.restart.tca headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 202 + [Documentation] Undeploy a policy named 'onap.restart.tca' from PdpGroups + PeformDeleteRequest /policy/pap/v1/pdps/policies/onap.restart.tca 202 QueryPdpGroupsAfterUndeploy - [Documentation] Runs Policy PAP Query PDP Groups after Undeploy - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= GET On Session policy /policy/pap/v1/pdps headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 - Should Be Equal As Strings ${resp.json()['groups'][0]['name']} create.group.request - Should Be Equal As Strings ${resp.json()['groups'][0]['pdpSubgroups'][0]['policies']} [] + [Documentation] Verify PdpGroups after undeploy + QueryPdpGroups 2 0 QueryPolicyAuditAfterUnDeploy - [Documentation] Runs Policy PAP Query Policy Audit after Undeploy - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= GET On Session policy /policy/pap/v1/policies/audit params=recordCount=1 headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 - Should Be Equal As Strings ${resp.json()[0]['pdpGroup']} create.group.request - Should Be Equal As Strings ${resp.json()[0]['pdpType']} pdpTypeA - Should Be Equal As Strings ${resp.json()[0]['policy']['name']} onap.restart.tca - Should Be Equal As Strings ${resp.json()[0]['policy']['version']} 1.0.0 - Should Be Equal As Strings ${resp.json()[0]['action']} UNDEPLOYMENT - Should Be Equal As Strings ${resp.json()[0]['user']} healthcheck + [Documentation] Verify policy audit record after undeploy + QueryPolicyAudit /policy/pap/v1/policies/audit 200 UNDEPLOYMENT DeactivatePdpGroup - [Documentation] Runs Policy PAP Change PDP Group State to PASSIVE - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= PUT On Session policy /policy/pap/v1/pdps/groups/create.group.request params=state=PASSIVE headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 + [Documentation] Change the state of PdpGroup named 'testGroup' to PASSIVE + PerformPutRequest /policy/pap/v1/pdps/groups/testGroup 200 PASSIVE DeletePdpGroups - [Documentation] Runs Policy PAP Delete PDP Groups - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= DELETE On Session policy /policy/pap/v1/pdps/groups/create.group.request headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 + [Documentation] Delete the PdpGroup named 'testGroup' from policy database + PeformDeleteRequest /policy/pap/v1/pdps/groups/testGroup 200 QueryPdpGroupsAfterDelete - [Documentation] Runs Policy PAP Query PDP Groups after Delete - ${auth}= Create List healthcheck zb!XztG34 - Log Creating session https://${POLICY_PAP_IP}:6969 - ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} - ${headers}= Create Dictionary Accept=application/json Content-Type=application/json - ${resp}= GET On Session policy /policy/pap/v1/pdps headers=${headers} - Log Received response from policy ${resp.text} - Should Be Equal As Strings ${resp.status_code} 200 - Should Be Equal As Strings ${resp.json()['groups'][0]['name']} defaultGroup + [Documentation] Verify PdpGroups after delete + QueryPdpGroups 1 0 + +*** Keywords *** + +CreatePolicy + [Arguments] ${url} ${expectedstatus} ${jsonfile} ${policyname} ${policyversion} + [Documentation] Create the specific policy + ${resp}= PerformPostRequest ${POLICY_API_IP} ${url} ${expectedstatus} ${jsonfile} ${DATA} + Run Keyword If ${expectedstatus}==200 Dictionary Should Contain Key ${resp.json()['topology_template']['policies'][0]} ${policyname} + Run Keyword If ${expectedstatus}==200 Should Be Equal As Strings ${resp.json()['topology_template']['policies'][0]['${policyname}']['version']} ${policyversion} + +QueryPdpGroups + [Arguments] ${groupsLength} ${policiesLength} + ${resp}= PeformGetRequest /policy/pap/v1/pdps 200 null + Length Should Be ${resp.json()['groups']} ${groupsLength} + Should Be Equal As Strings ${resp.json()['groups'][0]['name']} defaultGroup + Should Be Equal As Strings ${resp.json()['groups'][0]['pdpGroupState']} ACTIVE + Run Keyword If ${groupsLength}>1 Should Be Equal As Strings ${resp.json()['groups'][1]['name']} testGroup + Run Keyword If ${groupsLength}>1 Should Be Equal As Strings ${resp.json()['groups'][1]['pdpGroupState']} ACTIVE + Run Keyword If ${groupsLength}>1 Length Should Be ${resp.json()['groups'][1]['pdpSubgroups'][0]['policies']} ${policiesLength} + +QueryPolicyAudit + [Arguments] ${url} ${expectedstatus} ${expectedAction} + ${resp}= PeformGetRequest ${url} ${expectedstatus} recordCount=1 + Should Be Equal As Strings ${resp.json()[0]['pdpGroup']} testGroup + Should Be Equal As Strings ${resp.json()[0]['pdpType']} pdpTypeA + Should Be Equal As Strings ${resp.json()[0]['policy']['name']} onap.restart.tca + Should Be Equal As Strings ${resp.json()[0]['policy']['version']} 1.0.0 + Should Be Equal As Strings ${resp.json()[0]['action']} ${expectedAction} + Should Be Equal As Strings ${resp.json()[0]['user']} healthcheck + +PerformPostRequest + [Arguments] ${hostname} ${url} ${expectedstatus} ${jsonfile} ${filepath} + ${auth}= Create List healthcheck zb!XztG34 + ${postjson}= Get file ${filepath}/${jsonfile} + Log Creating session https://${hostname}:6969 + ${session}= Create Session policy https://${hostname}:6969 auth=${auth} + ${headers}= Create Dictionary Accept=application/json Content-Type=application/json + ${resp}= POST On Session policy ${url} data=${postjson} headers=${headers} expected_status=${expectedstatus} + Log Received response from policy ${resp.text} + [return] ${resp} + +PerformPutRequest + [Arguments] ${url} ${expectedstatus} ${state} + ${auth}= Create List healthcheck zb!XztG34 + Log Creating session https://${POLICY_PAP_IP}:6969 + ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} + ${headers}= Create Dictionary Accept=application/json Content-Type=application/json + ${resp}= PUT On Session policy ${url} params=state=${state} headers=${headers} expected_status=${expectedstatus} + Log Received response from policy ${resp.text} + [return] ${resp} + +PeformGetRequest + [Arguments] ${url} ${expectedstatus} ${params} + ${auth}= Create List healthcheck zb!XztG34 + Log Creating session https://${POLICY_PAP_IP}:6969 + ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} + ${headers}= Create Dictionary Accept=application/json Content-Type=application/json + ${resp}= GET On Session policy ${url} params=${params} headers=${headers} expected_status=${expectedstatus} + Log Received response from policy ${resp.text} + [return] ${resp} + +PeformDeleteRequest + [Arguments] ${url} ${expectedstatus} + ${auth}= Create List healthcheck zb!XztG34 + Log Creating session https://${POLICY_PAP_IP}:6969 + ${session}= Create Session policy https://${POLICY_PAP_IP}:6969 auth=${auth} + ${headers}= Create Dictionary Accept=application/json Content-Type=application/json + ${resp}= DELETE On Session policy ${url} headers=${headers} expected_status=${expectedstatus} + Log Received response from policy ${resp.text} |