blob: 74d4ed99b4930deb0ed0b573498f0f326880aae0 [file] [log] [blame]
Lajos Katonac87a06b2019-01-04 13:21:48 +01001# Copyright (c) 2019 Ericsson
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from oslo_log import log as logging
16
17from tempest.common import utils
18from tempest.common import waiters
19from tempest import config
20from tempest.lib.common.utils import data_utils
21from tempest.lib.common.utils import test_utils
22from tempest.lib import decorators
23from tempest.scenario import manager
24
25
26LOG = logging.getLogger(__name__)
27CONF = config.CONF
28
29
30class MinBwAllocationPlacementTest(manager.NetworkScenarioTest):
31 credentials = ['primary', 'admin']
32 required_extensions = ['port-resource-request',
33 'qos',
34 'qos-bw-minimum-ingress']
35 # The feature QoS minimum bandwidth allocation in Placement API depends on
36 # Granular resource requests to GET /allocation_candidates and Support
37 # allocation candidates with nested resource providers features in
38 # Placement (see: https://specs.openstack.org/openstack/nova-specs/specs/
39 # stein/approved/bandwidth-resource-provider.html#rest-api-impact) and this
40 # means that the minimum placement microversion is 1.29
41 placement_min_microversion = '1.29'
42 placement_max_microversion = 'latest'
43
44 # Nova rejects to boot VM with port which has resource_request field, below
45 # microversion 2.72
46 compute_min_microversion = '2.72'
47 compute_max_microversion = 'latest'
48
49 INGRESS_RESOURCE_CLASS = "NET_BW_IGR_KILOBIT_PER_SEC"
50 INGRESS_DIRECTION = 'ingress'
51
52 SMALLEST_POSSIBLE_BW = 1
53 # For any realistic inventory value (that is inventory != MAX_INT) an
54 # allocation candidate request of MAX_INT is expected to be rejected, see:
55 # https://github.com/openstack/placement/blob/master/placement/
56 # db/constants.py#L16
57 PLACEMENT_MAX_INT = 0x7FFFFFFF
58
59 @classmethod
60 def setup_clients(cls):
61 super(MinBwAllocationPlacementTest, cls).setup_clients()
62 cls.placement_client = cls.os_admin.placement_client
63 cls.networks_client = cls.os_admin.networks_client
64 cls.subnets_client = cls.os_admin.subnets_client
65 cls.routers_client = cls.os_adm.routers_client
66 cls.qos_client = cls.os_admin.qos_client
67 cls.qos_min_bw_client = cls.os_admin.qos_min_bw_client
68
69 @classmethod
70 def skip_checks(cls):
71 super(MinBwAllocationPlacementTest, cls).skip_checks()
72 if not CONF.network_feature_enabled.qos_placement_physnet:
73 msg = "Skipped as no physnet is available in config for " \
74 "placement based QoS allocation."
75 raise cls.skipException(msg)
76
77 def _create_policy_and_min_bw_rule(self, name_prefix, min_kbps):
78 policy = self.qos_client.create_qos_policy(
79 name=data_utils.rand_name(name_prefix),
80 shared=True)['policy']
81 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
82 self.qos_client.delete_qos_policy, policy['id'])
83 rule = self.qos_min_bw_client.create_minimum_bandwidth_rule(
84 policy['id'],
85 **{
86 'min_kbps': min_kbps,
87 'direction': self.INGRESS_DIRECTION
88 })['minimum_bandwidth_rule']
89 self.addCleanup(
90 test_utils.call_and_ignore_notfound_exc,
91 self.qos_min_bw_client.delete_minimum_bandwidth_rule, policy['id'],
92 rule['id'])
93
94 return policy
95
96 def _create_qos_policies(self):
97 self.qos_policy_valid = self._create_policy_and_min_bw_rule(
98 name_prefix='test_policy_valid',
99 min_kbps=self.SMALLEST_POSSIBLE_BW)
100 self.qos_policy_not_valid = self._create_policy_and_min_bw_rule(
101 name_prefix='test_policy_not_valid',
102 min_kbps=self.PLACEMENT_MAX_INT)
103
104 def _create_network_and_qos_policies(self):
105 physnet_name = CONF.network_feature_enabled.qos_placement_physnet
106 base_segm = \
107 CONF.network_feature_enabled.provider_net_base_segmentation_id
108
109 self.prov_network, _, _ = self.create_networks(
110 networks_client=self.networks_client,
111 routers_client=self.routers_client,
112 subnets_client=self.subnets_client,
113 **{
114 'shared': True,
115 'provider:network_type': 'vlan',
116 'provider:physical_network': physnet_name,
117 'provider:segmentation_id': base_segm
118 })
119
120 self._create_qos_policies()
121
122 def _check_if_allocation_is_possible(self):
123 alloc_candidates = self.placement_client.list_allocation_candidates(
124 resources1='%s:%s' % (self.INGRESS_RESOURCE_CLASS,
125 self.SMALLEST_POSSIBLE_BW))
126 if len(alloc_candidates['provider_summaries']) == 0:
Lucas Alvares Gomes0976ae42020-09-01 10:04:59 +0100127 # Skip if the backend does not support QoS minimum bandwidth
128 # allocation in Placement API
129 raise self.skipException(
130 'No allocation candidates are available for %s:%s' %
131 (self.INGRESS_RESOURCE_CLASS, self.SMALLEST_POSSIBLE_BW))
Lajos Katonac87a06b2019-01-04 13:21:48 +0100132
133 # Just to be sure check with impossible high (placement max_int),
134 # allocation
135 alloc_candidates = self.placement_client.list_allocation_candidates(
136 resources1='%s:%s' % (self.INGRESS_RESOURCE_CLASS,
137 self.PLACEMENT_MAX_INT))
138 if len(alloc_candidates['provider_summaries']) != 0:
139 self.fail('For %s:%s there should be no available candidate!' %
140 (self.INGRESS_RESOURCE_CLASS, self.PLACEMENT_MAX_INT))
141
142 @decorators.idempotent_id('78625d92-212c-400e-8695-dd51706858b8')
143 @decorators.attr(type='slow')
144 @utils.services('compute', 'network')
145 def test_qos_min_bw_allocation_basic(self):
146 """"Basic scenario with QoS min bw allocation in placement.
147
148 Steps:
149 * Create prerequisites:
150 ** VLAN type provider network with subnet.
151 ** valid QoS policy with minimum bandwidth rule with min_kbps=1
152 (This is a simplification to skip the checks in placement for
153 detecting the resource provider tree and inventories, as if
154 bandwidth resource is available 1 kbs will be available).
155 ** invalid QoS policy with minimum bandwidth rule with
156 min_kbs=max integer from placement (this is a simplification again
157 to avoid detection of RP tress and inventories, as placement will
158 reject such big allocation).
159 * Create port with valid QoS policy, and boot VM with that, it should
160 pass.
161 * Create port with invalid QoS policy, and try to boot VM with that,
162 it should fail.
163 """
164
165 self._check_if_allocation_is_possible()
166
167 self._create_network_and_qos_policies()
168
169 valid_port = self.create_port(
170 self.prov_network['id'], qos_policy_id=self.qos_policy_valid['id'])
171
172 server1 = self.create_server(
173 networks=[{'port': valid_port['id']}])
174 allocations = self.placement_client.list_allocations(server1['id'])
175
176 self.assertGreater(len(allocations['allocations']), 0)
177 bw_resource_in_alloc = False
178 for rp, resources in allocations['allocations'].items():
179 if self.INGRESS_RESOURCE_CLASS in resources['resources']:
180 bw_resource_in_alloc = True
elajkate4f28202019-10-24 12:56:42 +0200181 allocation_rp = rp
Lajos Katonac87a06b2019-01-04 13:21:48 +0100182 self.assertTrue(bw_resource_in_alloc)
elajkate4f28202019-10-24 12:56:42 +0200183 # Check that binding_profile of the port is not empty and equals with
184 # the rp uuid
185 port = self.os_admin.ports_client.show_port(valid_port['id'])
186 self.assertEqual(allocation_rp,
187 port['port']['binding:profile']['allocation'])
Lajos Katonac87a06b2019-01-04 13:21:48 +0100188
189 # boot another vm with max int bandwidth
190 not_valid_port = self.create_port(
191 self.prov_network['id'],
192 qos_policy_id=self.qos_policy_not_valid['id'])
193 server2 = self.create_server(
194 wait_until=None,
195 networks=[{'port': not_valid_port['id']}])
196 waiters.wait_for_server_status(
197 client=self.os_primary.servers_client, server_id=server2['id'],
198 status='ERROR', ready_wait=False, raise_on_error=False)
199 allocations = self.placement_client.list_allocations(server2['id'])
200
201 self.assertEqual(0, len(allocations['allocations']))
202 server2 = self.servers_client.show_server(server2['id'])
203 self.assertIn('fault', server2['server'])
204 self.assertIn('No valid host', server2['server']['fault']['message'])
elajkate4f28202019-10-24 12:56:42 +0200205 # Check that binding_profile of the port is empty
206 port = self.os_admin.ports_client.show_port(not_valid_port['id'])
207 self.assertEqual(0, len(port['port']['binding:profile']))