Adds provider API tests

This patch adds provider API tests to the Octavia tempest plugin.

Change-Id: I25685276e12dd94e866f7db5b501baaa9a38cc84
diff --git a/octavia_tempest_plugin/config.py b/octavia_tempest_plugin/config.py
index 1bc4a63..905dc9c 100644
--- a/octavia_tempest_plugin/config.py
+++ b/octavia_tempest_plugin/config.py
@@ -114,6 +114,16 @@
                help='Type of RBAC tests to run. "advanced" runs the octavia '
                     'default RBAC tests. "owner_or_admin" runs the legacy '
                     'owner or admin tests. "none" disables the RBAC tests.'),
+    cfg.DictOpt('enabled_provider_drivers',
+                help=('List of enabled provider drivers and description '
+                      'dictionaries. Must match the driver name in the '
+                      'octavia.api.drivers entrypoint. Example: '
+                      '{\'amphora\': \'The Octavia Amphora driver.\', '
+                      '\'octavia\': \'Deprecated alias of the Octavia '
+                      'Amphora driver.\'}'),
+                default={'amphora': 'The Octavia Amphora driver.',
+                         'octavia': 'Deprecated alias of the Octavia Amphora '
+                         'driver.'}),
     # Networking
     cfg.BoolOpt('test_with_ipv6',
                 default=True,
diff --git a/octavia_tempest_plugin/tests/api/v2/test_provider.py b/octavia_tempest_plugin/tests/api/v2/test_provider.py
new file mode 100644
index 0000000..917b365
--- /dev/null
+++ b/octavia_tempest_plugin/tests/api/v2/test_provider.py
@@ -0,0 +1,73 @@
+#    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 oslo_log import log as logging
+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
+LOG = logging.getLogger(__name__)
+
+
+class ProviderAPITest(test_base.LoadBalancerBaseTest):
+    """Test the provider object API."""
+
+    @decorators.idempotent_id('8b94e0cc-a24d-4c29-bc8e-53f58214dc67')
+    def test_provider_list(self):
+        """Tests provider list API and field filtering.
+
+        * Validates that non-lb member accounts cannot list the providers.
+        * List the providers and validate against the expected provider list.
+        * 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.1'):
+            raise self.skipException('Providers are only available on '
+                                     'Octavia API version 2.1 or newer.')
+
+        # Test that a user without the load balancer role cannot
+        # list providers.
+        if CONF.load_balancer.RBAC_test_type == const.ADVANCED:
+            self.assertRaises(
+                exceptions.Forbidden,
+                self.os_primary.provider_client.list_providers)
+
+        providers = self.mem_provider_client.list_providers()
+
+        # Check against the expected providers from the tempest config
+        enabled_providers = CONF.load_balancer.enabled_provider_drivers
+        for provider in providers:
+            self.assertEqual(enabled_providers[provider[const.NAME]],
+                             provider.get(const.DESCRIPTION, ''))
+
+        # Test fields
+        providers = self.mem_provider_client.list_providers(
+            query_params='{fields}={field}'.format(fields=const.FIELDS,
+                                                   field=const.NAME))
+        for provider in providers:
+            self.assertEqual(1, len(provider))
+            self.assertIn(provider[const.NAME], enabled_providers.keys())
+        providers = self.mem_provider_client.list_providers(
+            query_params='{fields}={field}'.format(fields=const.FIELDS,
+                                                   field=const.DESCRIPTION))
+        for provider in providers:
+            self.assertEqual(1, len(provider))
+            self.assertIn(provider[const.DESCRIPTION],
+                          enabled_providers.values())
diff --git a/octavia_tempest_plugin/tests/test_base.py b/octavia_tempest_plugin/tests/test_base.py
index 4ba5cae..f8acc2b 100644
--- a/octavia_tempest_plugin/tests/test_base.py
+++ b/octavia_tempest_plugin/tests/test_base.py
@@ -126,6 +126,7 @@
             cls.os_roles_lb_admin.flavor_profile_client)
         cls.lb_admin_flavor_client = cls.os_roles_lb_admin.flavor_client
         cls.mem_flavor_client = cls.os_roles_lb_member.flavor_client
+        cls.mem_provider_client = cls.os_roles_lb_member.provider_client
 
     @classmethod
     def resource_setup(cls):