Lajos Katona | c87a06b | 2019-01-04 13:21:48 +0100 | [diff] [blame] | 1 | # 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 | |
| 15 | from oslo_log import log as logging |
| 16 | |
| 17 | from tempest.common import utils |
| 18 | from tempest.common import waiters |
| 19 | from tempest import config |
| 20 | from tempest.lib.common.utils import data_utils |
| 21 | from tempest.lib.common.utils import test_utils |
| 22 | from tempest.lib import decorators |
| 23 | from tempest.scenario import manager |
| 24 | |
| 25 | |
| 26 | LOG = logging.getLogger(__name__) |
| 27 | CONF = config.CONF |
| 28 | |
| 29 | |
| 30 | class 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: |
| 127 | self.fail('No allocation candidates are available for %s:%s' % |
| 128 | (self.INGRESS_RESOURCE_CLASS, self.SMALLEST_POSSIBLE_BW)) |
| 129 | |
| 130 | # Just to be sure check with impossible high (placement max_int), |
| 131 | # allocation |
| 132 | alloc_candidates = self.placement_client.list_allocation_candidates( |
| 133 | resources1='%s:%s' % (self.INGRESS_RESOURCE_CLASS, |
| 134 | self.PLACEMENT_MAX_INT)) |
| 135 | if len(alloc_candidates['provider_summaries']) != 0: |
| 136 | self.fail('For %s:%s there should be no available candidate!' % |
| 137 | (self.INGRESS_RESOURCE_CLASS, self.PLACEMENT_MAX_INT)) |
| 138 | |
| 139 | @decorators.idempotent_id('78625d92-212c-400e-8695-dd51706858b8') |
| 140 | @decorators.attr(type='slow') |
| 141 | @utils.services('compute', 'network') |
| 142 | def test_qos_min_bw_allocation_basic(self): |
| 143 | """"Basic scenario with QoS min bw allocation in placement. |
| 144 | |
| 145 | Steps: |
| 146 | * Create prerequisites: |
| 147 | ** VLAN type provider network with subnet. |
| 148 | ** valid QoS policy with minimum bandwidth rule with min_kbps=1 |
| 149 | (This is a simplification to skip the checks in placement for |
| 150 | detecting the resource provider tree and inventories, as if |
| 151 | bandwidth resource is available 1 kbs will be available). |
| 152 | ** invalid QoS policy with minimum bandwidth rule with |
| 153 | min_kbs=max integer from placement (this is a simplification again |
| 154 | to avoid detection of RP tress and inventories, as placement will |
| 155 | reject such big allocation). |
| 156 | * Create port with valid QoS policy, and boot VM with that, it should |
| 157 | pass. |
| 158 | * Create port with invalid QoS policy, and try to boot VM with that, |
| 159 | it should fail. |
| 160 | """ |
| 161 | |
| 162 | self._check_if_allocation_is_possible() |
| 163 | |
| 164 | self._create_network_and_qos_policies() |
| 165 | |
| 166 | valid_port = self.create_port( |
| 167 | self.prov_network['id'], qos_policy_id=self.qos_policy_valid['id']) |
| 168 | |
| 169 | server1 = self.create_server( |
| 170 | networks=[{'port': valid_port['id']}]) |
| 171 | allocations = self.placement_client.list_allocations(server1['id']) |
| 172 | |
| 173 | self.assertGreater(len(allocations['allocations']), 0) |
| 174 | bw_resource_in_alloc = False |
| 175 | for rp, resources in allocations['allocations'].items(): |
| 176 | if self.INGRESS_RESOURCE_CLASS in resources['resources']: |
| 177 | bw_resource_in_alloc = True |
| 178 | self.assertTrue(bw_resource_in_alloc) |
| 179 | |
| 180 | # boot another vm with max int bandwidth |
| 181 | not_valid_port = self.create_port( |
| 182 | self.prov_network['id'], |
| 183 | qos_policy_id=self.qos_policy_not_valid['id']) |
| 184 | server2 = self.create_server( |
| 185 | wait_until=None, |
| 186 | networks=[{'port': not_valid_port['id']}]) |
| 187 | waiters.wait_for_server_status( |
| 188 | client=self.os_primary.servers_client, server_id=server2['id'], |
| 189 | status='ERROR', ready_wait=False, raise_on_error=False) |
| 190 | allocations = self.placement_client.list_allocations(server2['id']) |
| 191 | |
| 192 | self.assertEqual(0, len(allocations['allocations'])) |
| 193 | server2 = self.servers_client.show_server(server2['id']) |
| 194 | self.assertIn('fault', server2['server']) |
| 195 | self.assertIn('No valid host', server2['server']['fault']['message']) |