Move variables from resources to testsuite for SA 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 Variables   %{ROBOT_DEVOPS_FOLDER}/resources/sa_02-vnf_with_vim_metrics_and_autoscaling_data.py
28
29 Force Tags   sa_02   cluster_sa   daily   regression   sanity
30
31 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
32
33
34 *** Variables ***
35 # NS instantiation parameters
36 ${ns_config}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
37
38 # NS and VNF descriptor package folder and ids
39 ${vnfd_pkg}   hackfest_basic_metrics_vnf
40 ${vnfd_name}   hackfest_basic_metrics-vnf
41 ${nsd_pkg}   hackfest_basic_metrics_ns
42 ${nsd_name}   hackfest_basic-ns-metrics
43
44 # NS instance name and id
45 ${ns_id}   ${EMPTY}
46 ${ns_name}   sa_02
47
48 # SSH keys and username to be used
49 ${publickey}   %{HOME}/.ssh/id_rsa.pub
50 ${privatekey}   %{HOME}/.ssh/id_rsa
51 ${username}   ubuntu
52 ${password}   osm4u
53
54 # Prometheus polling interval and retries
55 ${prometheus_poll_retries}   15 times
56 ${prometheus_poll_timeout}   1 minute
57
58 # Prometheus metrics to retrieve
59 ${metric_name}   osm_cpu_utilization
60
61 # VNF Variables
62 ${vnf_member_index}   vnf
63 ${vnf_ip_addr}   ${EMPTY}
64 ${vnf_id}   ${EMPTY}
65
66 ${success_return_code}   0
67
68
69 *** Test Cases ***
70 Create VNF Descriptor
71
72     Create VNFD   '%{PACKAGES_FOLDER}/${vnfd_pkg}'
73
74
75 Get Scale-Out Threshold From VNF
76
77     ${rc}   ${stdout}=   Run and Return RC and Output   osm vnfpkg-show ${vnfd_name} --literal | yq '.df[0]."scaling-aspect"[0]."scaling-policy"[0]."scaling-criteria"[0]."scale-out-threshold"' | tr -d \\"
78     Should Be Equal As Integers   ${rc}   ${success_return_code}   msg=${stdout}   values=False
79     ${scaleout_threshold}=   Convert To Number   ${stdout}
80     Set Suite Variable   ${metric_threshold}   ${scaleout_threshold}
81     log   ${metric_threshold}
82
83
84 Create NS Descriptor
85
86     Create NSD   '%{PACKAGES_FOLDER}/${nsd_pkg}'
87
88
89 Instantiate Network Service
90
91     ${id}=   Create Network Service   ${nsd_name}   %{VIM_TARGET}   ${ns_name}   ${ns_config}   ${publickey}
92     Set Suite Variable   ${ns_id}   ${id}
93
94
95 Get VNF Id
96
97     @{vnfr_list}=   Get Ns Vnfr Ids   ${ns_id}
98     Log List   ${vnfr_list}
99     Set Suite Variable   ${vnf_id}   ${vnfr_list}[0]
100
101
102 Get VNF IP Address
103
104     ${ip_addr}=   Get Vnf Management Ip Address   ${ns_id}   ${vnf_member_index}
105     log   ${ip_addr}
106     Set Suite Variable   ${vnf_ip_addr}   ${ip_addr}
107
108
109 Get VNF VIM-based Metric Before Auto-scaling
110
111     Variable Should Exist   ${prometheus_poll_retries}   msg=Metric polling retries is not available
112     Variable Should Exist   ${prometheus_poll_timeout}   msg=Metric polling timeout is not available
113     Variable Should Exist   ${prometheus_host}   msg=Prometheus address is not available
114     Variable Should Exist   ${prometheus_port}   msg=Prometheus port is not available
115     Variable Should Exist   ${metric_name}   msg=Prometheus metric name is not available
116     ${metric_value}=   Wait Until Keyword Succeeds   ${prometheus_poll_retries}   ${prometheus_poll_timeout}   Get Metric   ${prometheus_host}   ${prometheus_port}   ${metric_name}
117     Run Keyword If   ${metric_value} <= 0   Fail   msg=The metric '${metric_name}' value is '${metric_value}'
118     Run Keyword If   ${metric_value} >= ${metric_threshold}   Fail   msg=The metric '${metric_name}' value is higher than '${metric_threshold}' before scaling
119
120
121 Increase VIM-based Metric To Force Auto-scaling
122
123     Variable Should Exist   ${privatekey}   msg=SSH private key not available
124     Execute Remote Command Check Rc Return Output   ${vnf_ip_addr}   ${username}   ${password}   ${privatekey}   for i in {1..9}; do yes > /dev/null & done
125
126
127 Wait VIM-based Metric To Exceed Threshold
128
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     Wait Until Keyword Succeeds   ${prometheus_poll_retries}   ${prometheus_poll_timeout}   Check VIM-based Metric Exceeds Threshold
132
133
134 Get VDUs After Auto-scaling
135
136     Sleep   2 minutes   Wait for auto-scale to take place
137     @{vdur_list}=   Get Vnf Vdur Names   ${vnf_id}
138     Log List   ${vdur_list}
139     ${vdurs}=   Get Length   ${vdur_list}
140     Run Keyword If   ${vdurs} <= 1   Fail   msg=There is no new VDU after auto-scaling
141
142
143 Delete NS Instance
144     [Tags]   cleanup
145
146     Delete NS   ${ns_name}
147
148
149 Delete NS Descriptor
150     [Tags]   cleanup
151
152     Delete NSD   ${nsd_name}
153
154
155 Delete VNF Descriptor
156     [Tags]   cleanup
157
158     Delete VNFD   ${vnfd_name}
159
160
161 *** Keywords ***
162 Suite Cleanup
163     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
164
165     Run Keyword If Any Tests Failed   Delete NS   ${ns_name}
166     Run Keyword If Any Tests Failed   Delete NSD   ${nsd_name}
167     Run Keyword If Any Tests Failed   Delete VNFD   ${vnfd_name}
168
169
170 Check VIM-based Metric Exceeds Threshold
171     [Documentation]   Auxiliar keyword to check if metric exceeds threshold
172
173     Variable Should Exist   ${prometheus_host}   msg=Prometheus address is not available
174     Variable Should Exist   ${prometheus_port}   msg=Prometheus port is not available
175     Variable Should Exist   ${metric_name}   msg=Prometheus metric name is not available
176     ${metric_value}=   Get Metric   ${prometheus_host}   ${prometheus_port}   ${metric_name}
177     Run Keyword If   ${metric_value} <= ${metric_threshold}   Fail   msg=The metric '${metric_name}' value is '${metric_value}' which is lower than '${metric_threshold}'
178
179