8227996f9b42d1bce89680af8395bd010e7f750f
[integration/csit.git] / tests / policy / xacml-pdp / xacml-pdp-test.robot
1 *** Settings ***
2 Library     Collections
3 Library     RequestsLibrary
4 Library     OperatingSystem
5 Library     json
6
7 *** Test Cases ***
8 Healthcheck
9      [Documentation]    Runs Policy Xacml PDP Health check
10      ${auth}=    Create List    healthcheck    zb!XztG34 
11      Log    Creating session https://${POLICY_PDPX_IP}:6969
12      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
13      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
14      ${resp}=   Get Request     policy  /policy/pdpx/v1/healthcheck     headers=${headers}
15      Log    Received response from policy ${resp.text}
16      Should Be Equal As Strings    ${resp.status_code}     200
17      Should Be Equal As Strings    ${resp.json()['code']}  200
18
19 Statistics
20      [Documentation]    Runs Policy Xacml PDP Statistics
21      ${auth}=    Create List    healthcheck    zb!XztG34
22      Log    Creating session https://${POLICY_PDPX_IP}:6969
23      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
24      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
25      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
26      Log    Received response from policy ${resp.text}
27      Should Be Equal As Strings    ${resp.status_code}     200
28      Should Be Equal As Strings    ${resp.json()['code']}  200
29
30 ExecuteXacmlPolicy
31      Wait Until Keyword Succeeds    2 min    5 sec    CreateMonitorPolicyType
32      Wait Until Keyword Succeeds    2 min    5 sec    CreateNewMonitorPolicy
33      Wait Until Keyword Succeeds    2 min    5 sec    DeployMonitorPolicy
34      Wait Until Keyword Succeeds    2 min    10 sec   GetAbbreviatedDecisionResult
35      Wait Until Keyword Succeeds    2 min    10 sec   GetDecision
36
37 *** Keywords ***
38
39 CreateMonitorPolicyType
40      [Documentation]    Create Monitoring Policy Type
41      ${auth}=    Create List    healthcheck    zb!XztG34
42      ${postjson}=  Get file  ${CURDIR}/data/onap.policies.monitoring.cdap.tca.hi.lo.app.json
43      Log    Creating session https://${POLICY_API_IP}:6969
44      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
45      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
46      ${resp}=   Post Request   policy  /policy/api/v1/policytypes  data=${postjson}   headers=${headers}
47      Log    Received response from policy2 ${resp.text}
48      Should Be Equal As Strings    ${resp.status_code}     200
49      ${postjsonobject}   To Json    ${postjson}
50      Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version
51      Dictionary Should Contain Key    ${postjsonobject}    tosca_definitions_version
52
53 CreateNewMonitorPolicy
54      [Documentation]    Create a new Monitoring policy
55      ${auth}=    Create List    healthcheck    zb!XztG34
56      ${postjson}=  Get file  ${CURDIR}/data/vCPE.policy.monitoring.input.tosca.json
57      Log    Creating session https://${POLICY_API_IP}:6969
58      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
59      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
60      ${resp}=   Post Request   policy  /policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies  data=${postjson}   headers=${headers}
61      Log    Received response from policy4 ${resp.text}
62      ${postjsonobject}   To Json    ${postjson}
63      Should Be Equal As Strings    ${resp.status_code}     200
64      Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version
65      Dictionary Should Contain Key    ${postjsonobject}    tosca_definitions_version
66
67 DeployMonitorPolicy
68      [Documentation]   Runs Policy PAP to deploy a policy
69      ${auth}=    Create List    healthcheck    zb!XztG34
70      ${postjson}=  Get file  ${CURDIR}/data/vCPE.policy.monitoring.input.tosca.deploy.json
71      Log    Creating session https://${POLICY_PAP_IP}:6969
72      ${session}=    Create Session      policy  https://${POLICY_PAP_IP}:6969   auth=${auth}
73      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
74      ${resp}=   Post Request   policy  /policy/pap/v1/pdps/policies  data=${postjson}   headers=${headers}
75      Log    Received response from policy5 ${resp.text}
76      ${postjsonobject}   To Json    ${postjson}
77      Should Be Equal As Strings    ${resp.status_code}     200
78
79 GetStatisticsAfterDeployed
80      [Documentation]    Runs Policy Xacml PDP Statistics after policy is deployed
81      ${auth}=    Create List    healthcheck    zb!XztG34
82      Log    Creating session https://${POLICY_PDPX_IP}:6969
83      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
84      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
85      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
86      Log    Received response from policy ${resp.text}
87      Should Be Equal As Strings    ${resp.status_code}     200
88      Should Be Equal As Strings    ${resp.json()['code']}  200
89      Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']     1
90
91 GetAbbreviatedDecisionResult
92     [Documentation]    Get Decision with abbreviated results from Policy Xacml PDP
93      ${auth}=    Create List    healthcheck    zb!XztG34
94      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.decision.request.json
95      Log    Creating session https://${POLICY_PDPX_IP}:6969
96      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
97      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
98      ${params}=  Create Dictionary      abbrev=true
99      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision     params=${params}  data=${postjson}   headers=${headers}
100      Log    Received response from policy ${resp.text}
101      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
102      Should Be Equal As Strings    ${resp.status_code}     200
103      Dictionary Should Contain Key    ${policy}    type
104      Dictionary Should Contain Key    ${policy}    metadata
105      Dictionary Should Not Contain Key    ${policy}    type_version
106      Dictionary Should Not Contain Key    ${policy}    properties
107      Dictionary Should Not Contain Key    ${policy}    name
108      Dictionary Should Not Contain Key    ${policy}    version
109
110 GetDecision
111     [Documentation]    Get Decision from Policy Xacml PDP
112      ${auth}=    Create List    healthcheck    zb!XztG34
113      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.decision.request.json
114      Log    Creating session https://${POLICY_PDPX_IP}:6969
115      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
116      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
117      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision  data=${postjson}   headers=${headers}
118      Log    Received response from policy ${resp.text}
119      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
120      Should Be Equal As Strings    ${resp.status_code}     200
121      Dictionary Should Contain Key    ${policy}    type
122      Dictionary Should Contain Key    ${policy}    metadata
123      Dictionary Should Contain Key    ${policy}    type_version
124      Dictionary Should Contain Key    ${policy}    properties
125      Dictionary Should Contain Key    ${policy}    name
126      Dictionary Should Contain Key    ${policy}    version
127      
128 GetStatisticsAfterDecision
129      [Documentation]    Runs Policy Xacml PDP Statistics after Decision request
130      ${auth}=    Create List    healthcheck    zb!XztG34 
131      Log    Creating session https://${POLICY_PDPX_IP}:6969
132      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
133      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
134      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
135      Log    Received response from policy ${resp.text}
136      Should Be Equal As Strings    ${resp.status_code}     200
137      Should Be Equal As Strings    ${resp.json()['code']}  200
138      Should Be Equal As Strings    ${resp.json()['totalDecisionsCount']     1
139      
140 UndeployMonitorPolicy
141      [Documentation]    Runs Policy PAP to undeploy a policy
142      ${auth}=    Create List    healthcheck    zb!XztG34
143      Log    Creating session https://${POLICY_PAP_IP}:6969
144      ${session}=    Create Session      policy  https://${POLICY_PAP_IP}:6969   auth=${auth}
145      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
146      ${resp}=   Delete Request     policy  /policy/pap/v1/pdps/policies/onap.restart.tca     headers=${headers}
147      Log    Received response from policy ${resp.text}
148      Should Be Equal As Strings    ${resp.status_code}     200
149      
150 GetStatisticsAfterUndeploy
151      [Documentation]    Runs Policy Xacml PDP Statistics after policy is undeployed
152      ${auth}=    Create List    healthcheck    zb!XztG34 
153      Log    Creating session https://${POLICY_PDPX_IP}:6969
154      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
155      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
156      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
157      Log    Received response from policy ${resp.text}
158      Should Be Equal As Strings    ${resp.status_code}     200
159      Should Be Equal As Strings    ${resp.json()['code']}  200
160      Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']     0
161
162