Debian Codegraph @

octavia_tempest_plugin/tests/api/v2/test_flavor_capabilities.py

raw symbols SCIP
1 # Copyright 2019 Rackspace US Inc. All rights reserved.
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 tempest import config
16 from tempest.lib import decorators
17
18 from octavia_tempest_plugin.common import constants as const
19 from octavia_tempest_plugin.tests import test_base
20
21 CONF = config.CONF
22
23
24 class FlavorCapabilitiesAPITest(test_base.LoadBalancerBaseTest):
25 """Test the provider flavor capabilities API."""
26
27 @decorators.idempotent_id('df837ee3-ca4b-4a4d-a7a3-27fa57cf3a33')
28 def test_flavor_capabilities_list(self):
29 """Tests provider flavor capabilities list API and field filtering.
30
31 * Validates that non-lb admin accounts cannot list the capabilities.
32 * List the flavor capablilities.
33 * Validate that the "loadbalancer_topology" capablility is present.
34 * List the providers returning one field at a time.
35 """
36 # We have to do this here as the api_version and clients are not
37 # setup in time to use a decorator or the skip_checks mixin
38 if not self.mem_provider_client.is_version_supported(
39 self.api_version, '2.6'):
40 raise self.skipException('Flavor capabilities are only available '
41 'on Octavia API version 2.6 or newer.')
42
43 # Test that a user without the load balancer admin role cannot
44 # list provider flavor capabilities.
45 expected_allowed = ['os_admin', 'os_roles_lb_admin']
46 self.check_list_RBAC_enforcement(
47 'FlavorCapabilitiesClient',
48 'list_flavor_capabilities', expected_allowed,
49 CONF.load_balancer.provider)
50
51 # Check for an expected flavor capability for the configured provider
52 admin_capabilities_client = self.lb_admin_flavor_capabilities_client
53 capabilities = admin_capabilities_client.list_flavor_capabilities(
54 CONF.load_balancer.provider)
55
56 expected_name = list(
57 CONF.load_balancer.expected_flavor_capability.keys())[0]
58 expected_description = (
59 CONF.load_balancer.expected_flavor_capability[expected_name])
60 for capability in capabilities:
61 if capability[const.NAME] == expected_name:
62 self.assertEqual(expected_description,
63 capability[const.DESCRIPTION])
64
65 # Test fields
66 capabilities = admin_capabilities_client.list_flavor_capabilities(
67 CONF.load_balancer.provider,
68 query_params='{fields}={field}&{field}={exp_name}'.format(
69 fields=const.FIELDS, field=const.NAME, exp_name=expected_name))
70 self.assertEqual(1, len(capabilities[0]))
71 self.assertEqual(expected_name, capabilities[0][const.NAME])
72
73 capabilities = admin_capabilities_client.list_flavor_capabilities(
74 CONF.load_balancer.provider,
75 query_params='{fields}={field}&{name}={exp_name}'.format(
76 fields=const.FIELDS, field=const.DESCRIPTION, name=const.NAME,
77 exp_name=expected_name))
78 self.assertEqual(1, len(capabilities[0]))
79 self.assertEqual(expected_description,
80 capabilities[0][const.DESCRIPTION])