bc09c1ccd2103d81e25c1004b5e8f8499d8045ad
[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 Variables   %{ROBOT_DEVOPS_FOLDER}/resources/sa_07-alarms_from_sa-related_vnfs_data.py
28
29 Force Tags   sa_07   cluster_sa   daily   regression
30
31 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
32
33
34 *** Variables ***
35 ${ns_id}   ${EMPTY}
36 ${ws_ns_id}   ${EMPTY}
37 ${username}   ubuntu
38 ${password}   ${EMPTY}
39 ${vnf_member_index}   vnf
40 ${ws_vnf_ip_addr}   ${EMPTY}
41 ${success_return_code}   0
42 ${alarm_msg}   notify_alarm
43 ${ws_log_file}   webhook.log
44 ${ns_config}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
45
46
47 *** Test Cases ***
48 Create Webhook Service VNF Descriptor
49
50     Create VNFD   '%{PACKAGES_FOLDER}/${ws_vnfd_pkg}'
51
52
53 Create Webhook Service NS Descriptor
54
55     Create NSD   '%{PACKAGES_FOLDER}/${ws_nsd_pkg}'
56
57
58 Instantiate Webhook Service Network Service
59
60     ${id}=   Create Network Service   ${ws_nsd_name}   %{VIM_TARGET}   ${ws_ns_name}   ${ns_config}   ${publickey}
61     Set Suite Variable   ${ws_ns_id}   ${id}
62
63
64 Get Webhook Service VNF IP Address
65
66     ${ip_addr}=   Get Vnf Management Ip Address   ${ws_ns_id}   ${vnf_member_index}
67     log   ${ip_addr}
68     Set Suite Variable   ${ws_vnf_ip_addr}   ${ip_addr}
69
70
71 Start Webhook Service
72
73     Variable Should Exist   ${privatekey}   msg=SSH private key not available
74     Sleep   40 seconds   Wait for SSH daemon to be up
75     ${stdout}=   Execute Remote Command Check Rc Return Output   ${ws_vnf_ip_addr}   ${username}   ${password}   ${privatekey}   while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; test; } | nc -l '${ws_port}'; done > '${ws_log_file}' 2>&1 &
76
77
78 Create VNF Descriptor
79
80     ${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}'
81     log   ${stdout}
82     Should Be Equal As Integers   ${rc}   ${success_return_code}
83     Create VNFD   '%{PACKAGES_FOLDER}/${new_vnfd_pkg}'
84
85
86 Create NS Descriptor
87
88     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
89
90
91 Instantiate Network Service
92
93     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}
94     Set Suite Variable   ${ns_id}   ${id}
95
96
97 Get Alarm Metric
98
99     Variable Should Exist   ${prometheus_poll_retries}   msg=Metric polling retries is not available
100     Variable Should Exist   ${prometheus_poll_timeout}   msg=Metric polling timeout is not available
101     Variable Should Exist   ${prometheus_host}   msg=Prometheus address is not available
102     Variable Should Exist   ${prometheus_port}   msg=Prometheus port is not available
103     Variable Should Exist   ${metric_name}   msg=Prometheus metric name is not available
104     ${metric_value}=   Wait Until Keyword Succeeds   ${prometheus_poll_retries}   ${prometheus_poll_timeout}   Get Metric   ${prometheus_host}   ${prometheus_port}   ${metric_name}
105     Run Keyword Unless   ${metric_value} > 0   Fail   msg=The metric '${metric_name}' value is '${metric_value}'
106
107
108 Check Alarms Were Received
109
110     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 '${alarm_msg}' | grep '${ns_name}'
111
112
113 Delete NS Instance
114     [Tags]   cleanup
115
116     Delete NS   ${ns_name}
117
118
119 Delete NS Descriptor
120     [Tags]   cleanup
121
122     Delete NSD   ${nsd_name}
123
124
125 Delete VNF Descriptor
126     [Tags]   cleanup
127
128     Delete VNFD   ${vnfd_name}
129
130
131 Delete Webhook Service NS Instance
132     [Tags]   cleanup
133
134     Delete NS   ${ws_ns_name}
135
136
137 Delete Webhook Service NS Descriptor
138     [Tags]   cleanup
139
140     Delete NSD   ${ws_nsd_name}
141
142
143 Delete Webhook Service VNF Descriptor
144     [Tags]   cleanup
145
146     Delete VNFD   ${ws_vnfd_name}
147
148
149 *** Keywords ***
150 Suite Cleanup
151     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
152
153     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
154     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
155     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_name}
156     Run Keyword If Any Tests Failed   Delete NS   ${ws_ns_name}
157     Run Keyword If Any Tests Failed   Delete NSD   ${ws_nsd_name}
158     Run Keyword If Any Tests Failed   Delete VNFD   ${ws_vnfd_name}
159     Delete Temporary Descriptor Folder   '%{PACKAGES_FOLDER}/${new_vnfd_pkg}'
160
161
162 Delete Temporary Descriptor Folder
163     [Documentation]   Removes the temporary package folder created for the test
164     [Arguments]   ${folder_name}
165     ${rc}   ${stdout}=   Run and Return RC and Output   rm -rf '${folder_name}'
166     log   ${stdout}
167
168