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