aboutsummaryrefslogtreecommitdiffstats
path: root/csit/tests/xacml-pdp-test.robot
blob: 03b0ca7a200a4ba58ac042f3397e94f3a29949c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
*** Settings ***
Library     Collections
Library     RequestsLibrary
Library     OperatingSystem
Library     Process
Library     json

*** Test Cases ***
Healthcheck
     [Documentation]    Runs Policy Xacml PDP Health check
     ${auth}=    Create List    healthcheck    zb!XztG34
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${resp}=   Get Request     policy  /policy/pdpx/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

Statistics
     [Documentation]    Runs Policy Xacml PDP Statistics
     ${auth}=    Create List    healthcheck    zb!XztG34
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${resp}=   Get Request     policy  /policy/pdpx/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

MakeTopics
     [Documentation]    Creates the Policy topics
     ${result}=     Run Process     ${SCR_DMAAP}/make_topic.sh   POLICY-PDP-PAP
     Should Be Equal As Integers        ${result.rc}    0

ExecuteXacmlPolicy
     Wait Until Keyword Succeeds    0 min   15 sec  CreateMonitorPolicy
     Wait Until Keyword Succeeds    0 min   15 sec  CreateOptimizationPolicy
     Wait Until Keyword Succeeds    0 min   15 sec  GetDefaultDecision
     Wait Until Keyword Succeeds    0 min   15 sec  DeployPolicies
     Wait Until Keyword Succeeds    0 min   15 sec  GetAbbreviatedDecisionResult
     Wait Until Keyword Succeeds    0 min   15 sec  GetMonitoringDecision
     Wait Until Keyword Succeeds    0 min   15 sec  GetNamingDecision
     Wait Until Keyword Succeeds    0 min   15 sec  GetOptimizationDecision

*** Keywords ***

CreateMonitorPolicy
     [Documentation]    Create a Monitoring policy
     ${auth}=    Create List    healthcheck    zb!XztG34
     ${postjson}=  Get file  ${DATA2}/vCPE.policy.monitoring.input.tosca.json
     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
     ${resp}=   Post Request   policy  /policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/policies  data=${postjson}   headers=${headers}
     Log    Received response from policy4 ${resp.text}
     ${postjsonobject}   To Json    ${postjson}
     Should Be Equal As Strings    ${resp.status_code}     200
     Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version
     Dictionary Should Contain Key    ${postjsonobject}    tosca_definitions_version

CreateOptimizationPolicy
     [Documentation]    Create an Optimization policy
     ${auth}=    Create List    healthcheck    zb!XztG34
     ${postjson}=  Get file  ${DATA2}/vCPE.policies.optimization.input.tosca.json
     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
     ${resp}=   Post Request   policy  /policy/api/v1/policytypes/onap.policies.optimization.resource.AffinityPolicy/versions/1.0.0/policies  data=${postjson}   headers=${headers}
     Log    Received response from policy4 ${resp.text}
     ${postjsonobject}   To Json    ${postjson}
     Should Be Equal As Strings    ${resp.status_code}     200
     Dictionary Should Contain Key    ${resp.json()}    tosca_definitions_version
     Dictionary Should Contain Key    ${postjsonobject}    tosca_definitions_version

DeployPolicies
     [Documentation]   Runs Policy PAP to deploy a policy
     ${auth}=    Create List    healthcheck    zb!XztG34
     ${postjson}=  Get file  ${CURDIR}/data/vCPE.policy.input.tosca.deploy.json
     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}=   Post Request   policy  /policy/pap/v1/pdps/policies  data=${postjson}   headers=${headers}
     Log    Received response from policy5 ${resp.text}
     ${postjsonobject}   To Json    ${postjson}
     Should Be Equal As Strings    ${resp.status_code}     202
     ${result}=     Run Process    ${SCR_DMAAP}/wait_topic.sh    POLICY-PDP-PAP
     ...            responseTo    xacml    ACTIVE    onap.restart.tca

GetStatisticsAfterDeployed
     [Documentation]    Runs Policy Xacml PDP Statistics after policy is deployed
     ${auth}=    Create List    healthcheck    zb!XztG34
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${resp}=   Get Request     policy  /policy/pdpx/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
     Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']     1

GetDefaultDecision
    [Documentation]    Get Default Decision with no policies in Xacml PDP
     ${auth}=    Create List    healthcheck    zb!XztG34
     ${postjson}=  Get file  ${CURDIR}/data/onap.policy.guard.decision.request.json
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${params}=  Create Dictionary      abbrev=true
     ${resp}=   Post Request     policy  /policy/pdpx/v1/decision     params=${params}  data=${postjson}   headers=${headers}
     Log    Received response from policy ${resp.text}
     ${status}=    Get From Dictionary    ${resp.json()}   status
     Should Be Equal As Strings    ${resp.status_code}     200
     Should Be Equal As Strings    ${status}     Permit

GetAbbreviatedDecisionResult
    [Documentation]    Get Decision with abbreviated results from Policy Xacml PDP
     ${auth}=    Create List    healthcheck    zb!XztG34
     ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.decision.request.json
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${params}=  Create Dictionary      abbrev=true
     ${resp}=   Post Request     policy  /policy/pdpx/v1/decision     params=${params}  data=${postjson}   headers=${headers}
     Log    Received response from policy ${resp.text}
     ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
     Should Be Equal As Strings    ${resp.status_code}     200
     Dictionary Should Contain Key    ${policy}    type
     Dictionary Should Contain Key    ${policy}    metadata
     Dictionary Should Not Contain Key    ${policy}    type_version
     Dictionary Should Not Contain Key    ${policy}    properties
     Dictionary Should Not Contain Key    ${policy}    name
     Dictionary Should Not Contain Key    ${policy}    version

GetMonitoringDecision
    [Documentation]    Get Decision from Monitoring Policy Xacml PDP
     ${auth}=    Create List    healthcheck    zb!XztG34
     ${postjson}=  Get file  ${CURDIR}/data/onap.policy.monitoring.decision.request.json
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${resp}=   Post Request     policy  /policy/pdpx/v1/decision  data=${postjson}   headers=${headers}
     Log    Received response from policy ${resp.text}
     ${policy}=    Get From Dictionary    ${resp.json()['policies']}   onap.restart.tca
     Should Be Equal As Strings    ${resp.status_code}     200
     Dictionary Should Contain Key    ${policy}    type
     Dictionary Should Contain Key    ${policy}    metadata
     Dictionary Should Contain Key    ${policy}    type_version
     Dictionary Should Contain Key    ${policy}    properties
     Dictionary Should Contain Key    ${policy}    name
     Dictionary Should Contain Key    ${policy}    version

GetNamingDecision
    [Documentation]    Get Decision from Naming Policy Xacml PDP
     ${auth}=    Create List    healthcheck    zb!XztG34
     ${postjson}=  Get file  ${CURDIR}/data/onap.policy.naming.decision.request.json
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${resp}=   Post Request     policy  /policy/pdpx/v1/decision  data=${postjson}   headers=${headers}
     Log    Received response from policy ${resp.text}
     ${policy}=    Get From Dictionary    ${resp.json()['policies']}   SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP
     Should Be Equal As Strings    ${resp.status_code}     200
     Dictionary Should Contain Key    ${policy}    type
     Dictionary Should Contain Key    ${policy}    type_version
     Dictionary Should Contain Key    ${policy}    properties
     Dictionary Should Contain Key    ${policy}    name

GetOptimizationDecision
    [Documentation]    Get Decision from Optimization Policy Xacml PDP
     ${auth}=    Create List    healthcheck    zb!XztG34
     ${postjson}=  Get file  ${CURDIR}/data/onap.policy.optimization.decision.request.json
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${resp}=   Post Request     policy  /policy/pdpx/v1/decision  data=${postjson}   headers=${headers}
     Log    Received response from policy ${resp.text}
     ${policy}=    Get From Dictionary    ${resp.json()['policies']}   OSDF_CASABLANCA.Affinity_Default
     Should Be Equal As Strings    ${resp.status_code}     200
     Dictionary Should Contain Key    ${policy}    type
     Dictionary Should Contain Key    ${policy}    type_version
     Dictionary Should Contain Key    ${policy}    properties
     Dictionary Should Contain Key    ${policy}    name

GetStatisticsAfterDecision
     [Documentation]    Runs Policy Xacml PDP Statistics after Decision request
     ${auth}=    Create List    healthcheck    zb!XztG34
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${resp}=   Get Request     policy  /policy/pdpx/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
     Should Be Equal As Strings    ${resp.json()['totalDecisionsCount']     1

UndeployMonitorPolicy
     [Documentation]    Runs Policy PAP to undeploy a policy
     ${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 Request     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

GetStatisticsAfterUndeploy
     [Documentation]    Runs Policy Xacml PDP Statistics after policy is undeployed
     ${auth}=    Create List    healthcheck    zb!XztG34
     Log    Creating session https://${POLICY_PDPX_IP}:6969
     ${session}=    Create Session      policy  https://${POLICY_PDPX_IP}:6969   auth=${auth}
     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
     ${resp}=   Get Request     policy  /policy/pdpx/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
     Should Be Equal As Strings    ${resp.json()['totalPoliciesCount']     0