d79a76251a8f6c253e8c7cf50f6a5316a46b0ce0
[osm/tests.git] / robot-systest / testsuite / sa_07-alarms_from_sa-related_vnfs.robot
1 #   Licensed under the Apache License, Version 2.0 (the "License");
2 #   you may not use this file except in compliance with the License.
3 #   You may obtain a copy of the License at
4 #
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #   Unless required by applicable law or agreed to in writing, software
8 #   distributed under the License is distributed on an "AS IS" BASIS,
9 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 #   See the License for the specific language governing permissions and
11 #   limitations under the License.
12
13 *** Settings ***
14 Documentation   [SA-07] Events or alarms coming from SA-related VNFs in the NS.
15
16 Library   OperatingSystem
17 Library   String
18 Library   Collections
19 Library   SSHLibrary
20
21 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/vnfd_lib.robot
22 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/nsd_lib.robot
23 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/ns_lib.robot
24 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/ssh_lib.robot
25 Resource   %{ROBOT_DEVOPS_FOLDER}/lib/prometheus_lib.robot
26
27 Force Tags   sa_07   cluster_sa   daily   regression
28
29 Suite Setup   Run Keyword And Ignore Error   Suite Preparation
30 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
31
32
33 *** Variables ***
34 # NS instantiation parameters
35 ${ns_config}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
36
37 # NS and VNF descriptor package folder and ids
38 ${vnfd_pkg}   cirros_alarm_vnf
39 ${vnfd_name}   cirros_alarm-vnf
40 ${vnfd_file}   cirros_alarm_vnfd.yaml
41 ${new_vnfd_pkg}   new_cirros_alarm_vnf
42 ${nsd_pkg}   cirros_alarm_ns
43 ${nsd_name}   cirros_alarm-ns
44
45 # NS instance name and id
46 ${ns_id}   ${EMPTY}
47 ${ns_name}   sa_07-alarm_test
48
49 # Webhook NS and VNF descriptor package folder and ids
50 ${ws_vnfd_pkg}   hackfest_basic_vnf
51 ${ws_nsd_pkg}   hackfest_basic_ns
52 ${ws_vnfd_name}   hackfest_basic-vnf
53 ${ws_nsd_name}   hackfest_basic-ns
54
55 # Webhook NS instance name and id
56 ${ws_ns_id}   ${EMPTY}
57 ${ws_ns_name}   sa_07-webhook_service_test
58
59 # Webhook NS Variables
60 ${ws_vnf_member_index}   vnf
61 ${ws_vnf_ip_addr}   ${EMPTY}
62 ${ws_log_file}   webhook.log
63 ${ws_port}   5212
64 ${ws_alarm_msg}   notify_alarm
65
66 # SSH keys and username to be used
67 ${publickey}   %{HOME}/.ssh/id_rsa.pub
68 ${privatekey}   %{HOME}/.ssh/id_rsa
69 ${username}   ubuntu
70 ${password}   ${EMPTY}
71
72 # Prometheus polling interval and retries
73 ${prometheus_poll_retries}   15 times
74 ${prometheus_poll_timeout}   1 minute
75
76 # Prometheus metrics to retrieve
77 ${metric_name}   osm_cpu_utilization
78
79 ${success_return_code}   0
80
81
82 *** Test Cases ***
83 Create Webhook Service VNF Descriptor
84
85     Create VNFD   '%{PACKAGES_FOLDER}/${ws_vnfd_pkg}'
86
87
88 Create Webhook Service NS Descriptor
89
90     Create NSD   '%{PACKAGES_FOLDER}/${ws_nsd_pkg}'
91
92
93 Instantiate Webhook Service Network Service
94
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
99 Get Webhook Service VNF IP Address
100
101     ${ip_addr}=   Get Vnf Management Ip Address   ${ws_ns_id}   ${ws_vnf_member_index}
102     Log   ${ip_addr}
103     Set Suite Variable   ${ws_vnf_ip_addr}   ${ip_addr}
104
105
106 Start Webhook Service
107
108     Variable Should Exist   ${privatekey}   msg=SSH private key not available
109     Sleep   40 seconds   Wait for SSH daemon to be up
110     ${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
112
113 Create VNF Descriptor
114
115     ${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}'
116     Log   ${stdout}
117     Should Be Equal As Integers   ${rc}   ${success_return_code}
118     Create VNFD   '%{PACKAGES_FOLDER}/${new_vnfd_pkg}'
119
120
121 Create NS Descriptor
122
123     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
124
125
126 Instantiate Network Service
127
128     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}
129     Set Suite Variable   ${ns_id}   ${id}
130
131
132 Get Alarm Metric
133
134     Variable Should Exist   ${prometheus_poll_retries}   msg=Metric polling retries is not available
135     Variable Should Exist   ${prometheus_poll_timeout}   msg=Metric polling timeout is not available
136     Variable Should Exist   ${prometheus_host}   msg=Prometheus address is not available
137     Variable Should Exist   ${prometheus_port}   msg=Prometheus port is not available
138     Variable Should Exist   ${metric_name}   msg=Prometheus metric name is not available
139     ${metric_filter}=   Set Variable   ns_id=${ns_id}
140     ${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}
141     Run Keyword If   ${metric_value} <= 0   Fail   msg=The metric '${metric_name}' value is '${metric_value}'
142
143
144 Check Alarms Were Received
145
146     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}'
147
148
149 Delete NS Instance
150     [Tags]   cleanup
151
152     Delete NS   ${ns_name}
153
154
155 Delete NS Descriptor
156     [Tags]   cleanup
157
158     Delete NSD   ${nsd_name}
159
160
161 Delete VNF Descriptor
162     [Tags]   cleanup
163
164     Delete VNFD   ${vnfd_name}
165
166
167 Delete Webhook Service NS Instance
168     [Tags]   cleanup
169
170     Delete NS   ${ws_ns_name}
171
172
173 Delete Webhook Service NS Descriptor
174     [Tags]   cleanup
175
176     Delete NSD   ${ws_nsd_name}
177
178
179 Delete Webhook Service VNF Descriptor
180     [Tags]   cleanup
181
182     Delete VNFD   ${ws_vnfd_name}
183
184
185 *** Keywords ***
186 Suite Preparation
187     [Documentation]   Test Suite Preparation: Setting Prometheus Testsuite Variables
188
189     Set Testsuite Prometheus Variables
190
191
192 Suite Cleanup
193     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
194
195     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
196     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
197     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_name}
198     Run Keyword If Any Tests Failed   Delete NS   ${ws_ns_name}
199     Run Keyword If Any Tests Failed   Delete NSD   ${ws_nsd_name}
200     Run Keyword If Any Tests Failed   Delete VNFD   ${ws_vnfd_name}
201     Delete Temporary Descriptor Folder   '%{PACKAGES_FOLDER}/${new_vnfd_pkg}'
202
203
204 Delete Temporary Descriptor Folder
205     [Documentation]   Removes the temporary package folder created for the test
206     [Arguments]   ${folder_name}
207     ${rc}   ${stdout}=   Run and Return RC and Output   rm -rf '${folder_name}'
208     Log   ${stdout}
209
210