Debian Codegraph @

octavia_tempest_plugin/tests/api/v2/test_provider.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 oslo_log import log as logging
16 from tempest import config
17 from tempest.lib import decorators
18
19 from octavia_tempest_plugin.common import constants as const
20 from octavia_tempest_plugin.tests import test_base
21
22 CONF = config.CONF
23 LOG = logging.getLogger(__name__)
24
25
26 class ProviderAPITest(test_base.LoadBalancerBaseTest):
27 """Test the provider object API."""
28
29 @decorators.idempotent_id('8b94e0cc-a24d-4c29-bc8e-53f58214dc67')
30 def test_provider_list(self):
31 """Tests provider list API and field filtering.
32
33 * Validates that non-lb member accounts cannot list the providers.
34 * List the providers and validate against the expected provider list.
35 * List the providers returning one field at a time.
36 """
37 # We have to do this here as the api_version and clients are not
38 # setup in time to use a decorator or the skip_checks mixin
39 if not self.mem_provider_client.is_version_supported(
40 self.api_version, '2.1'):
41 raise self.skipException('Providers are only available on '
42 'Octavia API version 2.1 or newer.')
43
44 # Test that a user without the load balancer role cannot
45 # list providers.
46 expected_allowed = []
47 if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN:
48 expected_allowed = [
49 'os_admin', 'os_primary', 'os_roles_lb_admin',
50 'os_roles_lb_member', 'os_roles_lb_member2']
51 if CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES:
52 expected_allowed = ['os_admin', 'os_primary', 'os_roles_lb_admin',
53 'os_roles_lb_observer',
54 'os_roles_lb_global_observer',
55 'os_roles_lb_member', 'os_roles_lb_member2']
56 if CONF.load_balancer.RBAC_test_type == const.ADVANCED:
57 expected_allowed = [
58 'os_admin', 'os_roles_lb_observer',
59 'os_roles_lb_global_observer',
60 'os_roles_lb_admin', 'os_roles_lb_member',
61 'os_roles_lb_member2']
62 if expected_allowed:
63 self.check_list_RBAC_enforcement(
64 'ProviderClient', 'list_providers', expected_allowed)
65
66 providers = self.mem_provider_client.list_providers()
67
68 # Check against the expected providers from the tempest config
69 enabled_providers = CONF.load_balancer.enabled_provider_drivers
70 for provider in providers:
71 self.assertEqual(enabled_providers[provider[const.NAME]],
72 provider.get(const.DESCRIPTION, ''))
73
74 # Test fields
75 providers = self.mem_provider_client.list_providers(
76 query_params='{fields}={field}'.format(fields=const.FIELDS,
77 field=const.NAME))
78 for provider in providers:
79 self.assertEqual(1, len(provider))
80 self.assertIn(provider[const.NAME], enabled_providers.keys())
81 providers = self.mem_provider_client.list_providers(
82 query_params='{fields}={field}'.format(fields=const.FIELDS,
83 field=const.DESCRIPTION))
84 for provider in providers:
85 self.assertEqual(1, len(provider))
86 self.assertIn(provider[const.DESCRIPTION],
87 enabled_providers.values())