From 38e9fa850589c336a0907ee0e7f26c56cd60b82e Mon Sep 17 00:00:00 2001
From: Paul Glass <paul.glass@rackspace.com>
Date: Wed, 24 Feb 2016 20:20:47 +0000
Subject: [PATCH] Add a service catalog override to the functional tests

This allows us to run the functional tests against environments than
what's in the service catalog.

note: ideally, this would allow us to run against a Designate in
noauth mode. And it does, however there's not a way to pass in the
X-Auth-Project-ID header, so the tests will always use the
noauth-project (tests involving multiple users like, zone transfer
tests, won't work).

Change-Id: If9306b27d78d7c774911d3c1abb46bfbf72539f1
---
 designateclient/functionaltests/client.py | 23 ++++++++++++++++++++++-
 designateclient/functionaltests/config.py |  5 +++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/designateclient/functionaltests/client.py b/designateclient/functionaltests/client.py
index 39dc970..56fa72a 100644
--- a/designateclient/functionaltests/client.py
+++ b/designateclient/functionaltests/client.py
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 """
 import logging
+import os
 
 from tempest_lib.cli import base
 
@@ -269,6 +270,10 @@ class DesignateCLI(base.CLIClient, ZoneCommands, ZoneTransferCommands,
         resp = FieldValueModel(self.keystone('token-get'))
         self.project_id = resp.tenant_id
 
+    @property
+    def using_auth_override(self):
+        return bool(cfg.CONF.identity.override_endpoint)
+
     @classmethod
     def get_clients(cls):
         if not cls._CLIENTS:
@@ -309,8 +314,24 @@ class DesignateCLI(base.CLIClient, ZoneCommands, ZoneTransferCommands,
         raise Exception("User '{0}' does not exist".format(user))
 
     def parsed_cmd(self, cmd, model=None, *args, **kwargs):
-        out = self.openstack(cmd, *args, **kwargs)
+        if self.using_auth_override:
+            # use --os-url and --os-token
+            func = self._openstack_noauth
+        else:
+            # use --os-username --os-tenant-name --os-password --os-auth-url
+            func = self.openstack
+
+        out = func(cmd, *args, **kwargs)
         LOG.debug(out)
         if model is not None:
             return model(out)
         return out
+
+    def _openstack_noauth(self, cmd, *args, **kwargs):
+        exe = os.path.join(cfg.CONF.designateclient.directory, 'openstack')
+        options = build_option_string({
+            '--os-url': cfg.CONF.identity.override_endpoint,
+            '--os-token': cfg.CONF.identity.override_token,
+        })
+        cmd = options + " " + cmd
+        return base.execute(exe, cmd, *args, **kwargs)
diff --git a/designateclient/functionaltests/config.py b/designateclient/functionaltests/config.py
index edf65d4..553f25c 100644
--- a/designateclient/functionaltests/config.py
+++ b/designateclient/functionaltests/config.py
@@ -46,6 +46,11 @@ cfg.CONF.register_opts([
     cfg.StrOpt('admin_tenant_name'),
     cfg.StrOpt('admin_password', secret=True),
     cfg.StrOpt('admin_domain_name'),
+
+    cfg.StrOpt("override_endpoint",
+               help="use this url instead of the url in the service catalog"),
+    cfg.StrOpt("override_token",
+               help="with the override endpoint, pass this token to the api"),
 ], group='identity')