ebdae844e91463a6b9950f7315c7270f04b55d41
[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}                      https://${MR_SIM_IP_ADDRESS}:3095
19 ${CBS_BASE_URL}                     https://${CBS_SIM_IP_ADDRESS}:10443
20 ${HEALTHCHECK_ENDPOINT}             /healthcheck
21
22 ${MR_EXPECTATION_AAI_PNF_CREATED}               %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/mr-expectation-aai-pnf-created.json
23 ${MR_EXPECTATION_AAI_PNF_REMOVED}               %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/mr-expectation-aai-pnf-deleted.json
24 ${MR_EXPECTATION_POLICY_RESPONSE_PNF_NEW}       %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/mr-expectation-policy-subscription-created-pnf-new.json
25 ${MR_EXPECTATION_POLICY_RESPONSE_PNF_EXISTING}  %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/mr-expectation-policy-subscription-created-pnf-existing.json
26 ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}         %{WORKSPACE}/tests/dcaegen2-services-pmsh/testcases/assets/cbs-expectation-unlocked-config.json
27
28 ${ADMIN_STATE_LOCKED_PATTERN}       'administrativeState': 'LOCKED'
29 ${ADMIN_STATE_UNLOCKED_PATTERN}     'administrativeState': 'UNLOCKED'
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/debug.log"
31 ${CLI_EXEC_GET_CBS_CONFIG_LAST}     docker exec pmsh /bin/sh -c "grep 'PMSH config from CBS' /var/log/ONAP/dcaegen2/services/pmsh/debug.log | tail -1"
32
33 ${DB_CMD_NETWORK_FUNCTIONS_COUNT}   docker exec db bash -c "psql -U pmsh -d pmsh -A -t -c 'select count(*) from network_functions;'"
34 ${DB_CMD_NF_TO_SUB_REL_COUNT}       docker exec db bash -c "psql -U pmsh -d pmsh -A -t -c 'select count(*) from nf_to_sub_rel;'"
35 ${DB_CMD_SUBSCRIPTIONS_COUNT}       docker exec db bash -c "psql -U pmsh -d pmsh -A -t -c 'select count(*) from subscriptions;'"
36
37 ${CLI_GET_NETWORK_FUNCTIONS_DB_TABLE}   docker exec db bash -c "psql -U pmsh -d pmsh -A -t -c 'select nf_name, orchestration_status from network_functions;'"
38 ${CLI_GET_NF_TO_SUB_REL_DB_TABLE}       docker exec db bash -c "psql -U pmsh -d pmsh -A -t -c 'select subscription_name, nf_name, nf_sub_status from nf_to_sub_rel;'"
39 ${CLI_GET_SUBSCRIPTIONS_DB_TABLE}       docker exec db bash -c "psql -U pmsh -d pmsh -A -t -c 'select subscription_name, status from subscriptions;'"
40
41
42 *** Test Cases ***
43
44 Verify PMSH health check returns 200 and has a status of healthy
45     [Tags]                          PMSH_01
46     [Documentation]                 Verify the PMSH health check api call functions correctly
47     [Timeout]                       10 seconds
48     ${resp}=                        Get Request                      pmsh_session  ${HEALTHCHECK_ENDPOINT}
49     Should Be True                  ${resp.status_code} == 200
50     Should Match Regexp             ${resp.text}             healthy
51
52 Verify Administrative State in PMSH log file is LOCKED
53     [Tags]                          PMSH_02
54     [Documentation]                 Verify Administrative State as logged in PMSH log file is LOCKED
55     [Timeout]                       10 seconds
56     Sleep                           3       Allow time for PMSH to flush to logs
57     ${cli_cmd_output}=              Run Process     ${CLI_EXEC_GET_CBS_CONFIG_FIRST}         shell=yes
58     Should Be True                  ${cli_cmd_output.rc} == 0
59     Should Contain                  ${cli_cmd_output.stdout}       ${ADMIN_STATE_LOCKED_PATTERN}
60
61 Verify database tables exist and are empty
62     [Tags]                          PMSH_03
63     [Documentation]                 Verify database has been created and is empty
64     [Timeout]                       10 seconds
65     VerifyDatabaseEmpty
66
67 Verify PNF detected in AAI when administrative state unlocked
68     [Tags]                          PMSH_04
69     [Documentation]                 Verify PNF detected when administrative state unlocked
70     [Timeout]                       40 seconds
71     SetAdministrativeStateToUnlocked
72     Sleep                           31      Allow PMSH time to pick up changes in CBS config
73     VerifyCommandOutputContains     ${CLI_EXEC_GET_CBS_CONFIG_LAST}     ${ADMIN_STATE_UNLOCKED_PATTERN}
74     VerifyCommandOutputIs           ${cli_get_subscriptions_db_table}       ExtraPM-All-gNB-R2B|UNLOCKED
75     VerifyCommandOutputIs           ${cli_get_network_functions_db_table}   pnf-existing|Active
76     VerifyCommandOutputIs           ${cli_get_nf_to_sub_rel_db_table}       ExtraPM-All-gNB-R2B|pnf-existing|PENDING_CREATE
77
78 Verify Policy response on MR is handled
79     [Tags]                          PMSH_05
80     [Documentation]                 Verify policy response on MR is handled
81     [Timeout]                       40 seconds
82     SimulatePolicyResponse          ${MR_EXPECTATION_POLICY_RESPONSE_PNF_EXISTING}
83     Sleep                           7 seconds      Ensure Policy response on MR is picked up
84     VerifyCommandOutputIs           ${cli_get_nf_to_sub_rel_db_table}       ExtraPM-All-gNB-R2B|pnf-existing|CREATED
85
86 Verify AAI event on MR detailing new PNF being detected is handled
87     [Tags]                          PMSH_06
88     [Documentation]                 Verify PNF created AAI event on MR is handled
89     [Timeout]                       30 seconds
90     SimulateNewPNF
91     Sleep                           12 seconds      Ensure AAI event on MR is picked up
92     VerifyCommandOutputIs           ${CLI_GET_SUBSCRIPTIONS_DB_TABLE}       ExtraPM-All-gNB-R2B|UNLOCKED
93     VerifyCommandOutputIs           ${CLI_GET_NETWORK_FUNCTIONS_DB_TABLE}   pnf-existing|Active\npnf_newly_discovered|Active
94     VerifyCommandOutputIs           ${CLI_GET_NF_TO_SUB_REL_DB_TABLE}       ExtraPM-All-gNB-R2B|pnf-existing|CREATED\nExtraPM-All-gNB-R2B|pnf_newly_discovered|PENDING_CREATE
95
96 Verify AAI event on MR detailing PNF being deleted is handled
97     [Tags]                          PMSH_07
98     [Documentation]                 Verify PNF deleted AAI event on MR is handled
99     [Timeout]                       30 seconds
100     SimulateDeletedPNF
101     Sleep                           12 seconds      Ensure AAI event on MR is picked up
102     VerifyNumberOfRecordsInDbTable       ${DB_CMD_NETWORK_FUNCTIONS_COUNT}   1
103     VerifyNumberOfRecordsInDbTable       ${DB_CMD_NF_TO_SUB_REL_COUNT}       1
104
105 *** Keywords ***
106
107 CreateSessions
108     Create Session  pmsh_session  ${PMSH_BASE_URL}
109     Create Session  mr_sim_session  ${MR_BASE_URL}
110     Create Session  cbs_sim_session  ${CBS_BASE_URL}
111
112 SetAdministrativeStateToUnlocked
113     ${data}=            Get Data From File      ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}
114     ${resp} =           Put Request             cbs_sim_session  /clear  data={"path": "/service_component_all/.*"}
115     Should Be True      ${resp.status_code} == 200
116     Sleep               2                       Allow CBS time to set expectation
117     ${resp} =           Put Request             cbs_sim_session  /expectation     data=${data}
118     Should Be True      ${resp.status_code} == 201
119
120 VerifyCommandOutputContains
121     [Arguments]                     ${cli_command}                  ${string_to_check_for}
122     ${cli_cmd_output}=              Run Process                     ${cli_command}         shell=yes
123     Should Be True                  ${cli_cmd_output.rc} == 0
124     Should Contain                  ${cli_cmd_output.stdout}        ${string_to_check_for}
125
126 VerifyCommandOutputIs
127     [Arguments]                     ${cli_cmd}          ${expected_contents}
128     ${cli_cmd_output}=              Run Process         ${cli_cmd}         shell=yes
129     Log             ${cli_cmd_output.stdout}
130     Should Be True                  ${cli_cmd_output.rc} == 0
131     Should Be Equal As Strings      ${cli_cmd_output.stdout}        ${expected_contents}
132
133 SimulateNewPNF
134     ${data}=        Get Data From File    ${MR_EXPECTATION_AAI_PNF_CREATED}
135     ${resp} =       Put Request     mr_sim_session  /clear  data={"path": "/events/AAI_EVENT/dcae_pmsh_cg/AAI-EVENT"}
136     Should Be True      ${resp.status_code} == 200
137     ${resp} =       Put Request     mr_sim_session  /expectation     data=${data}
138     Should Be True      ${resp.status_code} == 201
139
140 SimulatePolicyResponse
141     [Arguments]                     ${expected_contents}
142     ${data}=        Get Data From File    ${expected_contents}
143     ${resp} =       Put Request     mr_sim_session  /clear  data={"path": "/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS/dcae_pmsh_cg/policy_response_consumer"}
144     Should Be True      ${resp.status_code} == 200
145     ${resp} =       Put Request     mr_sim_session  /expectation     data=${data}
146     Should Be True      ${resp.status_code} == 201
147
148 SimulateDeletedPNF
149     ${data}=        Get Data From File    ${MR_EXPECTATION_AAI_PNF_REMOVED}
150     ${resp} =       Put Request     mr_sim_session  /clear  data={"path": "/events/AAI_EVENT/dcae_pmsh_cg/AAI-EVENT"}
151     Should Be True      ${resp.status_code} == 200
152     ${resp} =       Put Request     mr_sim_session  /expectation     data=${data}
153     Should Be True      ${resp.status_code} == 201
154
155 VerifyNumberOfRecordsInDbTable
156     [Arguments]         ${db_query}          ${expected_count}
157     ${db_count}         Run Process     ${db_query}         shell=yes
158     Should Be True      ${db_count.stdout} == ${expected_count}
159
160 VerifyDatabaseEmpty
161    VerifyNumberOfRecordsInDbTable       ${DB_CMD_NETWORK_FUNCTIONS_COUNT}   0
162    VerifyNumberOfRecordsInDbTable       ${DB_CMD_NF_TO_SUB_REL_COUNT}       0
163    VerifyNumberOfRecordsInDbTable       ${DB_CMD_SUBSCRIPTIONS_COUNT}       0