9fd4ed2583d934863611a05f63b232b8b072bde5
[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]    Runs Policy Xacml PDP Health check
11      ${auth}=    Create List    healthcheck    zb!XztG34
12      Log    Creating session https://${POLICY_PDPX_IP}:6969
13      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
14      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
15      ${resp}=   Get Request     policy  /policy/pdpx/v1/healthcheck     headers=${headers}
16      Log    Received response from policy ${resp.text}
17      Should Be Equal As Strings    ${resp.status_code}     200
18      Should Be Equal As Strings    ${resp.json()['code']}  200
19
20 Statistics
21      [Documentation]    Runs Policy Xacml PDP Statistics
22      ${auth}=    Create List    healthcheck    zb!XztG34
23      Log    Creating session https://${POLICY_PDPX_IP}:6969
24      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
25      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
26      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
27      Log    Received response from policy ${resp.text}
28      Should Be Equal As Strings    ${resp.status_code}     200
29      Should Be Equal As Strings    ${resp.json()['code']}  200
30
31 MakeTopics
32      [Documentation]    Creates the Policy topics
33      ${result}=     Run Process     ${SCR_DMAAP}/make_topic.sh   POLICY-PDP-PAP
34      Should Be Equal As Integers        ${result.rc}    0
35
36 ExecuteXacmlPolicy
37      Wait Until Keyword Succeeds    0 min   15 sec  CreateMonitorPolicy
38      Wait Until Keyword Succeeds    0 min   15 sec  CreateOptimizationPolicy
39      Wait Until Keyword Succeeds    0 min   15 sec  GetDefaultDecision
40      Wait Until Keyword Succeeds    0 min   15 sec  DeployPolicies
41      Wait Until Keyword Succeeds    0 min   15 sec  GetAbbreviatedDecisionResult
42      Wait Until Keyword Succeeds    0 min   15 sec  GetMonitoringDecision
43      Wait Until Keyword Succeeds    0 min   15 sec  GetNamingDecision
44      Wait Until Keyword Succeeds    0 min   15 sec  GetOptimizationDecision
45
46 *** Keywords ***
47
48 CreateMonitorPolicy
49      [Documentation]    Create a Monitoring policy
50      ${auth}=    Create List    healthcheck    zb!XztG34
51      ${postjson}=  Get file  ${DATA2}/vCPE.policy.monitoring.input.tosca.json
52      Log    Creating session https://${POLICY_API_IP}:6969
53      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
54      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
55      ${resp}=   Post Request   policy  /policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/policies  data=${postjson}   headers=${headers}
56      Log    Received response from policy4 ${resp.text}
57      ${postjsonobject}   To Json    ${postjson}
58      Should Be Equal As Strings    ${resp.status_code}     200
59      Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version
60      Dictionary Should Contain Key    ${postjsonobject}    tosca_definitions_version
61
62 CreateOptimizationPolicy
63      [Documentation]    Create an Optimization policy
64      ${auth}=    Create List    healthcheck    zb!XztG34
65      ${postjson}=  Get file  ${DATA2}/vCPE.policies.optimization.input.tosca.json
66      Log    Creating session https://${POLICY_API_IP}:6969
67      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
68      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
69      ${resp}=   Post Request   policy  /policy/api/v1/policytypes/onap.policies.optimization.resource.AffinityPolicy/versions/1.0.0/policies  data=${postjson}   headers=${headers}
70      Log    Received response from policy4 ${resp.text}
71      ${postjsonobject}   To Json    ${postjson}
72      Should Be Equal As Strings    ${resp.status_code}     200
73      Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version
74      Dictionary Should Contain Key    ${postjsonobject}    tosca_definitions_version
75
76 DeployPolicies
77      [Documentation]   Runs Policy PAP to deploy a policy
78      ${auth}=    Create List    healthcheck    zb!XztG34
79      ${postjson}=  Get file  ${CURDIR}/data/vCPE.policy.input.tosca.deploy.json
80      Log    Creating session https://${POLICY_PAP_IP}:6969
81      ${session}=    Create Session      policy  https://${POLICY_PAP_IP}:6969   auth=${auth}
82      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
83      ${resp}=   Post Request   policy  /policy/pap/v1/pdps/policies  data=${postjson}   headers=${headers}
84      Sleep      5s
85      Log    Received response from policy5 ${resp.text}
86      ${postjsonobject}   To Json    ${postjson}
87      Should Be Equal As Strings    ${resp.status_code}     202
88      ${result}=     Run Process    ${SCR_DMAAP}/wait_topic.sh    POLICY-PDP-PAP
89      ...            responseTo    xacml    ACTIVE    onap.restart.tca
90
91 GetStatisticsAfterDeployed
92      [Documentation]    Runs Policy Xacml PDP Statistics after policy is deployed
93      ${auth}=    Create List    healthcheck    zb!XztG34
94      Log    Creating session https://${POLICY_PDPX_IP}:6969
95      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
96      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
97      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
98      Log    Received response from policy ${resp.text}
99      Should Be Equal As Strings    ${resp.status_code}     200
100      Should Be Equal As Strings    ${resp.json()['code']}  200
101      Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']     1
102
103 GetDefaultDecision
104     [Documentation]    Get Default Decision with no policies in Xacml PDP
105      ${auth}=    Create List    healthcheck    zb!XztG34
106      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.guard.decision.request.json
107      Log    Creating session https://${POLICY_PDPX_IP}:6969
108      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
109      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
110      ${params}=  Create Dictionary      abbrev=true
111      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision     params=${params}  data=${postjson}   headers=${headers}
112      Log    Received response from policy ${resp.text}
113      ${status}=    Get From Dictionary    ${resp.json()}   status
114      Should Be Equal As Strings    ${resp.status_code}     200
115      Should Be Equal As Strings    ${status}     Permit
116
117 GetAbbreviatedDecisionResult
118     [Documentation]    Get Decision with abbreviated results from Policy Xacml PDP
119      ${auth}=    Create List    healthcheck    zb!XztG34
120      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.decision.request.json
121      Log    Creating session https://${POLICY_PDPX_IP}:6969
122      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
123      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
124      ${params}=  Create Dictionary      abbrev=true
125      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision     params=${params}  data=${postjson}   headers=${headers}
126      Log    Received response from policy ${resp.text}
127      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
128      Should Be Equal As Strings    ${resp.status_code}     200
129      Dictionary Should Contain Key    ${policy}    type
130      Dictionary Should Contain Key    ${policy}    metadata
131      Dictionary Should Not Contain Key    ${policy}    type_version
132      Dictionary Should Not Contain Key    ${policy}    properties
133      Dictionary Should Not Contain Key    ${policy}    name
134      Dictionary Should Not Contain Key    ${policy}    version
135
136 GetMonitoringDecision
137     [Documentation]    Get Decision from Monitoring Policy Xacml PDP
138      ${auth}=    Create List    healthcheck    zb!XztG34
139      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.decision.request.json
140      Log    Creating session https://${POLICY_PDPX_IP}:6969
141      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
142      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
143      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision  data=${postjson}   headers=${headers}
144      Log    Received response from policy ${resp.text}
145      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
146      Should Be Equal As Strings    ${resp.status_code}     200
147      Dictionary Should Contain Key    ${policy}    type
148      Dictionary Should Contain Key    ${policy}    metadata
149      Dictionary Should Contain Key    ${policy}    type_version
150      Dictionary Should Contain Key    ${policy}    properties
151      Dictionary Should Contain Key    ${policy}    name
152      Dictionary Should Contain Key    ${policy}    version
153
154 GetNamingDecision
155     [Documentation]    Get Decision from Naming Policy Xacml PDP
156      ${auth}=    Create List    healthcheck    zb!XztG34
157      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.naming.decision.request.json
158      Log    Creating session https://${POLICY_PDPX_IP}:6969
159      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
160      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
161      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision  data=${postjson}   headers=${headers}
162      Log    Received response from policy ${resp.text}
163      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP
164      Should Be Equal As Strings    ${resp.status_code}     200
165      Dictionary Should Contain Key    ${policy}    type
166      Dictionary Should Contain Key    ${policy}    type_version
167      Dictionary Should Contain Key    ${policy}    properties
168      Dictionary Should Contain Key    ${policy}    name
169
170 GetOptimizationDecision
171     [Documentation]    Get Decision from Optimization Policy Xacml PDP
172      ${auth}=    Create List    healthcheck    zb!XztG34
173      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.optimization.decision.request.json
174      Log    Creating session https://${POLICY_PDPX_IP}:6969
175      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
176      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
177      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision  data=${postjson}   headers=${headers}
178      Log    Received response from policy ${resp.text}
179      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   OSDF_CASABLANCA.Affinity_Default
180      Should Be Equal As Strings    ${resp.status_code}     200
181      Dictionary Should Contain Key    ${policy}    type
182      Dictionary Should Contain Key    ${policy}    type_version
183      Dictionary Should Contain Key    ${policy}    properties
184      Dictionary Should Contain Key    ${policy}    name
185
186 GetStatisticsAfterDecision
187      [Documentation]    Runs Policy Xacml PDP Statistics after Decision request
188      ${auth}=    Create List    healthcheck    zb!XztG34
189      Log    Creating session https://${POLICY_PDPX_IP}:6969
190      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
191      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
192      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
193      Log    Received response from policy ${resp.text}
194      Should Be Equal As Strings    ${resp.status_code}     200
195      Should Be Equal As Strings    ${resp.json()['code']}  200
196      Should Be Equal As Strings    ${resp.json()['totalDecisionsCount']     1
197
198 UndeployMonitorPolicy
199      [Documentation]    Runs Policy PAP to undeploy a policy
200      ${auth}=    Create List    healthcheck    zb!XztG34
201      Log    Creating session https://${POLICY_PAP_IP}:6969
202      ${session}=    Create Session      policy  https://${POLICY_PAP_IP}:6969   auth=${auth}
203      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
204      ${resp}=   Delete Request     policy  /policy/pap/v1/pdps/policies/onap.restart.tca     headers=${headers}
205      Log    Received response from policy ${resp.text}
206      Should Be Equal As Strings    ${resp.status_code}     202
207
208 GetStatisticsAfterUndeploy
209      [Documentation]    Runs Policy Xacml PDP Statistics after policy is undeployed
210      ${auth}=    Create List    healthcheck    zb!XztG34
211      Log    Creating session https://${POLICY_PDPX_IP}:6969
212      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
213      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
214      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
215      Log    Received response from policy ${resp.text}
216      Should Be Equal As Strings    ${resp.status_code}     200
217      Should Be Equal As Strings    ${resp.json()['code']}  200
218      Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']     0