4b0dc6e4a3ca9a3a51c94c77ef00dfc7191bc225
[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
11 Test Setup        CreateSessions
12 Test Teardown     Delete All Sessions
13
14
15 *** Variables ***
16
17 ${PMSH_BASE_URL}                    https://${PMSH_IP}:8443
18 ${MR_BASE_URL}                      http://${MR_IP_ADDRESS}:3904
19 ${CBS_BASE_URL}                     https://${CBS_SIM_IP_ADDRESS}:10443
20 ${SUBSCRIPTIONS_ENDPOINT}           /subscriptions
21 ${POLICY_PUBLISH_MR_TOPIC}          /events/unauthenticated.PMSH_CL_INPUT
22 ${AAI_MR_TOPIC}                     /events/AAI_EVENT
23
24 ${MR_AAI_PNF_CREATED}                       %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/aai-pnf-create.json
25 ${MR_AAI_PNF_REMOVED}                       %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/aai-pnf-delete.json
26 ${MR_POLICY_RESPONSE_PNF_EXISTING}          %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/policy-sub-created-pnf-existing.json
27 ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}     %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/cbs-expectation-unlocked-config.json
28
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 Administrative State in PMSH log file is LOCKED
35     [Tags]                          PMSH_01
36     [Documentation]                 Verify Administrative State as logged in PMSH log file is LOCKED
37     [Timeout]                       10 seconds
38     Sleep                           3       Allow time for PMSH to flush to logs
39     ${cli_cmd_output}=              Run Process     ${CLI_EXEC_GET_CBS_CONFIG_FIRST}         shell=yes
40     Should Be True                  ${cli_cmd_output.rc} == 0
41     Should Contain                  ${cli_cmd_output.stdout}       ${ADMIN_STATE_LOCKED_PATTERN}
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}=                        Get Request     pmsh_session    ${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}=                        Get Request     pmsh_session    ${SUBSCRIPTIONS_ENDPOINT}
58     Should Be Equal As Strings      ${resp.json()[0]['subscription_status']}                        UNLOCKED
59     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][0]['nf_name']}            pnf-existing
60     Should Be Equal As Strings      ${resp.json()[0]['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}=                        Get Request     pmsh_session    ${SUBSCRIPTIONS_ENDPOINT}
69     Should Be Equal As Strings      ${resp.json()[0]['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}=                        Get Request     pmsh_session    ${SUBSCRIPTIONS_ENDPOINT}
78     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][1]['nf_name']}            pnf_newly_discovered
79     Should Be Equal As Strings      ${resp.json()[0]['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}=                        Get Request     pmsh_session    ${SUBSCRIPTIONS_ENDPOINT}
88     Should Not Contain              ${resp.text}    pnf_newly_discovered
89
90 *** Keywords ***
91
92 CreateSessions
93     Create Session  pmsh_session     ${PMSH_BASE_URL}
94     Create Session  mr_sim_session   ${MR_BASE_URL}
95     Create Session  cbs_sim_session  ${CBS_BASE_URL}
96
97 SetAdministrativeStateToUnlocked
98     ${data}=            Get Data From File      ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}
99     ${resp} =           Put Request             cbs_sim_session  /clear  data={"path": "/service_component_all/.*"}
100     Should Be True      ${resp.status_code} == 200
101     Sleep               2                       Allow CBS time to set expectation
102     ${resp} =           Put Request             cbs_sim_session  /expectation     data=${data}
103     Should Be True      ${resp.status_code} == 201
104
105
106 SimulatePolicyResponse
107     [Arguments]                     ${expected_contents}
108     ${json_value}=                  json_from_file                  ${expected_contents}
109     ${resp}=                                            PostCall                                        ${POLICY_PUBLISH_MR_TOPIC}     ${json_value}
110     log                                                 ${resp.text}
111     Should Be Equal As Strings          ${resp.status_code}             200
112     ${count}=                           Evaluate                                        $resp.json().get('count')
113     log                                                         'JSON Response Code:'${resp}
114
115 SimulateNewPNF
116     [Arguments]                     ${expected_contents}
117     ${json_value}=                  json_from_file                  ${expected_contents}
118     ${resp}=                                            PostCall                                        ${AAI_MR_TOPIC}      ${json_value}
119     log                                                 ${resp.text}
120     Should Be Equal As Strings          ${resp.status_code}             200
121     ${count}=                           Evaluate                                        $resp.json().get('count')
122     log                                                         'JSON Response Code:'${resp}
123
124 SimulateDeletedPNF
125     [Arguments]                     ${expected_contents}
126     ${json_value}=                  json_from_file                  ${expected_contents}
127     ${resp}=                                            PostCall                                        ${AAI_MR_TOPIC}      ${json_value}
128     log                                                 ${resp.text}
129     Should Be Equal As Strings          ${resp.status_code}             200
130     ${count}=                           Evaluate                                        $resp.json().get('count')
131     log                                                         'JSON Response Code:'${resp}
132
133 PostCall
134     [Arguments]     ${url}     ${data}
135     ${headers}=    Create Dictionary    Accept=application/json     Content-Type=application/json
136     ${resp}=       Post Request         mr_sim_session     ${url}     json=${data}     headers=${headers}
137     [Return]       ${resp}