Fix CSIT failure in clamp.
[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      ${K8sEnabled}=    Convert To Boolean    ${CLAMP_K8S_TEST}
59      Run Keyword If    '${K8sEnabled}'=='True'    set Suite variable  ${instantiationfile}  AcK8s.json
60
61      ...    ELSE    set Suite variable  ${instantiationfile}  AcDocker.json
62      ${postjson}=  Get file  ${CURDIR}/data/${instantiationfile}
63      ${updatedpostjson}=   Replace String     ${postjson}     COMPOSITIONIDPLACEHOLDER       ${compositionId}
64      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
65      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
66      ${resp}=   POST On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances   data=${updatedpostjson}  headers=${headers}
67      Log    Received response from runtime acm ${resp.text}
68      ${respyaml}=  yaml.Safe Load  ${resp.text}
69      set Suite variable  ${instanceId}    ${respyaml["instanceId"]}
70      Should Be Equal As Strings    ${resp.status_code}     201
71
72 DeployAutomationComposition
73      [Documentation]  Deploy automation composition.
74      ${auth}=    Create List    runtimeUser    zb!XztG34
75      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
76      ${postjson}=  Get file  ${CURDIR}/data/DeployAC.json
77      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
78      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
79      ${resp}=   PUT On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}   data=${postjson}  headers=${headers}
80      Log    Received response from runtime acm ${resp.text}
81      Should Be Equal As Strings    ${resp.status_code}     202
82      Wait Until Keyword Succeeds    10 min    5 sec    VerifyDeployStatus  DEPLOYED
83
84
85 QueryPolicies
86      [Documentation]    Verify the new policies deployed
87      ${auth}=    Create List    policyadmin    zb!XztG34
88      Log    Creating session http://${POLICY_PAP_IP}
89      ${session}=    Create Session      policy  http://${POLICY_PAP_IP}   auth=${auth}
90      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
91      ${resp}=   GET On Session     policy  /policy/pap/v1/policies/deployed     headers=${headers}
92      Log    Received response from policy-pap {resp.text}
93      Should Be Equal As Strings    ${resp.status_code}     200
94      Dictionary Should Contain Value  ${resp.json()[0]}  onap.policies.native.apex.ac.element
95
96
97 QueryPolicyTypes
98      [Documentation]    Verify the new policy types created
99      ${auth}=    Create List    policyadmin    zb!XztG34
100      Log    Creating session http://${POLICY_API_IP}}:6969
101      ${session}=    Create Session      policy  http://${POLICY_API_IP}   auth=${auth}
102      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
103      ${resp}=   GET On Session     policy  /policy/api/v1/policytypes     headers=${headers}
104      Log    Received response from policy-api ${resp.text}
105      Should Be Equal As Strings    ${resp.status_code}     200
106      List Should Contain Value  ${resp.json()['policy_types']}  onap.policies.native.Apex
107
108
109 UnDeployAutomationComposition
110      [Documentation]  UnDeploy automation composition.
111      ${auth}=    Create List    runtimeUser    zb!XztG34
112      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
113      ${postjson}=  Get file  ${CURDIR}/data/UndeployAC.json
114      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
115      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
116      ${resp}=   PUT On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}   data=${postjson}   headers=${headers}
117      Log    Received response from runtime acm ${resp.text}
118      Should Be Equal As Strings    ${resp.status_code}     202
119      Wait Until Keyword Succeeds    10 min    5 sec    VerifyDeployStatus  UNDEPLOYED
120
121
122 UnInstantiateAutomationComposition
123      [Documentation]  Delete automation composition instance.
124      ${auth}=    Create List    runtimeUser    zb!XztG34
125      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
126      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
127      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
128      ${resp}=   DELETE On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}     headers=${headers}
129      Log    Received response from runtime acm ${resp.text}
130      Should Be Equal As Strings    ${resp.status_code}     202
131      Wait Until Keyword Succeeds    1 min    5 sec    VerifyUninstantiated
132
133
134 DePrimeACDefinitions
135      [Documentation]  DePrime automation composition definition
136      ${auth}=    Create List    runtimeUser    zb!XztG34
137      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
138      ${postjson}=  Get file  ${CURDIR}/data/ACDepriming.json
139      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
140      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
141      ${resp}=   PUT On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}   data=${postjson}  headers=${headers}
142      Should Be Equal As Strings    ${resp.status_code}     202
143      Wait Until Keyword Succeeds    2 min    5 sec    VerifyPriming  COMMISSIONED
144
145
146 DeleteACDefinition
147      [Documentation]  Delete automation composition definition.
148      ${auth}=    Create List    runtimeUser    zb!XztG34
149      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
150      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
151      ${headers}=  Create Dictionary     Accept=application/yaml    Content-Type=application/yaml
152      ${resp}=   DELETE On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}  headers=${headers}
153      Log    Received response from runtime acm ${resp.text}
154      Should Be Equal As Strings    ${resp.status_code}     200
155
156
157
158 *** Keywords ***
159
160 VerifyPriming
161     [Arguments]  ${primestate}
162     [Documentation]    Verify the AC definitions are primed to the participants
163     ${auth}=    Create List    runtimeUser    zb!XztG34
164     Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
165     ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
166     ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
167     ${resp}=   GET On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}   headers=${headers}
168     Should Be Equal As Strings    ${resp.status_code}   200
169     Run Keyword If  ${resp.status_code}==200  Should Be Equal As Strings  ${resp.json()['state']}  ${primestate}
170
171 VerifyDeployStatus
172      [Arguments]  ${deploystate}
173      [Documentation]  Verify the Deploy status of automation composition.
174      ${auth}=    Create List    runtimeUser    zb!XztG34
175      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
176      ${postjson}=  Get file  ${CURDIR}/data/DeployAC.json
177      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
178      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
179      ${resp}=   GET On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances/${instanceId}     headers=${headers}
180      Should Be Equal As Strings    ${resp.status_code}     200
181      Run Keyword If  ${resp.status_code}==200  Should Be Equal As Strings  ${resp.json()['deployState']}  ${deploystate}
182
183 VerifyUninstantiated
184      [Documentation]  Verify the Uninstantiation of automation composition.
185      ${auth}=    Create List    runtimeUser    zb!XztG34
186      Log    Creating session http://${POLICY_RUNTIME_ACM_IP}
187      ${session}=    Create Session      policy  http://${POLICY_RUNTIME_ACM_IP}   auth=${auth}
188      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json
189      ${resp}=   GET On Session     policy  /onap/policy/clamp/acm/v2/compositions/${compositionId}/instances     headers=${headers}
190      Should Be Equal As Strings    ${resp.status_code}     200
191      Run Keyword If  ${resp.status_code}==200  Length Should Be  ${resp.json()['automationCompositionList']}  0
192
193