a2b8cad65c439483b69bb3d385ce446dddda08bf
[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 ${SUBSCRIPTIONS_ENDPOINT}           /subscriptions
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 ${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"
30
31 *** Test Cases ***
32
33 Verify Administrative State in PMSH log file is LOCKED
34     [Tags]                          PMSH_01
35     [Documentation]                 Verify Administrative State as logged in PMSH log file is LOCKED
36     [Timeout]                       10 seconds
37     Sleep                           3       Allow time for PMSH to flush to logs
38     ${cli_cmd_output}=              Run Process     ${CLI_EXEC_GET_CBS_CONFIG_FIRST}         shell=yes
39     Should Be True                  ${cli_cmd_output.rc} == 0
40     Should Contain                  ${cli_cmd_output.stdout}       ${ADMIN_STATE_LOCKED_PATTERN}
41
42 Verify database tables exist and are empty
43     [Tags]                          PMSH_02
44     [Documentation]                 Verify database has been created and is empty
45     [Timeout]                       10 seconds
46     ${resp}=                        Get Request                      pmsh_session  ${SUBSCRIPTIONS_ENDPOINT}
47     Should Be True                  ${resp.status_code} == 200
48     Should Contain                  ${resp.text}                     []
49
50 Verify PNF detected in AAI when administrative state unlocked
51     [Tags]                          PMSH_03
52     [Documentation]                 Verify PNF detected when administrative state unlocked
53     [Timeout]                       40 seconds
54     SetAdministrativeStateToUnlocked
55     Sleep                           31      Allow PMSH time to pick up changes in CBS config
56     ${resp}=                        Get Request                      pmsh_session  ${SUBSCRIPTIONS_ENDPOINT}
57     Should Be Equal As Strings      ${resp.json()[0]['subscription_status']}                            UNLOCKED
58     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][0]['nf_name']}                pnf-existing
59     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][0]['orchestration_status']}   Active
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]                       40 seconds
66     SimulatePolicyResponse          ${MR_EXPECTATION_POLICY_RESPONSE_PNF_EXISTING}
67     Sleep                           15 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]                       30 seconds
75     SimulateNewPNF
76     Sleep                           15 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]['orchestration_status']}   Active
80     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][1]['nf_sub_status']}          PENDING_CREATE
81
82 Verify AAI event on MR detailing PNF being deleted is handled
83     [Tags]                          PMSH_06
84     [Documentation]                 Verify PNF deleted AAI event on MR is handled
85     [Timeout]                       30 seconds
86     SimulateDeletedPNF
87     Sleep                           12 seconds      Ensure AAI event on MR is picked up
88     ${resp}=                        Get Request                      pmsh_session  ${SUBSCRIPTIONS_ENDPOINT}
89     Should Not Contain              ${resp.text}            pnf_newly_discovered
90
91 *** Keywords ***
92
93 CreateSessions
94     Create Session  pmsh_session  ${PMSH_BASE_URL}
95     Create Session  mr_sim_session  ${MR_BASE_URL}
96     Create Session  cbs_sim_session  ${CBS_BASE_URL}
97
98 SetAdministrativeStateToUnlocked
99     ${data}=            Get Data From File      ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}
100     ${resp} =           Put Request             cbs_sim_session  /clear  data={"path": "/service_component_all/.*"}
101     Should Be True      ${resp.status_code} == 200
102     Sleep               2                       Allow CBS time to set expectation
103     ${resp} =           Put Request             cbs_sim_session  /expectation     data=${data}
104     Should Be True      ${resp.status_code} == 201
105
106 SimulateNewPNF
107     ${data}=        Get Data From File    ${MR_EXPECTATION_AAI_PNF_CREATED}
108     ${resp} =       Put Request     mr_sim_session  /clear  data={"path": "/events/AAI_EVENT/dcae_pmsh_cg/dcae_pmsh_aai_event"}
109     Should Be True      ${resp.status_code} == 200
110     ${resp} =       Put Request     mr_sim_session  /expectation     data=${data}
111     Should Be True      ${resp.status_code} == 201
112
113 SimulatePolicyResponse
114     [Arguments]                     ${expected_contents}
115     ${data}=        Get Data From File    ${expected_contents}
116     ${resp} =       Put Request     mr_sim_session  /clear  data={"path": "/events/unauthenticated.PMSH_CL_INPUT/dcae_pmsh_cg/dcae_pmsh_policy_cl_input"}
117     Should Be True      ${resp.status_code} == 200
118     ${resp} =       Put Request     mr_sim_session  /expectation     data=${data}
119     Should Be True      ${resp.status_code} == 201
120
121 SimulateDeletedPNF
122     ${data}=        Get Data From File    ${MR_EXPECTATION_AAI_PNF_REMOVED}
123     ${resp} =       Put Request     mr_sim_session  /clear  data={"path": "/events/AAI_EVENT/dcae_pmsh_cg/dcae_pmsh_aai_event"}
124     Should Be True      ${resp.status_code} == 200
125     ${resp} =       Put Request     mr_sim_session  /expectation     data=${data}
126     Should Be True      ${resp.status_code} == 201