a26ca11d58c522fc4f7758a8263e5f88b01011df
[osm/tests.git] / robot-systest / testsuite / sa_07-alarms_from_sa-related_vnfs.robot
1 *** Comments ***
2 #   Licensed under the Apache License, Version 2.0 (the "License");
3 #   you may not use this file except in compliance with the License.
4 #   You may obtain a copy of the License at
5 #
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
8 #   Unless required by applicable law or agreed to in writing, software
9 #   distributed under the License is distributed on an "AS IS" BASIS,
10 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 #   See the License for the specific language governing permissions and
12 #   limitations under the License.
13
14
15 *** Settings ***
16 Documentation   [SA-07] Events or alarms coming from SA-related VNFs in the NS.
17
18 Library   OperatingSystem
19 Library   String
20 Library   Collections
21 Library   SSHLibrary
22
23 Resource   ../lib/vnfd_lib.resource
24 Resource   ../lib/nsd_lib.resource
25 Resource   ../lib/ns_lib.resource
26 Resource   ../lib/ssh_lib.resource
27 Resource   ../lib/prometheus_lib.resource
28
29 Test Tags   sa_07   cluster_sa   daily   regression
30
31 Suite Setup   Run Keyword And Ignore Error   Suite Preparation
32 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
33
34
35 *** Variables ***
36 # NS instantiation parameters
37 ${NS_CONFIG}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
38
39 # NS and VNF descriptor package folder and ids
40 ${VNFD_PKG}   cirros_alarm_vnf
41 ${VNFD_NAME}   cirros_alarm-vnf
42 ${VNFD_FILE}   cirros_alarm_vnfd.yaml
43 ${NEW_VNFD_PKG}   new_cirros_alarm_vnf
44 ${NSD_PKG}   cirros_alarm_ns
45 ${NSD_NAME}   cirros_alarm-ns
46
47 # NS instance name and id
48 ${NS_ID}   ${EMPTY}
49 ${NS_NAME}   sa_07-alarm_test
50
51 # Webhook NS and VNF descriptor package folder and ids
52 ${WS_VNFD_PKG}   hackfest_basic_vnf
53 ${WS_NSD_PKG}   hackfest_basic_ns
54 ${WS_VNFD_NAME}   hackfest_basic-vnf
55 ${WS_NSD_NAME}   hackfest_basic-ns
56
57 # Webhook NS instance name and id
58 ${WS_NS_ID}   ${EMPTY}
59 ${WS_NS_NAME}   sa_07-webhook_service_test
60
61 # Webhook NS Variables
62 ${WS_VNF_MEMBER_INDEX}   vnf
63 ${WS_VNF_IP_ADDR}   ${EMPTY}
64 ${WS_LOG_FILE}   webhook.log
65 ${WS_PORT}   5212
66 ${WS_ALARM_MSG}   notify_alarm
67
68 # SSH keys and username to be used
69 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
70 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
71 ${USERNAME}   ubuntu
72 ${PASSWORD}   ${EMPTY}
73
74 # Prometheus polling interval and retries
75 ${PROMETHEUS_POLL_RETRIES}   15 times
76 ${PROMETHEUS_POLL_TIMEOUT}   1 minute
77
78 # Prometheus metrics to retrieve
79 ${METRIC_NAME}   osm_cpu_utilization
80
81 ${SUCCESS_RETURN_CODE}   0
82
83
84 *** Test Cases ***
85 Create Webhook Service VNF Descriptor
86     [Documentation]   Upload VNF package with a webhook service for the testsuite.
87     Create VNFD   '%{PACKAGES_FOLDER}/${WS_VNFD_PKG}'
88
89 Create Webhook Service NS Descriptor
90     [Documentation]   Upload NS package with a webhook service for the testsuite.
91     Create NSD   '%{PACKAGES_FOLDER}/${WS_NSD_PKG}'
92
93 Instantiate Webhook Service Network Service
94     [Documentation]   Instantiate NS with the webhook for the testsuite.
95     ${id}=   Create Network Service   ${WS_NSD_NAME}   %{VIM_TARGET}   ${WS_NS_NAME}   ${NS_CONFIG}   ${PUBLICKEY}
96     Set Suite Variable   ${WS_NS_ID}   ${id}
97
98 Get Webhook Service VNF IP Address
99     [Documentation]   Get the mgmt IP address of the VNF offering the webhook service.
100     ${ip_addr}=   Get Vnf Management Ip Address   ${WS_NS_ID}   ${WS_VNF_MEMBER_INDEX}
101     Log   ${ip_addr}
102     Set Suite Variable   ${WS_VNF_IP_ADDR}   ${ip_addr}
103
104 Start Webhook Service
105     [Documentation]   Launch simple command in webhook VNF to listen to notifications.
106     Variable Should Exist   ${PRIVATEKEY}   msg=SSH private key not available
107     Sleep   40 seconds   Wait for SSH daemon to be up
108     ${stdout}=   Execute Remote Command Check Rc Return Output   ${WS_VNF_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   while true; do { echo -e 'HTTP/1.0 200 OK\r\nContent-Length: 0\r\n\r\n'; test; } | nc -l '${WS_PORT}'; done > '${WS_LOG_FILE}' 2>&1 &
109     Log   ${stdout}
110
111 Create VNF Descriptor
112     [Documentation]   Upload VNF package for the testsuite.
113     ${rc}   ${stdout}=   Run And Return RC And Output   mkdir '%{PACKAGES_FOLDER}/${NEW_VNFD_PKG}' && WEBHOOK_URL="http://${WS_VNF_IP_ADDR}:${WS_PORT}" envsubst < '%{PACKAGES_FOLDER}/${VNFD_PKG}'/'${VNFD_FILE}' > '%{PACKAGES_FOLDER}/${NEW_VNFD_PKG}'/'${VNFD_FILE}'
114     Log   ${stdout}
115     Should Be Equal As Integers   ${rc}   ${SUCCESS_RETURN_CODE}
116     Create VNFD   '%{PACKAGES_FOLDER}/${NEW_VNFD_PKG}'
117
118 Create NS Descriptor
119     [Documentation]   Upload NS package for the testsuite.
120     Create NSD   '%{PACKAGES_FOLDER}/${NSD_PKG}'
121
122 Instantiate Network Service
123     [Documentation]   Instantiate the main NS for the testsuite.
124     ${id}=   Create Network Service   ${NSD_NAME}   %{VIM_TARGET}   ${NS_NAME}   ${NS_CONFIG}   ${PUBLICKEY}
125     Set Suite Variable   ${NS_ID}   ${id}
126
127 Get Alarm Metric
128     [Documentation]   Check that the expected metric is present in Prometheus (pushed from SA modules).
129     Variable Should Exist   ${PROMETHEUS_POLL_RETRIES}   msg=Metric polling retries is not available
130     Variable Should Exist   ${PROMETHEUS_POLL_TIMEOUT}   msg=Metric polling timeout is not available
131     Variable Should Exist   ${PROMETHEUS_HOST}   msg=Prometheus address is not available
132     Variable Should Exist   ${PROMETHEUS_PORT}   msg=Prometheus port is not available
133     Variable Should Exist   ${METRIC_NAME}   msg=Prometheus metric name is not available
134     ${metric_filter}=   Set Variable   ns_id=${NS_ID}
135     ${metric_value}=   Wait Until Keyword Succeeds   ${PROMETHEUS_POLL_RETRIES}   ${PROMETHEUS_POLL_TIMEOUT}   Get Metric   ${PROMETHEUS_HOST}   ${PROMETHEUS_PORT}   ${PROMETHEUS_USER}   ${PROMETHEUS_PASSWORD}   ${METRIC_NAME}   ${metric_filter}
136     IF   ${metric_value} <= 0   Fail   msg=The metric '${METRIC_NAME}' value is '${metric_value}'
137
138 Check Alarms Were Received
139     [Documentation]   Check in the webhook VNF that the notification is received.
140     Wait Until Keyword Succeeds   6 times   40 seconds   Execute Remote Command Check Rc Return Output   ${WS_VNF_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   cat '${WS_LOG_FILE}' | grep '${WS_ALARM_MSG}' | grep '${NS_NAME}'
141
142 Delete NS Instance
143     [Documentation]   Delete main NS instance.
144     [Tags]   cleanup
145     Delete NS   ${NS_NAME}
146
147 Delete NS Descriptor
148     [Documentation]   Delete main NS package.
149     [Tags]   cleanup
150     Delete NSD   ${NSD_NAME}
151
152 Delete VNF Descriptor
153     [Documentation]   Delete main VNF package.
154     [Tags]   cleanup
155     Delete VNFD   ${VNFD_NAME}
156
157 Delete Webhook Service NS Instance
158     [Documentation]   Delete NS instance for the webhook.
159     [Tags]   cleanup
160     Delete NS   ${WS_NS_NAME}
161
162 Delete Webhook Service NS Descriptor
163     [Documentation]   Delete NS package for the webhook.
164     [Tags]   cleanup
165     Delete NSD   ${WS_NSD_NAME}
166
167 Delete Webhook Service VNF Descriptor
168     [Documentation]   Delete VNF package for the webhook.
169     [Tags]   cleanup
170     Delete VNFD   ${WS_VNFD_NAME}
171
172
173 *** Keywords ***
174 Suite Preparation
175     [Documentation]   Test Suite Preparation: Setting Prometheus Testsuite Variables
176     Set Testsuite Prometheus Variables
177
178 Suite Cleanup
179     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
180     Run Keyword If Any Tests Failed   Delete NS   ${NS_NAME}
181     Run Keyword If Any Tests Failed   Delete NSD   ${NSD_NAME}
182     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_NAME}
183     Run Keyword If Any Tests Failed   Delete NS   ${WS_NS_NAME}
184     Run Keyword If Any Tests Failed   Delete NSD   ${WS_NSD_NAME}
185     Run Keyword If Any Tests Failed   Delete VNFD   ${WS_VNFD_NAME}
186     Delete Temporary Descriptor Folder   '%{PACKAGES_FOLDER}/${NEW_VNFD_PKG}'
187
188 Delete Temporary Descriptor Folder
189     [Documentation]   Removes the temporary package folder created for the test
190     [Arguments]   ${folder_name}
191     ${rc}   ${stdout}=   Run And Return RC And Output   rm -rf '${folder_name}'
192     Log   ${rc},${stdout}