Revert "Feature 11001: Robot framework linting for E2E tests"
[osm/tests.git] / robot-systest / testsuite / sa_02-vnf_with_vim_metrics_and_autoscaling.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-02] VNF with VIM-based metrics and auto-scaling.
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_02   cluster_sa   daily   regression   sanity   azure
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}   hackfest_basic_metrics_vnf
39 ${vnfd_name}   hackfest_basic_metrics-vnf
40 ${nsd_pkg}   hackfest_basic_metrics_ns
41 ${nsd_name}   hackfest_basic-ns-metrics
42
43 # NS instance name and id
44 ${ns_id}   ${EMPTY}
45 ${ns_name}   sa_02
46
47 # SSH keys and username to be used
48 ${publickey}   %{HOME}/.ssh/id_rsa.pub
49 ${privatekey}   %{HOME}/.ssh/id_rsa
50 ${username}   ubuntu
51 ${password}   osm4u
52
53 # Prometheus polling interval and retries
54 ${prometheus_poll_retries}   15 times
55 ${prometheus_poll_timeout}   1 minute
56
57 # Prometheus metrics to retrieve
58 ${metric_name}   osm_cpu_utilization
59
60 # VNF Variables
61 ${vnf_member_index}   vnf
62 ${vnf_ip_addr}   ${EMPTY}
63 ${vnf_id}   ${EMPTY}
64
65 ${success_return_code}   0
66
67
68 *** Test Cases ***
69 Create VNF Descriptor
70
71     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_pkg}'
72
73
74 Get Thresholds From VNF
75
76     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnfpkg-show ${vnfd_name} --literal | yq -r '.df[0]."scaling-aspect"[0]."scaling-policy"[0]."scaling-criteria"[0]."scale-out-threshold"'
77     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${stdout}   values=False
78     ${scaleout_threshold}=   Convert To Number   ${stdout}
79     Set Suite Variable   ${metric_threshold}   ${scaleout_threshold}
80     Log   ${metric_threshold}
81
82     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnfpkg-show ${vnfd_name} --literal | yq -r '.df[0]."scaling-aspect"[0]."scaling-policy"[0]."threshold-time"'
83     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${stdout}   values=False
84     ${threshold_time_value}=   Convert To Number   ${stdout}
85     Set Suite Variable   ${threshold_time}   ${threshold_time_value}
86     Log   ${threshold_time}
87
88
89 Create NS Descriptor
90
91     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
92
93
94 Instantiate Network Service
95
96     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}
97     Set Suite Variable   ${ns_id}   ${id}
98
99
100 Get VNF Id
101
102     @{vnfr_list}=   Get Ns Vnfr Ids   ${ns_id}
103     Log List   ${vnfr_list}
104     Set Suite Variable   ${vnf_id}   ${vnfr_list}[0]
105
106
107 Get VNF IP Address
108
109     ${ip_addr}=   Get Vnf Management Ip Address   ${ns_id}   ${vnf_member_index}
110     Log   ${ip_addr}
111     Set Suite Variable   ${vnf_ip_addr}   ${ip_addr}
112
113
114 Get VNF VIM-based Metric Before Auto-scaling
115
116     Variable Should Exist   ${prometheus_poll_retries}   msg=Metric polling retries is not available
117     Variable Should Exist   ${prometheus_poll_timeout}   msg=Metric polling timeout is not available
118     Variable Should Exist   ${prometheus_host}   msg=Prometheus address is not available
119     Variable Should Exist   ${prometheus_port}   msg=Prometheus port is not available
120     Variable Should Exist   ${metric_name}   msg=Prometheus metric name is not available
121     ${metric_filter}=   Set Variable   ns_id=${ns_id}
122     ${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}
123     Run Keyword If   ${metric_value} <= 0   Fail   msg=The metric '${metric_name}' value is '${metric_value}'
124     Run Keyword If   ${metric_value} >= ${metric_threshold}   Fail   msg=The metric '${metric_name}' value is higher than '${metric_threshold}' before scaling
125
126
127 Increase VIM-based Metric To Force Auto-scaling
128
129     Variable Should Exist   ${privatekey}   msg=SSH private key not available
130     Execute Remote Command Check Rc Return Output   ${vnf_ip_addr}   ${username}   ${password}   ${privatekey}   for i in {1..9}; do yes &> /dev/null & done
131
132
133 Wait VIM-based Metric To Exceed Threshold
134
135     Variable Should Exist   ${prometheus_poll_retries}   msg=Metric polling retries is not available
136     Variable Should Exist   ${prometheus_poll_timeout}   msg=Metric polling timeout is not available
137     Wait Until Keyword Succeeds   ${prometheus_poll_retries}   ${prometheus_poll_timeout}   Check VIM-based Metric Exceeds Threshold
138
139
140 Wait Threshold Time
141
142     ${threshold_time_sleep}=   Evaluate   ${threshold_time} + 1
143     Sleep   ${threshold_time_sleep} minutes   Wait scale-out threshold time plus 1 minute
144
145
146 Check VIM-based Metric Exceeds Threshold After Threshold-time
147
148     Check VIM-based Metric Exceeds Threshold
149
150
151 Get VDUs After Auto-scaling
152
153     Sleep   2 minutes   Wait for auto-scale to take place
154     @{vdur_list}=   Get Vnf Vdur Names   ${vnf_id}
155     Log List   ${vdur_list}
156     ${vdurs}=   Get Length   ${vdur_list}
157     Run Keyword If   ${vdurs} <= 1   Fail   msg=There is no new VDU after auto-scaling
158
159
160 Delete NS Instance
161     [Tags]   cleanup
162
163     Delete NS   ${ns_name}
164
165
166 Delete NS Descriptor
167     [Tags]   cleanup
168
169     Delete NSD   ${nsd_name}
170
171
172 Delete VNF Descriptor
173     [Tags]   cleanup
174
175     Delete VNFD   ${vnfd_name}
176
177
178 *** Keywords ***
179 Suite Preparation
180     [Documentation]   Test Suite Preparation: Setting Prometheus Testsuite Variables
181
182     Set Testsuite Prometheus Variables
183
184
185 Suite Cleanup
186     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
187
188     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
189     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
190     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_name}
191
192
193 Check VIM-based Metric Exceeds Threshold
194     [Documentation]   Auxiliar keyword to check if metric exceeds threshold
195
196     Variable Should Exist   ${prometheus_host}   msg=Prometheus address is not available
197     Variable Should Exist   ${prometheus_port}   msg=Prometheus port is not available
198     Variable Should Exist   ${metric_name}   msg=Prometheus metric name is not available
199     ${metric_filter}=   Set Variable   ns_id=${ns_id}
200     ${metric_value}=   Get Metric   ${prometheus_host}   ${prometheus_port}   ${prometheus_user}   ${prometheus_password}   ${metric_name}   ${metric_filter}
201     Run Keyword If   ${metric_value} <= ${metric_threshold}   Fail   msg=The metric '${metric_name}' value is '${metric_value}' which is lower than '${metric_threshold}'