[DCAEGEN2] PMSH CSIT changes for public Subscription APIs
[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 ${SUBSCRIPTIONS_ENDPOINT}           /subscriptions
19 ${SUBSCRIPTION_ENDPOINT}            /subscription
20 ${POLICY_PUBLISH_MR_TOPIC}          /events/unauthenticated.PMSH_CL_INPUT
21 ${AAI_MR_TOPIC}                     /events/AAI_EVENT
22
23 ${MR_AAI_PNF_CREATED}                       %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/aai-pnf-create.json
24 ${MR_AAI_PNF_REMOVED}                       %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/aai-pnf-delete.json
25 ${MR_POLICY_RESPONSE_PNF_EXISTING}          %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/policy-sub-created-pnf-existing.json
26 ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}     %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/cbs-expectation-unlocked-config.json
27 ${CREATE_SUBSCRIPTION_DATA}                 %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/create_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
35 Verify Create Subscription API
36     [Tags]                          PMSH_07
37     [Documentation]                 Verify Create Subscription API
38     [Timeout]                       60 seconds
39     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_DATA}
40     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
41     Should Be True                  ${resp.status_code} == 201
42
43 Verify database tables exist and are empty
44     [Tags]                          PMSH_02
45     [Documentation]                 Verify database has been created and is empty
46     [Timeout]                       10 seconds
47     ${resp}=                        GetSubsCall    ${SUBSCRIPTIONS_ENDPOINT}
48     Should Be True                  ${resp.status_code} == 200
49     Should Contain                  ${resp.text}                     []
50
51 Verify PNF detected in AAI when administrative state unlocked
52     [Tags]                          PMSH_03
53     [Documentation]                 Verify PNF detected when administrative state unlocked
54     [Timeout]                       60 seconds
55     SetAdministrativeStateToUnlocked
56     Sleep                           31             Allow PMSH time to pick up changes in CBS config
57     ${resp}=                        GetSubsCall    ${SUBSCRIPTIONS_ENDPOINT}
58     Should Be Equal As Strings      ${resp.json()[1]['subscription_status']}                        UNLOCKED
59     Should Be Equal As Strings      ${resp.json()[1]['network_functions'][0]['nf_name']}            pnf-existing
60     Should Be Equal As Strings      ${resp.json()[1]['network_functions'][0]['nf_sub_status']}      PENDING_CREATE
61
62 Verify Policy response on MR is handled
63     [Tags]                          PMSH_04
64     [Documentation]                 Verify policy response on MR is handled
65     [Timeout]                       60 seconds
66     SimulatePolicyResponse          ${MR_POLICY_RESPONSE_PNF_EXISTING}
67     Sleep                           31 seconds      Ensure Policy response on MR is picked up
68     ${resp}=                        GetSubsCall     ${SUBSCRIPTIONS_ENDPOINT}
69     Should Be Equal As Strings      ${resp.json()[1]['network_functions'][0]['nf_sub_status']}      CREATED
70
71 Verify AAI event on MR detailing new PNF being detected is handled
72     [Tags]                          PMSH_05
73     [Documentation]                 Verify PNF created AAI event on MR is handled
74     [Timeout]                       60 seconds
75     SimulateNewPNF                  ${MR_AAI_PNF_CREATED}
76     Sleep                           31 seconds      Ensure AAI event on MR is picked up
77     ${resp}=                        GetSubsCall     ${SUBSCRIPTIONS_ENDPOINT}
78     Should Be Equal As Strings      ${resp.json()[1]['network_functions'][1]['nf_name']}            pnf_newly_discovered
79     Should Be Equal As Strings      ${resp.json()[1]['network_functions'][1]['nf_sub_status']}      PENDING_CREATE
80
81 Verify AAI event on MR detailing PNF being deleted is handled
82     [Tags]                          PMSH_06
83     [Documentation]                 Verify PNF deleted AAI event on MR is handled
84     [Timeout]                       60 seconds
85     SimulateDeletedPNF              ${MR_AAI_PNF_REMOVED}
86     Sleep                           31 seconds      Ensure AAI event on MR is picked up
87     ${resp}=                        GetSubsCall     ${SUBSCRIPTIONS_ENDPOINT}
88     Should Not Contain              ${resp.text}    pnf_newly_discovered
89
90 Verify Create Subscription API for duplicate subscription Id
91     [Tags]                          PMSH_08
92     [Documentation]                 Verify Create Subscription API
93     [Timeout]                       60 seconds
94     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_DATA}
95     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
96     Should Be True                  ${resp.status_code} == 409
97     Should Contain                  ${resp.json()}      subscription Name: subs_01 already exists.
98
99 Verify Create Subscription API for schema error
100     [Tags]                          PMSH_09
101     [Documentation]                 Verify Create Subscription API
102     [Timeout]                       60 seconds
103     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_SCHEMA_ERROR_DATA}
104     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
105     Should Be True                  ${resp.status_code} == 400
106     Should Contain                  ${resp.json()['detail']}      'administrativeState' is a required property - 'subscription.measurementGroups.0.measurementGroup'
107
108 Verify Create Subscription API for filter values missing
109     [Tags]                          PMSH_10
110     [Documentation]                 Verify Create Subscription API
111     [Timeout]                       60 seconds
112     ${json_value}=                  json_from_file                  ${CREATE_SUBSCRIPTION_BAD_DATA}
113     ${resp}=                        PostSubscriptionCall     ${SUBSCRIPTION_ENDPOINT}   ${json_value}
114     Should Be True                  ${resp.status_code} == 400
115     Should Contain                  ${resp.json()}      At least one filter within nfFilter must not be empty
116
117 *** Keywords ***
118
119 SetAdministrativeStateToUnlocked
120     ${data}=            Get Data From File      ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}
121     Create Session      cbs_sim_session   ${CBS_BASE_URL}    verify=false
122     ${resp}=            PUT On Session    cbs_sim_session    url=/clear  data={"path": "/service_component_all/.*"}
123     Should Be True      ${resp.status_code} == 200
124     Sleep               2                 Allow CBS time to set expectation
125     ${resp} =           PUT On Session    cbs_sim_session    url=/expectation     data=${data}
126     Should Be True      ${resp.status_code} == 201
127
128
129 SimulatePolicyResponse
130     [Arguments]                     ${expected_contents}
131     ${json_value}=                  json_from_file                  ${expected_contents}
132     ${resp}=                                            PostMrCall                                  ${POLICY_PUBLISH_MR_TOPIC}     ${json_value}
133     log                                                 ${resp.text}
134     Should Be Equal As Strings          ${resp.status_code}             200
135     ${count}=                           Evaluate                                        $resp.json().get('count')
136     log                                                         'JSON Response Code:'${resp}
137
138 SimulateNewPNF
139     [Arguments]                     ${expected_contents}
140     ${json_value}=                  json_from_file                  ${expected_contents}
141     ${resp}=                                            PostMrCall                                      ${AAI_MR_TOPIC}      ${json_value}
142     log                                                 ${resp.text}
143     Should Be Equal As Strings          ${resp.status_code}             200
144     ${count}=                           Evaluate                                        $resp.json().get('count')
145     log                                                         'JSON Response Code:'${resp}
146
147 SimulateDeletedPNF
148     [Arguments]                     ${expected_contents}
149     ${json_value}=                  json_from_file                  ${expected_contents}
150     ${resp}=                                            PostMrCall                                      ${AAI_MR_TOPIC}      ${json_value}
151     log                                                 ${resp.text}
152     Should Be Equal As Strings          ${resp.status_code}             200
153     ${count}=                           Evaluate                                        $resp.json().get('count')
154     log                                                         'JSON Response Code:'${resp}
155
156 PostMrCall
157     [Arguments]     ${url}     ${data}
158     Create Session  mr_sim_session       ${MR_BASE_URL}    verify=false
159     ${headers}=     Create Dictionary    Accept=application/json     Content-Type=application/json
160     ${resp}=        POST On Session      mr_sim_session    url=${url}    json=${data}     headers=${headers}
161     [Return]        ${resp}
162
163 GetSubsCall
164     [Arguments]     ${url}
165     Create Session  pmsh_session      ${PMSH_BASE_URL}    verify=false
166     ${resp}=        GET On Session    pmsh_session        url=${url}
167     [Return]        ${resp}
168
169 PostSubscriptionCall
170     [Arguments]     ${url}     ${data}
171     Create Session  pmsh_sub_session       ${PMSH_BASE_URL}    verify=false
172     ${headers}=     Create Dictionary    Accept=application/json     Content-Type=application/json
173     ${resp}=        POST On Session      pmsh_sub_session    url=${url}    json=${data}     headers=${headers}  expected_status=anything
174     [Return]        ${resp}