[SO] SO release image for CSIT testing
[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    CreateNewMonitorPolicy
32      Wait Until Keyword Succeeds    2 min    5 sec    DeployMonitorPolicy
33      Wait Until Keyword Succeeds    2 min    10 sec   GetAbbreviatedDecisionResult
34      Wait Until Keyword Succeeds    2 min    10 sec   GetDecision
35
36 *** Keywords ***
37
38 CreateNewMonitorPolicy
39      [Documentation]    Create a new Monitoring policy
40      ${auth}=    Create List    healthcheck    zb!XztG34
41      ${postjson}=  Get file  ${CURDIR}/data/vCPE.policy.monitoring.input.tosca.json
42      Log    Creating session https://${POLICY_API_IP}:6969
43      ${session}=    Create Session      policy  https://${POLICY_API_IP}:6969   auth=${auth}
44      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
45      ${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}
46      Log    Received response from policy4 ${resp.text}
47      ${postjsonobject}   To Json    ${postjson}
48      Should Be Equal As Strings    ${resp.status_code}     200
49      Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version
50      Dictionary Should Contain Key    ${postjsonobject}    tosca_definitions_version
51
52 DeployMonitorPolicy
53      [Documentation]   Runs Policy PAP to deploy a policy
54      ${auth}=    Create List    healthcheck    zb!XztG34
55      ${postjson}=  Get file  ${CURDIR}/data/vCPE.policy.monitoring.input.tosca.deploy.json
56      Log    Creating session https://${POLICY_PAP_IP}:6969
57      ${session}=    Create Session      policy  https://${POLICY_PAP_IP}:6969   auth=${auth}
58      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
59      ${resp}=   Post Request   policy  /policy/pap/v1/pdps/policies  data=${postjson}   headers=${headers}
60      Log    Received response from policy5 ${resp.text}
61      ${postjsonobject}   To Json    ${postjson}
62      Should Be Equal As Strings    ${resp.status_code}     200
63
64 GetStatisticsAfterDeployed
65      [Documentation]    Runs Policy Xacml PDP Statistics after policy is deployed
66      ${auth}=    Create List    healthcheck    zb!XztG34
67      Log    Creating session https://${POLICY_PDPX_IP}:6969
68      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
69      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
70      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
71      Log    Received response from policy ${resp.text}
72      Should Be Equal As Strings    ${resp.status_code}     200
73      Should Be Equal As Strings    ${resp.json()['code']}  200
74      Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']     1
75
76 GetAbbreviatedDecisionResult
77     [Documentation]    Get Decision with abbreviated results from Policy Xacml PDP
78      ${auth}=    Create List    healthcheck    zb!XztG34
79      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.decision.request.json
80      Log    Creating session https://${POLICY_PDPX_IP}:6969
81      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
82      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
83      ${params}=  Create Dictionary      abbrev=true
84      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision     params=${params}  data=${postjson}   headers=${headers}
85      Log    Received response from policy ${resp.text}
86      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
87      Should Be Equal As Strings    ${resp.status_code}     200
88      Dictionary Should Contain Key    ${policy}    type
89      Dictionary Should Contain Key    ${policy}    metadata
90      Dictionary Should Not Contain Key    ${policy}    type_version
91      Dictionary Should Not Contain Key    ${policy}    properties
92      Dictionary Should Not Contain Key    ${policy}    name
93      Dictionary Should Not Contain Key    ${policy}    version
94
95 GetDecision
96     [Documentation]    Get Decision from Policy Xacml PDP
97      ${auth}=    Create List    healthcheck    zb!XztG34
98      ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.decision.request.json
99      Log    Creating session https://${POLICY_PDPX_IP}:6969
100      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
101      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
102      ${resp}=   Post Request     policy  /policy/pdpx/v1/decision  data=${postjson}   headers=${headers}
103      Log    Received response from policy ${resp.text}
104      ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
105      Should Be Equal As Strings    ${resp.status_code}     200
106      Dictionary Should Contain Key    ${policy}    type
107      Dictionary Should Contain Key    ${policy}    metadata
108      Dictionary Should Contain Key    ${policy}    type_version
109      Dictionary Should Contain Key    ${policy}    properties
110      Dictionary Should Contain Key    ${policy}    name
111      Dictionary Should Contain Key    ${policy}    version
112      
113 GetStatisticsAfterDecision
114      [Documentation]    Runs Policy Xacml PDP Statistics after Decision request
115      ${auth}=    Create List    healthcheck    zb!XztG34 
116      Log    Creating session https://${POLICY_PDPX_IP}:6969
117      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
118      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
119      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
120      Log    Received response from policy ${resp.text}
121      Should Be Equal As Strings    ${resp.status_code}     200
122      Should Be Equal As Strings    ${resp.json()['code']}  200
123      Should Be Equal As Strings    ${resp.json()['totalDecisionsCount']     1
124      
125 UndeployMonitorPolicy
126      [Documentation]    Runs Policy PAP to undeploy a policy
127      ${auth}=    Create List    healthcheck    zb!XztG34
128      Log    Creating session https://${POLICY_PAP_IP}:6969
129      ${session}=    Create Session      policy  https://${POLICY_PAP_IP}:6969   auth=${auth}
130      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
131      ${resp}=   Delete Request     policy  /policy/pap/v1/pdps/policies/onap.restart.tca     headers=${headers}
132      Log    Received response from policy ${resp.text}
133      Should Be Equal As Strings    ${resp.status_code}     200
134      
135 GetStatisticsAfterUndeploy
136      [Documentation]    Runs Policy Xacml PDP Statistics after policy is undeployed
137      ${auth}=    Create List    healthcheck    zb!XztG34 
138      Log    Creating session https://${POLICY_PDPX_IP}:6969
139      ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
140      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
141      ${resp}=   Get Request     policy  /policy/pdpx/v1/statistics     headers=${headers}
142      Log    Received response from policy ${resp.text}
143      Should Be Equal As Strings    ${resp.status_code}     200
144      Should Be Equal As Strings    ${resp.json()['code']}  200
145      Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']     0
146
147