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