Add CSIT for ACM in docker
[policy/docker.git] / csit / resources / tests / policy-clamp-test.robot
1 *** Settings ***
2 Library     Collections
3 Library     RequestsLibrary
4 Library     OperatingSystem
5 Library     String
6 Library     json
7 Library     yaml
8
9 *** Test Cases ***
10 Healthcheck
11      [Documentation]    Healthcheck on Clamp Acm
12      ${auth}=    Create List    runtimeUser    zb!XztG34
13      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
14      ${session}=    Create Session      ACM  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
15      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
16      ${resp}=   GET On Session     ACM  /onap/policy/clamp/acm/health     headers=${headers}
17      Log    Received response from ACM healthcheck {resp.text}
18      Should Be Equal As Strings    ${resp.status_code}     200
19
20 CommissionAutomationComposition
21      [Documentation]  Commission automation composition.
22      ${auth}=    Create List    runtimeUser    zb!XztG34
23      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
24      ${postyaml}=  Get file  ${CURDIR}/data/acelement-usecase.yaml
25      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
26      ${headers}=  Create Dictionary     Accept=application/yaml    Content-Type=application/yaml
27      ${resp}=   POST On Session     policy  /onap/policy/clamp/acm/v2/compositions   data=${postyaml}  headers=${headers}
28      Log    Received response from runtime acm ${resp.text}
29      ${respyaml}=  yaml.Safe Load  ${resp.text}
30      set Suite variable  ${compositionId}  ${respyaml["compositionId"]}
31      Should Be Equal As Strings    ${resp.status_code}     201
32
33 RegisterParticipants
34      [Documentation]  Register Participants.
35      ${auth}=    Create List    runtimeUser    zb!XztG34
36      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
37      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
38      ${resp}=   PUT On Session     policy  /onap/policy/clamp/acm/v2/participants
39      Log    Received response from runtime acm ${resp.text}
40      Should Be Equal As Strings    ${resp.status_code}     202
41
42 PrimeACDefinitions
43      [Documentation]  Prime automation composition definition
44      ${auth}=    Create List    runtimeUser    zb!XztG34
45      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
46      ${postjson}=  Get file  ${CURDIR}/data/ACPriming.json
47      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
48      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
49      ${resp}=   PUT On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}   data=${postjson}  headers=${headers}
50      Should Be Equal As Strings    ${resp.status_code}     202
51      Wait Until Keyword Succeeds    2 min    5 sec    VerifyPriming  PRIMED
52
53
54 InstantiateAutomationComposition
55      [Documentation]  Instantiate automation composition.
56      ${auth}=    Create List    runtimeUser    zb!XztG34
57      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
58      ${postjson}=  Get file  ${CURDIR}/data/AutomationComposition.json
59      ${updatedpostjson}=   Replace String     ${postjson}     COMPOSITIONIDPLACEHOLDER       ${compositionId}
60      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
61      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
62      ${resp}=   POST On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances   data=${updatedpostjson}  headers=${headers}
63      Log    Received response from runtime acm ${resp.text}
64      ${respyaml}=  yaml.Safe Load  ${resp.text}
65      set Suite variable  ${instanceId}    ${respyaml["instanceId"]}
66      Should Be Equal As Strings    ${resp.status_code}     201
67
68 DeployAutomationComposition
69      [Documentation]  Deploy automation composition.
70      ${auth}=    Create List    runtimeUser    zb!XztG34
71      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
72      ${postjson}=  Get file  ${CURDIR}/data/DeployAC.json
73      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
74      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
75      ${resp}=   PUT On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}   data=${postjson}  headers=${headers}
76      Log    Received response from runtime acm ${resp.text}
77      Should Be Equal As Strings    ${resp.status_code}     202
78      Wait Until Keyword Succeeds    10 min    5 sec    VerifyDeployStatus  DEPLOYED
79
80
81 QueryPolicies
82      [Documentation]    Verify the new policies deployed
83      ${auth}=    Create List    policyadmin    zb!XztG34
84      Log    Creating session http://${POLICY_PAP_IP}
85      ${session}=    Create Session      policy  http://${POLICY_PAP_IP}   auth=${auth}
86      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
87      ${resp}=   GET On Session     policy  /policy/pap/v1/policies/deployed     headers=${headers}
88      Log    Received response from policy-pap {resp.text}
89      Should Be Equal As Strings    ${resp.status_code}     200
90      Dictionary Should Contain Value  ${resp.json()[0]}  onap.policies.native.apex.ac.element
91
92
93 QueryPolicyTypes
94      [Documentation]    Verify the new policy types created
95      ${auth}=    Create List    policyadmin    zb!XztG34
96      Log    Creating session http://${POLICY_API_IP}}:6969
97      ${session}=    Create Session      policy  http://${POLICY_API_IP}   auth=${auth}
98      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
99      ${resp}=   GET On Session     policy  /policy/api/v1/policytypes     headers=${headers}
100      Log    Received response from policy-api ${resp.text}
101      Should Be Equal As Strings    ${resp.status_code}     200
102      List Should Contain Value  ${resp.json()['policy_types']}  onap.policies.native.Apex
103
104
105 UnDeployAutomationComposition
106      [Documentation]  UnDeploy automation composition.
107      ${auth}=    Create List    runtimeUser    zb!XztG34
108      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
109      ${postjson}=  Get file  ${CURDIR}/data/UndeployAC.json
110      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
111      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
112      ${resp}=   PUT On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}   data=${postjson}   headers=${headers}
113      Log    Received response from runtime acm ${resp.text}
114      Should Be Equal As Strings    ${resp.status_code}     202
115      Wait Until Keyword Succeeds    10 min    5 sec    VerifyDeployStatus  UNDEPLOYED
116
117
118 UnInstantiateAutomationComposition
119      [Documentation]  Delete automation composition instance.
120      ${auth}=    Create List    runtimeUser    zb!XztG34
121      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
122      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
123      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
124      ${resp}=   DELETE On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}     headers=${headers}
125      Log    Received response from runtime acm ${resp.text}
126      Should Be Equal As Strings    ${resp.status_code}     200
127
128
129 DePrimeACDefinitions
130      [Documentation]  DePrime automation composition definition
131      ${auth}=    Create List    runtimeUser    zb!XztG34
132      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
133      ${postjson}=  Get file  ${CURDIR}/data/ACDepriming.json
134      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
135      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
136      ${resp}=   PUT On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}   data=${postjson}  headers=${headers}
137      Should Be Equal As Strings    ${resp.status_code}     202
138      Wait Until Keyword Succeeds    2 min    5 sec    VerifyPriming  COMMISSIONED
139
140
141 DeleteACDefinition
142      [Documentation]  Delete automation composition definition.
143      ${auth}=    Create List    runtimeUser    zb!XztG34
144      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
145      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
146      ${headers}=  Create Dictionary     Accept=application/yaml    Content-Type=application/yaml
147      ${resp}=   DELETE On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}  headers=${headers}
148      Log    Received response from runtime acm ${resp.text}
149      Should Be Equal As Strings    ${resp.status_code}     200
150
151
152
153 *** Keywords ***
154
155 VerifyPriming
156     [Arguments]  ${primestate}
157     [Documentation]    Verify the AC definitions are primed to the participants
158     ${auth}=    Create List    runtimeUser    zb!XztG34
159     Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
160     ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
161     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
162     ${resp}=   GET On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}   headers=${headers}
163     Should Be Equal As Strings    ${resp.status_code}   200
164     Run Keyword If  ${resp.status_code}==200  Should Be Equal As Strings  ${resp.json()['state']}  ${primestate}
165
166 VerifyDeployStatus
167      [Arguments]  ${deploystate}
168      [Documentation]  Verify the Deploy status of automation composition.
169      ${auth}=    Create List    runtimeUser    zb!XztG34
170      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
171      ${postjson}=  Get file  ${CURDIR}/data/DeployAC.json
172      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
173      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
174      ${resp}=   GET On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}     headers=${headers}
175      Should Be Equal As Strings    ${resp.status_code}     200
176      Run Keyword If  ${resp.status_code}==200  Should Be Equal As Strings  ${resp.json()['deployState']}  ${deploystate}
177