Refactor policy/xacml-pdp csit tests
[policy/xacml-pdp.git] / csit / tests / xacml-pdp-test.robot
1 *** Settings ***
2 Library     Collections
3 Library     RequestsLibrary
4 Library     OperatingSystem
5 Library     Process
6 Library     json
7
8 *** Test Cases ***
9 Healthcheck
10      [Documentation]  Verify policy xacml-pdp health check
11      ${resp}=  PeformGetRequest  /policy/pdpx/v1/healthcheck  200
12      Should Be Equal As Strings    ${resp.json()['code']}  200
13
14 Statistics
15      [Documentation]  Verify policy xacml-pdp statistics
16      ${resp}=  PeformGetRequest  /policy/pdpx/v1/statistics  200
17      Should Be Equal As Strings    ${resp.json()['code']}  200
18
19 MakeTopics
20      [Documentation]    Creates the Policy topics
21      ${result}=     Run Process     ${SCR_DMAAP}/make_topic.sh   POLICY-PDP-PAP
22      Should Be Equal As Integers        ${result.rc}    0
23
24 ExecuteXacmlPolicy
25      Wait Until Keyword Succeeds    0 min   15 sec  CreateMonitorPolicy
26      Wait Until Keyword Succeeds    0 min   15 sec  CreateOptimizationPolicy
27      Wait Until Keyword Succeeds    0 min   15 sec  GetDefaultDecision
28      Wait Until Keyword Succeeds    0 min   15 sec  DeployPolicies
29      Wait Until Keyword Succeeds    0 min   15 sec  GetStatisticsAfterDeployed
30      Wait Until Keyword Succeeds    0 min   15 sec  GetAbbreviatedDecisionResult
31      Wait Until Keyword Succeeds    0 min   15 sec  GetMonitoringDecision
32      Wait Until Keyword Succeeds    0 min   15 sec  GetNamingDecision
33      Wait Until Keyword Succeeds    0 min   15 sec  GetOptimizationDecision
34      Wait Until Keyword Succeeds    0 min   15 sec  GetStatisticsAfterDecision
35      Wait Until Keyword Succeeds    0 min   15 sec  UndeployMonitorPolicy
36      Wait Until Keyword Succeeds    0 min   15 sec  GetStatisticsAfterUndeploy
37
38 *** Keywords ***
39
40 CreateMonitorPolicy
41      [Documentation]  Create a Monitoring policy
42      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
43
44 CreateOptimizationPolicy
45      [Documentation]  Create an Optimization policy
46      CreatePolicy  /policy/api/v1/policytypes/onap.policies.optimization.resource.AffinityPolicy/versions/1.0.0/policies  200  vCPE.policies.optimization.input.tosca.json  OSDF_CASABLANCA.Affinity_Default  1.0.0
47
48 GetDefaultDecision
49     [Documentation]  Get Default Decision with no policies in Xacml PDP
50      ${resp}=  PerformPostRequest  /policy/pdpx/v1/decision  abbrev=true  ${POLICY_PDPX_IP}  200  onap.policy.guard.decision.request.json  ${CURDIR}/data
51      ${status}=  Get From Dictionary  ${resp.json()}  status
52      Should Be Equal As Strings  ${status}  Permit
53
54 DeployPolicies
55      [Documentation]   Runs Policy PAP to deploy a policy
56      ${resp}=  PerformPostRequest  /policy/pap/v1/pdps/policies  null  ${POLICY_PAP_IP}  202  vCPE.policy.input.tosca.deploy.json  ${CURDIR}/data
57      Sleep      5s
58      ${result}=     Run Process    ${SCR_DMAAP}/wait_topic.sh    POLICY-PDP-PAP
59      ...            responseTo    xacml    ACTIVE    onap.restart.tca
60
61 GetStatisticsAfterDeployed
62      [Documentation]  Verify policy xacml-pdp statistics after policy is deployed
63      ${resp}=  PeformGetRequest  /policy/pdpx/v1/statistics  200
64      Should Be Equal As Strings  ${resp.json()['code']}  200
65      Should Be Equal As Strings  ${resp.json()['totalPoliciesCount']}  3
66
67 GetAbbreviatedDecisionResult
68     [Documentation]    Get Decision with abbreviated results from Policy Xacml PDP
69      ${resp}=  PerformPostRequest  /policy/pdpx/v1/decision  abbrev=true  ${POLICY_PDPX_IP}  200  onap.policy.monitoring.decision.request.json  ${CURDIR}/data
70      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
71      Dictionary Should Contain Key    ${policy}    type
72      Dictionary Should Contain Key    ${policy}    metadata
73      Dictionary Should Not Contain Key    ${policy}    type_version
74      Dictionary Should Not Contain Key    ${policy}    properties
75      Dictionary Should Not Contain Key    ${policy}    name
76      Dictionary Should Not Contain Key    ${policy}    version
77
78 GetMonitoringDecision
79     [Documentation]    Get Decision from Monitoring Policy Xacml PDP
80      ${resp}=  PerformPostRequest  /policy/pdpx/v1/decision  null  ${POLICY_PDPX_IP}  200  onap.policy.monitoring.decision.request.json  ${CURDIR}/data
81      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
82      Dictionary Should Contain Key    ${policy}    type
83      Dictionary Should Contain Key    ${policy}    metadata
84      Dictionary Should Contain Key    ${policy}    type_version
85      Dictionary Should Contain Key    ${policy}    properties
86      Dictionary Should Contain Key    ${policy}    name
87      Dictionary Should Contain Key    ${policy}    version
88
89 GetNamingDecision
90     [Documentation]    Get Decision from Naming Policy Xacml PDP
91      ${resp}=  PerformPostRequest  /policy/pdpx/v1/decision  null  ${POLICY_PDPX_IP}  200  onap.policy.naming.decision.request.json  ${CURDIR}/data
92      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP
93      Dictionary Should Contain Key    ${policy}    type
94      Dictionary Should Contain Key    ${policy}    type_version
95      Dictionary Should Contain Key    ${policy}    properties
96      Dictionary Should Contain Key    ${policy}    name
97
98 GetOptimizationDecision
99     [Documentation]    Get Decision from Optimization Policy Xacml PDP
100      ${resp}=  PerformPostRequest  /policy/pdpx/v1/decision  null  ${POLICY_PDPX_IP}  200  onap.policy.optimization.decision.request.json  ${CURDIR}/data
101      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   OSDF_CASABLANCA.Affinity_Default
102      Dictionary Should Contain Key    ${policy}    type
103      Dictionary Should Contain Key    ${policy}    type_version
104      Dictionary Should Contain Key    ${policy}    properties
105      Dictionary Should Contain Key    ${policy}    name
106
107 GetStatisticsAfterDecision
108      [Documentation]    Runs Policy Xacml PDP Statistics after Decision request
109      ${resp}=  PeformGetRequest  /policy/pdpx/v1/statistics  200
110      Should Be Equal As Strings    ${resp.json()['code']}  200
111      Should Be Equal As Strings    ${resp.json()['permitDecisionsCount']}     4
112      Should Be Equal As Strings    ${resp.json()['notApplicableDecisionsCount']}     1
113
114 UndeployMonitorPolicy
115      [Documentation]    Runs Policy PAP to undeploy a policy
116      PeformDeleteRequest  /policy/pap/v1/pdps/policies/onap.restart.tca  202
117
118 GetStatisticsAfterUndeploy
119      [Documentation]    Runs Policy Xacml PDP Statistics after policy is undeployed
120      ${resp}=  PeformGetRequest  /policy/pdpx/v1/statistics  200
121      Should Be Equal As Strings    ${resp.json()['code']}  200
122      Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']}     2
123      
124 CreatePolicy
125      [Arguments]  ${url}  ${expectedstatus}  ${jsonfile}  ${policyname}  ${policyversion}
126      [Documentation]  Create the specific policy
127      ${resp}=  PerformPostRequest  ${url}  null  ${POLICY_API_IP}  ${expectedstatus}  ${jsonfile}  ${DATA2}
128      Run Keyword If  ${expectedstatus}==200  Dictionary Should Contain Key  ${resp.json()['topology_template']['policies'][0]}  ${policyname}
129      Run Keyword If  ${expectedstatus}==200  Should Be Equal As Strings  ${resp.json()['topology_template']['policies'][0]['${policyname}']['version']}  ${policyversion}
130      
131 PerformPostRequest
132      [Arguments]  ${url}  ${params}  ${hostname}  ${expectedstatus}  ${jsonfile}  ${filepath}
133      ${auth}=  Create List  healthcheck  zb!XztG34
134      ${postjson}=  Get file  ${filepath}/${jsonfile}
135      Log  Creating session https://${hostname}:6969
136      ${session}=  Create Session  policy  https://${hostname}:6969  auth=${auth}
137      ${headers}=  Create Dictionary  Accept=application/json  Content-Type=application/json
138      ${resp}=  POST On Session  policy  ${url}  params=${params}  data=${postjson}  headers=${headers}  expected_status=${expectedstatus}
139      Log  Received response from policy ${resp.text}
140      [return]  ${resp}
141
142 PeformGetRequest
143      [Arguments]  ${url}  ${expectedstatus}
144      ${auth}=  Create List  healthcheck  zb!XztG34
145      Log  Creating session https://${POLICY_PDPX_IP}:6969
146      ${session}=  Create Session  policy  https://${POLICY_PDPX_IP}:6969  auth=${auth}
147      ${headers}=  Create Dictionary  Accept=application/json  Content-Type=application/json
148      ${resp}=  GET On Session  policy  ${url}  headers=${headers}  expected_status=${expectedstatus}
149      Log  Received response from policy ${resp.text}
150      [return]  ${resp}
151
152 PeformDeleteRequest
153      [Arguments]  ${url}  ${expectedstatus}
154      ${auth}=  Create List  healthcheck  zb!XztG34
155      Log  Creating session https://${POLICY_PAP_IP}:6969
156      ${session}=  Create Session  policy  https://${POLICY_PAP_IP}:6969  auth=${auth}
157      ${headers}=  Create Dictionary  Accept=application/json  Content-Type=application/json
158      ${resp}=  DELETE On Session  policy  ${url}  headers=${headers}  expected_status=${expectedstatus}
159      Log  Received response from policy ${resp.text}