71452350bac5f332b38b99326ef02563f7b34546
[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 ${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
27 ${ADMIN_STATE_LOCKED_PATTERN}       'administrativeState': 'LOCKED'
28 ${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"
29
30 *** Test Cases ***
31
32 Verify Administrative State in PMSH log file is LOCKED
33     [Tags]                          PMSH_01
34     [Documentation]                 Verify Administrative State as logged in PMSH log file is LOCKED
35     [Timeout]                       10 seconds
36     Sleep                           3       Allow time for PMSH to flush to logs
37     ${cli_cmd_output}=              Run Process     ${CLI_EXEC_GET_CBS_CONFIG_FIRST}         shell=yes
38     Should Be True                  ${cli_cmd_output.rc} == 0
39     Should Contain                  ${cli_cmd_output.stdout}       ${ADMIN_STATE_LOCKED_PATTERN}
40
41 Verify database tables exist and are empty
42     [Tags]                          PMSH_02
43     [Documentation]                 Verify database has been created and is empty
44     [Timeout]                       10 seconds
45     ${resp}=                        GetSubsCall    ${SUBSCRIPTIONS_ENDPOINT}
46     Should Be True                  ${resp.status_code} == 200
47     Should Contain                  ${resp.text}                     []
48
49 Verify PNF detected in AAI when administrative state unlocked
50     [Tags]                          PMSH_03
51     [Documentation]                 Verify PNF detected when administrative state unlocked
52     [Timeout]                       60 seconds
53     SetAdministrativeStateToUnlocked
54     Sleep                           31             Allow PMSH time to pick up changes in CBS config
55     ${resp}=                        GetSubsCall    ${SUBSCRIPTIONS_ENDPOINT}
56     Should Be Equal As Strings      ${resp.json()[0]['subscription_status']}                        UNLOCKED
57     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][0]['nf_name']}            pnf-existing
58     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][0]['nf_sub_status']}      PENDING_CREATE
59
60 Verify Policy response on MR is handled
61     [Tags]                          PMSH_04
62     [Documentation]                 Verify policy response on MR is handled
63     [Timeout]                       60 seconds
64     SimulatePolicyResponse          ${MR_POLICY_RESPONSE_PNF_EXISTING}
65     Sleep                           31 seconds      Ensure Policy response on MR is picked up
66     ${resp}=                        GetSubsCall     ${SUBSCRIPTIONS_ENDPOINT}
67     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][0]['nf_sub_status']}      CREATED
68
69 Verify AAI event on MR detailing new PNF being detected is handled
70     [Tags]                          PMSH_05
71     [Documentation]                 Verify PNF created AAI event on MR is handled
72     [Timeout]                       60 seconds
73     SimulateNewPNF                  ${MR_AAI_PNF_CREATED}
74     Sleep                           31 seconds      Ensure AAI event on MR is picked up
75     ${resp}=                        GetSubsCall     ${SUBSCRIPTIONS_ENDPOINT}
76     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][1]['nf_name']}            pnf_newly_discovered
77     Should Be Equal As Strings      ${resp.json()[0]['network_functions'][1]['nf_sub_status']}      PENDING_CREATE
78
79 Verify AAI event on MR detailing PNF being deleted is handled
80     [Tags]                          PMSH_06
81     [Documentation]                 Verify PNF deleted AAI event on MR is handled
82     [Timeout]                       60 seconds
83     SimulateDeletedPNF              ${MR_AAI_PNF_REMOVED}
84     Sleep                           31 seconds      Ensure AAI event on MR is picked up
85     ${resp}=                        GetSubsCall     ${SUBSCRIPTIONS_ENDPOINT}
86     Should Not Contain              ${resp.text}    pnf_newly_discovered
87
88 *** Keywords ***
89
90 SetAdministrativeStateToUnlocked
91     ${data}=            Get Data From File      ${CBS_EXPECTATION_ADMIN_STATE_UNLOCKED}
92     Create Session      cbs_sim_session   ${CBS_BASE_URL}    verify=false
93     ${resp}=            PUT On Session    cbs_sim_session    url=/clear  data={"path": "/service_component_all/.*"}
94     Should Be True      ${resp.status_code} == 200
95     Sleep               2                 Allow CBS time to set expectation
96     ${resp} =           PUT On Session    cbs_sim_session    url=/expectation     data=${data}
97     Should Be True      ${resp.status_code} == 201
98
99
100 SimulatePolicyResponse
101     [Arguments]                     ${expected_contents}
102     ${json_value}=                  json_from_file                  ${expected_contents}
103     ${resp}=                                            PostMrCall                                  ${POLICY_PUBLISH_MR_TOPIC}     ${json_value}
104     log                                                 ${resp.text}
105     Should Be Equal As Strings          ${resp.status_code}             200
106     ${count}=                           Evaluate                                        $resp.json().get('count')
107     log                                                         'JSON Response Code:'${resp}
108
109 SimulateNewPNF
110     [Arguments]                     ${expected_contents}
111     ${json_value}=                  json_from_file                  ${expected_contents}
112     ${resp}=                                            PostMrCall                                      ${AAI_MR_TOPIC}      ${json_value}
113     log                                                 ${resp.text}
114     Should Be Equal As Strings          ${resp.status_code}             200
115     ${count}=                           Evaluate                                        $resp.json().get('count')
116     log                                                         'JSON Response Code:'${resp}
117
118 SimulateDeletedPNF
119     [Arguments]                     ${expected_contents}
120     ${json_value}=                  json_from_file                  ${expected_contents}
121     ${resp}=                                            PostMrCall                                      ${AAI_MR_TOPIC}      ${json_value}
122     log                                                 ${resp.text}
123     Should Be Equal As Strings          ${resp.status_code}             200
124     ${count}=                           Evaluate                                        $resp.json().get('count')
125     log                                                         'JSON Response Code:'${resp}
126
127 PostMrCall
128     [Arguments]     ${url}     ${data}
129     Create Session  mr_sim_session       ${MR_BASE_URL}    verify=false
130     ${headers}=     Create Dictionary    Accept=application/json     Content-Type=application/json
131     ${resp}=        POST On Session      mr_sim_session    url=${url}    json=${data}     headers=${headers}
132     [Return]        ${resp}
133
134 GetSubsCall
135     [Arguments]     ${url}
136     Create Session  pmsh_session      ${PMSH_BASE_URL}    verify=false
137     ${resp}=        GET On Session    pmsh_session        url=${url}
138     [Return]        ${resp}