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