[DCAEGEN2] CSIT Update for Read Subscription and it's associated NFS by subName
[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_SUBSCRIPTION_BAD_DATA}             %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/create_subscription_bad_request.json
28 ${CREATE_SUBSCRIPTION_SCHEMA_ERROR_DATA}    %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/create_subscription_schema_error_request.json
29 ${ADMIN_STATE_LOCKED_PATTERN}       'administrativeState': 'LOCKED'
30 ${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"
31
32 *** Test Cases ***
33
34 Verify Create Subscriptions API
35     [Tags]                          PMSH_07
36     [Documentation]                 Verify Create Subscription API
37     [Timeout]                       60 seconds
38     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_DATA}
39     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
40     Should Be True                  ${resp.status_code} == 201
41      ${resp}=                       GetSubsCall    ${SUBSCRIPTION_ENDPOINT}   "/subs_01"
42     Should Be Equal As Strings      ${resp.json()[0]['subscription']['subscriptionName']}       subs_01
43
44 Verify database tables exist and are empty
45     [Tags]                          PMSH_02
46     [Documentation]                 Verify database has been created and is empty
47     [Timeout]                       10 seconds
48     ${resp}=                        GetSubsCall    ${SUBSCRIPTION_ENDPOINT}     ""
49     Should Be True                  ${resp.status_code} == 200
50     Should Contain                  ${resp.text}                     []
51
52 Verify PNF detected in AAI when administrative state unlocked
53     [Tags]                          PMSH_03
54     [Documentation]                 Verify PNF detected when administrative state unlocked
55     [Timeout]                       60 seconds
56     SetAdministrativeStateToUnlocked
57     Sleep                           31             Allow PMSH time to pick up changes in CBS config
58     ${resp}=                        GetMeasGrpCall    /subscription/subs_01/measurementGroups/msg_grp_01
59     Should Be Equal As Strings      ${resp.json()['subscriptionName']}      subs_01
60     Should Be Equal As Strings      ${resp.json()['administrativeState']}       UNLOCKED
61     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfName']}            pnf-existing
62     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfMgStatus']}      PENDING_CREATE
63
64 Verify Policy response on MR is handled
65     [Tags]                          PMSH_04
66     [Documentation]                 Verify policy response on MR is handled
67     [Timeout]                       60 seconds
68     SimulatePolicyResponse          ${MR_POLICY_RESPONSE_PNF_EXISTING}
69     Sleep                           31 seconds      Ensure Policy response on MR is picked up
70     ${resp}=                        GetMeasGrpCall    /subscription/subs_01/measurementGroups/msg_grp_01
71     Should Be Equal As Strings      ${resp.json()['subscriptionName']}      subs_01
72     Should Be Equal As Strings      ${resp.json()['administrativeState']}       UNLOCKED
73     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfName']}            pnf-existing
74     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfMgStatus']}     CREATED
75
76 Verify AAI event on MR detailing new PNF being detected is handled
77     [Tags]                          PMSH_05
78     [Documentation]                 Verify PNF created AAI event on MR is handled
79     [Timeout]                       60 seconds
80     SimulateNewPNF                  ${MR_AAI_PNF_CREATED}
81     Sleep                           31 seconds      Ensure AAI event on MR is picked up
82     ${resp}=                        GetMeasGrpCall    /subscription/subs_01/measurementGroups/msg_grp_01
83     Should Be Equal As Strings      ${resp.json()['subscriptionName']}      subs_01
84     Should Be Equal As Strings      ${resp.json()['administrativeState']}       UNLOCKED
85     Should Be Equal As Strings      ${resp.json()['networkFunctions'][1]['nfName']}            pnf_newly_discovered
86     Should Be Equal As Strings      ${resp.json()['networkFunctions'][1]['nfMgStatus']}      PENDING_CREATE
87
88 Verify AAI event on MR detailing PNF being deleted is handled
89     [Tags]                          PMSH_06
90     [Documentation]                 Verify PNF deleted AAI event on MR is handled
91     [Timeout]                       60 seconds
92     SimulateDeletedPNF              ${MR_AAI_PNF_REMOVED}
93     Sleep                           31 seconds      Ensure AAI event on MR is picked up
94     ${resp}=                        GetMeasGrpCall    /subscription/subs_01/measurementGroups/msg_grp_01
95     Should Not Contain              ${resp.text}    pnf_newly_discovered
96
97 Verify Create Subscription API for duplicate subscription Id
98     [Tags]                          PMSH_08
99     [Documentation]                 Verify Create Subscription API
100     [Timeout]                       60 seconds
101     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_DATA}
102     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
103     Should Be True                  ${resp.status_code} == 409
104     Should Contain                  ${resp.json()}      subscription Name: subs_01 already exists.
105
106 Verify Create Subscription API for schema error
107     [Tags]                          PMSH_09
108     [Documentation]                 Verify Create Subscription API
109     [Timeout]                       60 seconds
110     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_SCHEMA_ERROR_DATA}
111     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
112     Should Be True                  ${resp.status_code} == 400
113     Should Contain                  ${resp.json()['detail']}      'administrativeState' is a required property - 'subscription.measurementGroups.0.measurementGroup'
114
115 Verify Create Subscription API for filter values missing
116     [Tags]                          PMSH_10
117     [Documentation]                 Verify Create Subscription API
118     [Timeout]                       60 seconds
119     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_BAD_DATA}
120     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
121     Should Be True                  ${resp.status_code} == 400
122     Should Contain                  ${resp.json()}      At least one filter within nfFilter must not be empty
123
124 Verify Get Measurement Group with Network Functions
125     [Tags]                          PMSH_11
126     [Documentation]                 Verify Get Measurement Group with Network Functions by using MGName and SubName
127     [Timeout]                       60 seconds
128     ${resp}=                        GetMeasGrpWithNFSCall     /subscription/subs_01/measurementGroups/msg_grp_01
129     ${nf_length}=                   Get length  ${resp.json()['networkFunctions']}
130     Should Be True                  ${resp.status_code} == 200
131     Should Be Equal As Strings      ${resp.json()['subscriptionName']}      subs_01
132     Should Be Equal As Strings      ${resp.json()['measurementGroupName']}      msg_grp_01
133     Should Be Equal As Strings      ${resp.json()['networkFunctions'][0]['nfName']}      pnf-existing
134     Should be equal as numbers      ${nf_length}  1
135
136 Verify Get single subscription with Network Functions
137     [Tags]                          PMSH_12
138     [Documentation]                 Verify Get single subscription with Network Functions by using subscription name
139     [Timeout]                       60 seconds
140     ${resp}=                        GetSubsCall    ${SUBSCRIPTION_ENDPOINT}/subs_01  ""
141     ${nf_length}=                   Get length  ${resp.json()['subscription']['nfs']}
142     Should Be True                  ${resp.status_code} == 200
143     Should Be Equal As Strings      ${resp.json()['subscription']['subscriptionName']}      subs_01
144     Should Be Equal As Strings      ${resp.json()['subscription']['nfs'][0]}      pnf-existing
145         Should Be Equal As Strings      ${resp.json()['subscription']['measurementGroups'][0]['measurementGroup']['measurementGroupName']}  msg_grp_02
146     Should be equal as numbers      ${nf_length}  1
147
148 Verify Get single subscription with Network Functions None
149     [Tags]                          PMSH_13
150     [Documentation]                 Verify Get single subscription with Network Functions when there is no defined subscription
151     [Timeout]                       60 seconds
152     ${resp}=                        GetSubsCall    ${SUBSCRIPTION_ENDPOINT}/sub_none  ""
153     Should Be True                  ${resp.status_code} == 404
154     Should Be Equal As Strings      ${resp.json()['error']}     Subscription was not defined with the name : sub_none
155
156
157 *** Keywords ***
158
159 SetAdministrativeStateToUnlocked
160     ${data}=            Get Data From File      ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}
161     Create Session      cbs_sim_session   ${CBS_BASE_URL}    verify=false
162     ${resp}=            PUT On Session    cbs_sim_session    url=/clear  data={"path": "/service_component_all/.*"}
163     Should Be True      ${resp.status_code} == 200
164     Sleep               2                 Allow CBS time to set expectation
165     ${resp} =           PUT On Session    cbs_sim_session    url=/expectation     data=${data}
166     Should Be True      ${resp.status_code} == 201
167
168
169 SimulatePolicyResponse
170     [Arguments]                     ${expected_contents}
171     ${json_value}=                  json_from_file                  ${expected_contents}
172     ${resp}=                                            PostMrCall                                  ${POLICY_PUBLISH_MR_TOPIC}     ${json_value}
173     log                                                 ${resp.text}
174     Should Be Equal As Strings          ${resp.status_code}             200
175     ${count}=                           Evaluate                                        $resp.json().get('count')
176     log                                                         'JSON Response Code:'${resp}
177
178 SimulateNewPNF
179     [Arguments]                     ${expected_contents}
180     ${json_value}=                  json_from_file                  ${expected_contents}
181     ${resp}=                                            PostMrCall                                      ${AAI_MR_TOPIC}      ${json_value}
182     log                                                 ${resp.text}
183     Should Be Equal As Strings          ${resp.status_code}             200
184     ${count}=                           Evaluate                                        $resp.json().get('count')
185     log                                                         'JSON Response Code:'${resp}
186
187 SimulateDeletedPNF
188     [Arguments]                     ${expected_contents}
189     ${json_value}=                  json_from_file                  ${expected_contents}
190     ${resp}=                                            PostMrCall                                      ${AAI_MR_TOPIC}      ${json_value}
191     log                                                 ${resp.text}
192     Should Be Equal As Strings          ${resp.status_code}             200
193     ${count}=                           Evaluate                                        $resp.json().get('count')
194     log                                                         'JSON Response Code:'${resp}
195
196 PostMrCall
197     [Arguments]     ${url}     ${data}
198     Create Session  mr_sim_session       ${MR_BASE_URL}    verify=false
199     ${headers}=     Create Dictionary    Accept=application/json     Content-Type=application/json
200     ${resp}=        POST On Session      mr_sim_session    url=${url}    json=${data}     headers=${headers}
201     [Return]        ${resp}
202
203 GetSubsCall
204     [Arguments]     ${url}      ${url_path_param}
205     Create Session  pmsh_session      ${PMSH_BASE_URL}    verify=false
206     ${resp}=        GET On Session    pmsh_session        url=${url}    data={"path": {url_path_param}}    expected_status=any
207     [Return]        ${resp}
208
209 GetMeasGrpCall
210     [Arguments]     ${url}
211     Create Session  pmsh_session      ${PMSH_BASE_URL}    verify=false
212     ${resp}=        GET On Session    pmsh_session        url=${url}
213     [Return]        ${resp}
214
215 GetMeasGrpWithNFSCall
216     [Arguments]     ${url}
217     Create Session  pmsh_session      ${PMSH_BASE_URL}    verify=false
218     ${resp}=        GET On Session    pmsh_session        url=${url}
219     [Return]        ${resp}
220
221 PostSubscriptionCall
222     [Arguments]     ${url}     ${data}
223     Create Session  pmsh_sub_session       ${PMSH_BASE_URL}    verify=false
224     ${headers}=     Create Dictionary    Accept=application/json     Content-Type=application/json
225     ${resp}=        POST On Session      pmsh_sub_session    url=${url}    json=${data}     headers=${headers}  expected_status=anything
226     [Return]        ${resp}