Adds provider flavor capabilities API tests
This patch adds provider flavor capabilities API tests to the Octavia
tempest plugin.
Change-Id: Ie4f9f72e011ee8aa30e8f9aa35558533839fb8c8
diff --git a/octavia_tempest_plugin/config.py b/octavia_tempest_plugin/config.py
index dee2bd2..52da1f2 100644
--- a/octavia_tempest_plugin/config.py
+++ b/octavia_tempest_plugin/config.py
@@ -115,6 +115,18 @@
default=const.SINGLE,
choices=const.SUPPORTED_LB_TOPOLOGIES,
help='Load balancer topology configuration.'),
+ cfg.DictOpt('expected_flavor_capability',
+ help=('Defines a provider flavor capability that is expected '
+ 'to be present in the selected provider under test. '
+ 'It is specified in a "name": "description" dict. '
+ 'Example: {"loadbalancer_topology": "The load balancer '
+ 'topology. One of: SINGLE - One amphora per load '
+ 'balancer. ACTIVE_STANDBY - Two amphora per load '
+ 'balancer."}'),
+ default={'loadbalancer_topology': 'The load balancer '
+ 'topology. One of: SINGLE - One amphora per load '
+ 'balancer. ACTIVE_STANDBY - Two amphora per load '
+ 'balancer.'}),
# Networking
cfg.BoolOpt('test_with_ipv6',
default=True,
diff --git a/octavia_tempest_plugin/tests/api/v2/test_flavor_capabilities.py b/octavia_tempest_plugin/tests/api/v2/test_flavor_capabilities.py
new file mode 100644
index 0000000..924c044
--- /dev/null
+++ b/octavia_tempest_plugin/tests/api/v2/test_flavor_capabilities.py
@@ -0,0 +1,83 @@
+# Copyright 2019 Rackspace US Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from tempest import config
+from tempest.lib import decorators
+from tempest.lib import exceptions
+
+from octavia_tempest_plugin.common import constants as const
+from octavia_tempest_plugin.tests import test_base
+
+CONF = config.CONF
+
+
+class FlavorCapabilitiesAPITest(test_base.LoadBalancerBaseTest):
+ """Test the provider flavor capabilities API."""
+
+ @decorators.idempotent_id('df837ee3-ca4b-4a4d-a7a3-27fa57cf3a33')
+ def test_flavor_capabilities_list(self):
+ """Tests provider flavor capabilities list API and field filtering.
+
+ * Validates that non-lb admin accounts cannot list the capabilities.
+ * List the flavor capablilities.
+ * Validate that the "loadbalancer_topology" capablility is present.
+ * List the providers returning one field at a time.
+ """
+ # We have to do this here as the api_version and clients are not
+ # setup in time to use a decorator or the skip_checks mixin
+ if not self.mem_provider_client.is_version_supported(
+ self.api_version, '2.6'):
+ raise self.skipException('Flavor capabilities are only available '
+ 'on Octavia API version 2.6 or newer.')
+
+ # Test that a user without the load balancer admin role cannot
+ # list provider flavor capabilities.
+ if CONF.load_balancer.RBAC_test_type == const.ADVANCED:
+ os_primary_capabilities_client = (
+ self.os_primary.flavor_capabilities_client)
+ self.assertRaises(
+ exceptions.Forbidden,
+ os_primary_capabilities_client.list_flavor_capabilities,
+ CONF.load_balancer.provider)
+
+ # Check for an expected flavor capability for the configured provider
+ admin_capabilities_client = self.lb_admin_capabilities_client
+ capabilities = admin_capabilities_client.list_flavor_capabilities(
+ CONF.load_balancer.provider)
+
+ expected_name = list(
+ CONF.load_balancer.expected_flavor_capability.keys())[0]
+ expected_description = (
+ CONF.load_balancer.expected_flavor_capability[expected_name])
+ for capability in capabilities:
+ if capability[const.NAME] == expected_name:
+ self.assertEqual(expected_description,
+ capability[const.DESCRIPTION])
+
+ # Test fields
+ capabilities = admin_capabilities_client.list_flavor_capabilities(
+ CONF.load_balancer.provider,
+ query_params='{fields}={field}&{field}={exp_name}'.format(
+ fields=const.FIELDS, field=const.NAME, exp_name=expected_name))
+ self.assertEqual(1, len(capabilities[0]))
+ self.assertEqual(expected_name, capabilities[0][const.NAME])
+
+ capabilities = admin_capabilities_client.list_flavor_capabilities(
+ CONF.load_balancer.provider,
+ query_params='{fields}={field}&{name}={exp_name}'.format(
+ fields=const.FIELDS, field=const.DESCRIPTION, name=const.NAME,
+ exp_name=expected_name))
+ self.assertEqual(1, len(capabilities[0]))
+ self.assertEqual(expected_description,
+ capabilities[0][const.DESCRIPTION])
diff --git a/octavia_tempest_plugin/tests/test_base.py b/octavia_tempest_plugin/tests/test_base.py
index e85fb0a..12929f4 100644
--- a/octavia_tempest_plugin/tests/test_base.py
+++ b/octavia_tempest_plugin/tests/test_base.py
@@ -128,6 +128,8 @@
cls.mem_flavor_client = cls.os_roles_lb_member.flavor_client
cls.mem_provider_client = cls.os_roles_lb_member.provider_client
cls.os_admin_servers_client = cls.os_admin.servers_client
+ cls.lb_admin_capabilities_client = (
+ cls.os_roles_lb_admin.flavor_capabilities_client)
@classmethod
def resource_setup(cls):