[DCAEGEN2] CSIT Update to Read all Subscriptions and it's associated NFS
[integration/csit.git] / tests / dcaegen2-services-pmsh / testcases / pmsh.robot
1 *** Settings ***
2 Documentation     Testing PMSH functionality
3
4 Library           OperatingSystem
5 Library           RequestsLibrary
6 Library           String
7 Library           Process
8
9 Resource          ../../common.robot
10 Test Teardown     Delete All Sessions
11
12
13 *** Variables ***
14
15 ${PMSH_BASE_URL}                    https://${PMSH_IP}:8443
16 ${MR_BASE_URL}                      http://${MR_IP_ADDRESS}:3904
17 ${CBS_BASE_URL}                     https://${CBS_SIM_IP_ADDRESS}:10443
18 ${SUBSCRIPTION_ENDPOINT}            /subscription
19 ${POLICY_PUBLISH_MR_TOPIC}          /events/unauthenticated.PMSH_CL_INPUT
20 ${AAI_MR_TOPIC}                     /events/AAI_EVENT
21
22 ${MR_AAI_PNF_CREATED}                       %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/aai-pnf-create.json
23 ${MR_AAI_PNF_REMOVED}                       %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/aai-pnf-delete.json
24 ${MR_POLICY_RESPONSE_PNF_EXISTING}          %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/policy-sub-created-pnf-existing.json
25 ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}     %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/cbs-expectation-unlocked-config.json
26 ${CREATE_SUBSCRIPTION_DATA}                 %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/create_subscription_request.json
27 ${CREATE_SECOND_SUBSCRIPTION_DATA}          %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/create_second_subscription_request.json
28 ${CREATE_SUBSCRIPTION_BAD_DATA}             %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/create_subscription_bad_request.json
29 ${CREATE_SUBSCRIPTION_SCHEMA_ERROR_DATA}    %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/create_subscription_schema_error_request.json
30 ${ADMIN_STATE_LOCKED_PATTERN}       'administrativeState': 'LOCKED'
31 ${CLI_EXEC_GET_CBS_CONFIG_FIRST}    docker exec pmsh /bin/sh -c "grep -m 1 'PMSH config from CBS' /var/log/ONAP/dcaegen2/services/pmsh/application.log"
32
33 *** Test Cases ***
34 Verify Get subscriptions with Network Functions None
35     [Tags]                          PMSH_01
36     [Documentation]                 Verify Get all subscriptions when there are no defined subscriptions
37     [Timeout]                       10 seconds
38     ${resp}=                        GetSubsCall    ${SUBSCRIPTION_ENDPOINT}     ""
39     Should Be True                  ${resp.status_code} == 200
40     Should Contain                  ${resp.text}                     []
41
42 Verify Create Subscriptions API
43     [Tags]                          PMSH_07
44     [Documentation]                 Verify Create Subscription API
45     [Timeout]                       60 seconds
46     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_DATA}
47     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
48     Should Be True                  ${resp.status_code} == 201
49      ${resp}=                       GetSubsCall    ${SUBSCRIPTION_ENDPOINT}   "/subs_01"
50     Should Be Equal As Strings      ${resp.json()[0]['subscription']['subscriptionName']}       subs_01
51
52 Verify database tables exist and are empty
53     [Tags]                          PMSH_02
54     [Documentation]                 Verify database has been created and is empty
55     [Timeout]                       10 seconds
56     ${resp}=                        GetSubsCall    ${SUBSCRIPTION_ENDPOINT}     ""
57     Should Be True                  ${resp.status_code} == 200
58     Should Contain                  ${resp.text}                     []
59
60 Verify PNF detected in AAI when administrative state unlocked
61     [Tags]                          PMSH_03
62     [Documentation]                 Verify PNF detected when administrative state unlocked
63     [Timeout]                       60 seconds
64     SetAdministrativeStateToUnlocked
65     Sleep                           31             Allow PMSH time to pick up changes in CBS config
66     ${resp}=                        GetMeasGrpCall    /subscription/subs_01/measurementGroups/msg_grp_01
67     Should Be Equal As Strings      ${resp.json()['subscriptionName']}      subs_01
68     Should Be Equal As Strings      ${resp.json()['administrativeState']}       UNLOCKED
69     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfName']}            pnf-existing
70     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfMgStatus']}      PENDING_CREATE
71
72 Verify Policy response on MR is handled
73     [Tags]                          PMSH_04
74     [Documentation]                 Verify policy response on MR is handled
75     [Timeout]                       60 seconds
76     SimulatePolicyResponse          ${MR_POLICY_RESPONSE_PNF_EXISTING}
77     Sleep                           31 seconds      Ensure Policy response on MR is picked up
78     ${resp}=                        GetMeasGrpCall    /subscription/subs_01/measurementGroups/msg_grp_01
79     Should Be Equal As Strings      ${resp.json()['subscriptionName']}      subs_01
80     Should Be Equal As Strings      ${resp.json()['administrativeState']}       UNLOCKED
81     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfName']}            pnf-existing
82     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfMgStatus']}     CREATED
83
84 Verify AAI event on MR detailing new PNF being detected is handled
85     [Tags]                          PMSH_05
86     [Documentation]                 Verify PNF created AAI event on MR is handled
87     [Timeout]                       60 seconds
88     SimulateNewPNF                  ${MR_AAI_PNF_CREATED}
89     Sleep                           31 seconds      Ensure AAI event on MR is picked up
90     ${resp}=                        GetMeasGrpCall    /subscription/subs_01/measurementGroups/msg_grp_01
91     Should Be Equal As Strings      ${resp.json()['subscriptionName']}      subs_01
92     Should Be Equal As Strings      ${resp.json()['administrativeState']}       UNLOCKED
93     Should Be Equal As Strings      ${resp.json()['networkFunctions'][1]['nfName']}            pnf_newly_discovered
94     Should Be Equal As Strings      ${resp.json()['networkFunctions'][1]['nfMgStatus']}      PENDING_CREATE
95
96 Verify AAI event on MR detailing PNF being deleted is handled
97     [Tags]                          PMSH_06
98     [Documentation]                 Verify PNF deleted AAI event on MR is handled
99     [Timeout]                       60 seconds
100     SimulateDeletedPNF              ${MR_AAI_PNF_REMOVED}
101     Sleep                           31 seconds      Ensure AAI event on MR is picked up
102     ${resp}=                        GetMeasGrpCall    /subscription/subs_01/measurementGroups/msg_grp_01
103     Should Not Contain              ${resp.text}    pnf_newly_discovered
104
105 Verify Create Subscription API for duplicate subscription Id
106     [Tags]                          PMSH_08
107     [Documentation]                 Verify Create Subscription API
108     [Timeout]                       60 seconds
109     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_DATA}
110     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
111     Should Be True                  ${resp.status_code} == 409
112     Should Contain                  ${resp.json()}      subscription Name: subs_01 already exists.
113
114 Verify Create Subscription API for schema error
115     [Tags]                          PMSH_09
116     [Documentation]                 Verify Create Subscription API
117     [Timeout]                       60 seconds
118     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_SCHEMA_ERROR_DATA}
119     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
120     Should Be True                  ${resp.status_code} == 400
121     Should Contain                  ${resp.json()['detail']}      'administrativeState' is a required property - 'subscription.measurementGroups.0.measurementGroup'
122
123 Verify Create Subscription API for filter values missing
124     [Tags]                          PMSH_10
125     [Documentation]                 Verify Create Subscription API
126     [Timeout]                       60 seconds
127     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_BAD_DATA}
128     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
129     Should Be True                  ${resp.status_code} == 400
130     Should Contain                  ${resp.json()}      At least one filter within nfFilter must not be empty
131
132 Verify Get Measurement Group with Network Functions
133     [Tags]                          PMSH_11
134     [Documentation]                 Verify Get Measurement Group with Network Functions by using MGName and SubName
135     [Timeout]                       60 seconds
136     ${resp}=                        GetMeasGrpWithNFSCall     /subscription/subs_01/measurementGroups/msg_grp_01
137     ${nf_length}=                   Get length  ${resp.json()['networkFunctions']}
138     Should Be True                  ${resp.status_code} == 200
139     Should Be Equal As Strings      ${resp.json()['subscriptionName']}      subs_01
140     Should Be Equal As Strings      ${resp.json()['measurementGroupName']}      msg_grp_01
141     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfName']}      pnf-existing
142     Should be equal as numbers      ${nf_length}  1
143
144 Verify Get single subscription with Network Functions
145     [Tags]                          PMSH_12
146     [Documentation]                 Verify Get single subscription with Network Functions by using subscription name
147     [Timeout]                       60 seconds
148     ${resp}=                        GetSubsCall    ${SUBSCRIPTION_ENDPOINT}/subs_01  ""
149     ${nf_length}=                   Get length  ${resp.json()['subscription']['nfs']}
150     Should Be True                  ${resp.status_code} == 200
151     Should Be Equal As Strings      ${resp.json()['subscription']['subscriptionName']}      subs_01
152     Should Be Equal As Strings      ${resp.json()['subscription']['nfs'][0]}      pnf-existing
153         Should Be Equal As Strings      ${resp.json()['subscription']['measurementGroups'][0]['measurementGroup']['measurementGroupName']}  msg_grp_02
154     Should be equal as numbers      ${nf_length}  1
155
156 Verify Get single subscription with Network Functions None
157     [Tags]                          PMSH_13
158     [Documentation]                 Verify Get single subscription with Network Functions when there is no defined subscription
159     [Timeout]                       60 seconds
160     ${resp}=                        GetSubsCall    ${SUBSCRIPTION_ENDPOINT}/sub_none  ""
161     Should Be True                  ${resp.status_code} == 404
162     Should Be Equal As Strings      ${resp.json()['error']}     Subscription was not defined with the name : sub_none
163
164 Verify Get subscriptions with Network Functions
165     [Tags]                          PMSH_14
166     [Documentation]                 Verify Get all defined subscriptions with associated Network Functions
167     [Timeout]                       60 seconds
168     ${json_value}=                  json_from_file                  ${CREATE_SECOND_SUBSCRIPTION_DATA}
169     ${resp_post}=                   PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
170     ${resp}=                        GetSubsCall    ${SUBSCRIPTION_ENDPOINT}  ""
171     ${nf_length_first}=             Get length  ${resp.json()[0]['subscription']['nfs']}
172     ${nf_length_second}=            Get length  ${resp.json()[1]['subscription']['nfs']}
173     Should Be True                  ${resp.status_code} == 200
174     Should Be Equal As Strings      ${resp.json()[0]['subscription']['subscriptionName']}      subs_01
175     Should Be Equal As Strings      ${resp.json()[0]['subscription']['nfs'][0]}      pnf-existing
176         Should Be Equal As Strings      ${resp.json()[0]['subscription']['measurementGroups'][0]['measurementGroup']['measurementGroupName']}  msg_grp_02
177     Should be equal as numbers      ${nf_length_first}  1
178     Should Be Equal As Strings      ${resp.json()[1]['subscription']['subscriptionName']}      subs_02
179     Should Be Equal As Strings      ${resp.json()[1]['subscription']['nfs'][0]}      pnf-existing
180         Should Be Equal As Strings      ${resp.json()[1]['subscription']['measurementGroups'][0]['measurementGroup']['measurementGroupName']}  msg_grp_04
181     Should be equal as numbers      ${nf_length_second}  1
182
183
184 *** Keywords ***
185
186 SetAdministrativeStateToUnlocked
187     ${data}=            Get Data From File      ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}
188     Create Session      cbs_sim_session   ${CBS_BASE_URL}    verify=false
189     ${resp}=            PUT On Session    cbs_sim_session    url=/clear  data={"path": "/service_component_all/.*"}
190     Should Be True      ${resp.status_code} == 200
191     Sleep               2                 Allow CBS time to set expectation
192     ${resp} =           PUT On Session    cbs_sim_session    url=/expectation     data=${data}
193     Should Be True      ${resp.status_code} == 201
194
195
196 SimulatePolicyResponse
197     [Arguments]                     ${expected_contents}
198     ${json_value}=                  json_from_file                  ${expected_contents}
199     ${resp}=                                            PostMrCall                                  ${POLICY_PUBLISH_MR_TOPIC}     ${json_value}
200     log                                                 ${resp.text}
201     Should Be Equal As Strings          ${resp.status_code}             200
202     ${count}=                           Evaluate                                        $resp.json().get('count')
203     log                                                         'JSON Response Code:'${resp}
204
205 SimulateNewPNF
206     [Arguments]                     ${expected_contents}
207     ${json_value}=                  json_from_file                  ${expected_contents}
208     ${resp}=                                            PostMrCall                                      ${AAI_MR_TOPIC}      ${json_value}
209     log                                                 ${resp.text}
210     Should Be Equal As Strings          ${resp.status_code}             200
211     ${count}=                           Evaluate                                        $resp.json().get('count')
212     log                                                         'JSON Response Code:'${resp}
213
214 SimulateDeletedPNF
215     [Arguments]                     ${expected_contents}
216     ${json_value}=                  json_from_file                  ${expected_contents}
217     ${resp}=                                            PostMrCall                                      ${AAI_MR_TOPIC}      ${json_value}
218     log                                                 ${resp.text}
219     Should Be Equal As Strings          ${resp.status_code}             200
220     ${count}=                           Evaluate                                        $resp.json().get('count')
221     log                                                         'JSON Response Code:'${resp}
222
223 PostMrCall
224     [Arguments]     ${url}     ${data}
225     Create Session  mr_sim_session       ${MR_BASE_URL}    verify=false
226     ${headers}=     Create Dictionary    Accept=application/json     Content-Type=application/json
227     ${resp}=        POST On Session      mr_sim_session    url=${url}    json=${data}     headers=${headers}
228     [Return]        ${resp}
229
230 GetSubsCall
231     [Arguments]     ${url}      ${url_path_param}
232     Create Session  pmsh_session      ${PMSH_BASE_URL}    verify=false
233     ${resp}=        GET On Session    pmsh_session        url=${url}    data={"path": {url_path_param}}    expected_status=any
234     [Return]        ${resp}
235
236 GetMeasGrpCall
237     [Arguments]     ${url}
238     Create Session  pmsh_session      ${PMSH_BASE_URL}    verify=false
239     ${resp}=        GET On Session    pmsh_session        url=${url}
240     [Return]        ${resp}
241
242 GetMeasGrpWithNFSCall
243     [Arguments]     ${url}
244     Create Session  pmsh_session      ${PMSH_BASE_URL}    verify=false
245     ${resp}=        GET On Session    pmsh_session        url=${url}
246     [Return]        ${resp}
247
248 PostSubscriptionCall
249     [Arguments]     ${url}     ${data}
250     Create Session  pmsh_sub_session       ${PMSH_BASE_URL}    verify=false
251     ${headers}=     Create Dictionary    Accept=application/json     Content-Type=application/json
252     ${resp}=        POST On Session      pmsh_sub_session    url=${url}    json=${data}     headers=${headers}  expected_status=anything
253     [Return]        ${resp}