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