Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / testsuite / sa_02-vnf_with_vim_metrics_and_autoscaling.robot
1 *** Comments ***
2 #   Licensed under the Apache License, Version 2.0 (the "License");
3 #   you may not use this file except in compliance with the License.
4 #   You may obtain a copy of the License at
5 #
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
8 #   Unless required by applicable law or agreed to in writing, software
9 #   distributed under the License is distributed on an "AS IS" BASIS,
10 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 #   See the License for the specific language governing permissions and
12 #   limitations under the License.
13
14
15 *** Settings ***
16 Documentation   [SA-02] VNF with VIM-based metrics and auto-scaling.
17
18 Library   OperatingSystem
19 Library   String
20 Library   Collections
21 Library   SSHLibrary
22
23 Resource   ../lib/vnfd_lib.resource
24 Resource   ../lib/nsd_lib.resource
25 Resource   ../lib/ns_lib.resource
26 Resource   ../lib/ssh_lib.resource
27 Resource   ../lib/prometheus_lib.resource
28
29 Test Tags   sa_02   cluster_sa   daily   regression   sanity   azure
30
31 Suite Setup   Run Keyword And Ignore Error   Suite Preparation
32 Suite Teardown   Run Keyword And Ignore Error   Suite Cleanup
33
34
35 *** Variables ***
36 # NS instantiation parameters
37 ${NS_CONFIG}   {vld: [ {name: mgmtnet, vim-network-name: %{VIM_MGMT_NET}} ] }
38
39 # NS and VNF descriptor package folder and ids
40 ${VNFD_PKG}   hackfest_basic_metrics_vnf
41 ${VNFD_NAME}   hackfest_basic_metrics-vnf
42 ${NSD_PKG}   hackfest_basic_metrics_ns
43 ${NSD_NAME}   hackfest_basic-ns-metrics
44
45 # NS instance name and id
46 ${NS_ID}   ${EMPTY}
47 ${NS_NAME}   sa_02
48
49 # SSH keys and username to be used
50 ${PUBLICKEY}   %{HOME}/.ssh/id_rsa.pub
51 ${PRIVATEKEY}   %{HOME}/.ssh/id_rsa
52 ${USERNAME}   ubuntu
53 ${PASSWORD}   osm4u
54
55 # Prometheus polling interval and retries
56 ${PROMETHEUS_POLL_RETRIES}   15 times
57 ${PROMETHEUS_POLL_TIMEOUT}   1 minute
58
59 # Prometheus metrics to retrieve
60 ${METRIC_NAME}   osm_cpu_utilization
61
62 # VNF Variables
63 ${VNF_MEMBER_INDEX}   vnf
64 ${VNF_IP_ADDR}   ${EMPTY}
65 ${VNF_ID}   ${EMPTY}
66
67 ${SUCCESS_RETURN_CODE}   0
68
69
70 *** Test Cases ***
71 Create VNF Descriptor
72     [Documentation]   Upload VNF package for the testsuite.
73     Create VNFD   '%{PACKAGES_FOLDER}/${VNFD_PKG}'
74
75 Get Thresholds From VNF
76     [Documentation]   Read metric threshold and threshold time from VNF descriptor.
77     ${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"'
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     ${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 Create NS Descriptor
89     [Documentation]   Upload NS package for the testsuite.
90     Create NSD   '%{PACKAGES_FOLDER}/${NSD_PKG}'
91
92 Instantiate Network Service
93     [Documentation]   Instantiate the NS for the testsuite.
94     ${id}=   Create Network Service   ${NSD_NAME}   %{VIM_TARGET}   ${NS_NAME}   ${NS_CONFIG}   ${PUBLICKEY}
95     Set Suite Variable   ${NS_ID}   ${id}
96
97 Get VNF Id
98     [Documentation]   Retrieve VNF instance id to be used later on.
99     @{vnfr_list}=   Get Ns Vnfr Ids   ${NS_ID}
100     Log List   ${vnfr_list}
101     Set Suite Variable   ${VNF_ID}   ${vnfr_list}[0]
102
103 Get VNF IP Address
104     [Documentation]   Get the mgmt IP address of the VNF to be used in later tests.
105     ${ip_addr}=   Get Vnf Management Ip Address   ${NS_ID}   ${VNF_MEMBER_INDEX}
106     Log   ${ip_addr}
107     Set Suite Variable   ${VNF_IP_ADDR}   ${ip_addr}
108
109 Get VNF VIM-based Metric Before Auto-scaling
110     [Documentation]   Get from Prometheus the VIM metric associated to the VNF auto-scaling group.
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_filter}=   Set Variable   ns_id=${NS_ID}
117     ${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}
118     IF   ${metric_value} <= 0
119         Fail   msg=The metric '${METRIC_NAME}' value is '${metric_value}'
120     END
121     IF   ${metric_value} >= ${METRIC_THRESHOLD}
122         Fail   msg=The metric '${METRIC_NAME}' value is higher than '${METRIC_THRESHOLD}' before scaling
123     END
124
125 Increase VIM-based Metric To Force Auto-scaling
126     [Documentation]   Connect to the VNF via SSH and force VIM metric to increase.
127     Variable Should Exist   ${PRIVATEKEY}   msg=SSH private key not available
128     Execute Remote Command Check Rc Return Output   ${VNF_IP_ADDR}   ${USERNAME}   ${PASSWORD}   ${PRIVATEKEY}   for i in {1..9}; do yes &> /dev/null & done
129
130 Wait VIM-based Metric To Exceed Threshold
131     [Documentation]   Wait until the VIM metric exceeds threshold, which should lead to a scale up.
132     Variable Should Exist   ${PROMETHEUS_POLL_RETRIES}   msg=Metric polling retries is not available
133     Variable Should Exist   ${PROMETHEUS_POLL_TIMEOUT}   msg=Metric polling timeout is not available
134     Wait Until Keyword Succeeds   ${PROMETHEUS_POLL_RETRIES}   ${PROMETHEUS_POLL_TIMEOUT}   Check VIM-based Metric Exceeds Threshold
135
136 Wait Threshold Time
137     [Documentation]   Wait until the VIM metric has exceeded threshold for the defined period in the descriptor.
138     ${threshold_time_sleep}=   Evaluate   ${THRESHOLD_TIME} + 1
139     Sleep   ${threshold_time_sleep} minutes   Wait scale-out threshold time plus 1 minute
140
141 Check VIM-based Metric Exceeds Threshold After Threshold-time
142     [Documentation]   Check that the VIM metric has exceeded the threshold.
143     Check VIM-based Metric Exceeds Threshold
144
145 Get VDUs After Auto-scaling
146     [Documentation]   Check that the VNF has scaled up and the humber of VDUs has increased.
147     Sleep   2 minutes   Wait for auto-scale to take place
148     @{vdur_list}=   Get Vnf Vdur Names   ${VNF_ID}
149     Log List   ${vdur_list}
150     ${vdurs}=   Get Length   ${vdur_list}
151     IF   ${vdurs} <= 1   Fail   msg=There is no new VDU after auto-scaling
152
153 Delete NS Instance
154     [Documentation]   Delete NS instance.
155     [Tags]   cleanup
156     Delete NS   ${NS_NAME}
157
158 Delete NS Descriptor
159     [Documentation]   Delete NS package from OSM.
160     [Tags]   cleanup
161     Delete NSD   ${NSD_NAME}
162
163 Delete VNF Descriptor
164     [Documentation]   Delete VNF package from OSM.
165     [Tags]   cleanup
166     Delete VNFD   ${VNFD_NAME}
167
168
169 *** Keywords ***
170 Suite Preparation
171     [Documentation]   Test Suite Preparation: Setting Prometheus Testsuite Variables
172     Set Testsuite Prometheus Variables
173
174 Suite Cleanup
175     [Documentation]   Test Suite Cleanup: Deleting descriptors and NS instance
176     Run Keyword If Any Tests Failed   Delete NS   ${NS_NAME}
177     Run Keyword If Any Tests Failed   Delete NSD   ${NSD_NAME}
178     Run Keyword If Any Tests Failed   Delete VNFD   ${VNFD_NAME}
179
180 Check VIM-based Metric Exceeds Threshold
181     [Documentation]   Auxiliar keyword to check if metric exceeds threshold
182     Variable Should Exist   ${PROMETHEUS_HOST}   msg=Prometheus address is not available
183     Variable Should Exist   ${PROMETHEUS_PORT}   msg=Prometheus port is not available
184     Variable Should Exist   ${METRIC_NAME}   msg=Prometheus metric name is not available
185     ${metric_filter}=   Set Variable   ns_id=${NS_ID}
186     ${metric_value}=   Get Metric   ${PROMETHEUS_HOST}   ${PROMETHEUS_PORT}   ${PROMETHEUS_USER}   ${PROMETHEUS_PASSWORD}   ${METRIC_NAME}   ${metric_filter}
187     IF   ${metric_value} <= ${METRIC_THRESHOLD}
188         Fail   msg=The metric '${METRIC_NAME}' value is '${metric_value}' which is lower than '${METRIC_THRESHOLD}'
189     END