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
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 Documentation [SA-07] Events or alarms coming from SA-related VNFs in the NS.
18 Library OperatingSystem
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
29 Test Tags sa_07 cluster_sa daily regression
31 Suite Setup Run Keyword And Ignore Error Suite Preparation
32 Suite Teardown Run Keyword And Ignore Error Suite Cleanup
36 # NS instantiation parameters
37 ${NS_CONFIG} {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
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
47 # NS instance name and id
49 ${NS_NAME} sa_07-alarm_test
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
57 # Webhook NS instance name and id
59 ${WS_NS_NAME} sa_07-webhook_service_test
61 # Webhook NS Variables
62 ${WS_VNF_MEMBER_INDEX} vnf
63 ${WS_VNF_IP_ADDR} ${EMPTY}
64 ${WS_LOG_FILE} webhook.log
66 ${WS_ALARM_MSG} notify_alarm
68 # SSH keys and username to be used
69 ${PUBLICKEY} %{HOME}/.ssh/id_rsa.pub
70 ${PRIVATEKEY} %{HOME}/.ssh/id_rsa
74 # Prometheus polling interval and retries
75 ${PROMETHEUS_POLL_RETRIES} 15 times
76 ${PROMETHEUS_POLL_TIMEOUT} 1 minute
78 # Prometheus metrics to retrieve
79 ${METRIC_NAME} osm_cpu_utilization
81 ${SUCCESS_RETURN_CODE} 0
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}'
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}'
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}
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}
102 Set Suite Variable ${WS_VNF_IP_ADDR} ${ip_addr}
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 &
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}'
115 Should Be Equal As Integers ${rc} ${SUCCESS_RETURN_CODE}
116 Create VNFD '%{PACKAGES_FOLDER}/${NEW_VNFD_PKG}'
119 [Documentation] Upload NS package for the testsuite.
120 Create NSD '%{PACKAGES_FOLDER}/${NSD_PKG}'
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}
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}'
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}'
143 [Documentation] Delete main NS instance.
148 [Documentation] Delete main NS package.
150 Delete NSD ${NSD_NAME}
152 Delete VNF Descriptor
153 [Documentation] Delete main VNF package.
155 Delete VNFD ${VNFD_NAME}
157 Delete Webhook Service NS Instance
158 [Documentation] Delete NS instance for the webhook.
160 Delete NS ${WS_NS_NAME}
162 Delete Webhook Service NS Descriptor
163 [Documentation] Delete NS package for the webhook.
165 Delete NSD ${WS_NSD_NAME}
167 Delete Webhook Service VNF Descriptor
168 [Documentation] Delete VNF package for the webhook.
170 Delete VNFD ${WS_VNFD_NAME}
175 [Documentation] Test Suite Preparation: Setting Prometheus Testsuite Variables
176 Set Testsuite Prometheus Variables
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}'
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}'