From 9712370357365edd467b6701e6a7817363340647 Mon Sep 17 00:00:00 2001
From: Dane LeBlanc <leblancd@cisco.com>
Date: Thu, 14 Apr 2016 15:49:50 -0400
Subject: [PATCH] Functional tests should support DNS nameserver config

The Magnum functional tests currently use a DNS server setting of
8.8.8.8 when configuring nodes in a cluster. In some environments,
this DNS server setting doesn't work. When this is the case, and
functional tests are run locally, bay creation times out and the
functional tests fail.

This patch enhances the functional tests to allow configuration of
DNS nameserver to be used in baymodels that are created in
functional tests.

Change-Id: I958d199565ae5741dd6f4b8764e51ea16a8d505b
Closes-Bug: #1570543
---
 doc/source/dev/functional-test.rst                        | 6 ++++++
 magnum/tests/contrib/post_test_hook.sh                    | 1 +
 magnum/tests/functional/common/config.py                  | 7 +++++++
 magnum/tests/functional/common/datagen.py                 | 2 +-
 magnum/tests/functional/python_client_base.py             | 5 +++++
 magnum/tests/functional/swarm/test_swarm_python_client.py | 1 -
 magnum/tests/functional/tempest_tests/config.py           | 4 ++++
 7 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/doc/source/dev/functional-test.rst b/doc/source/dev/functional-test.rst
index 76f2fcf23c..7e7725d74e 100644
--- a/doc/source/dev/functional-test.rst
+++ b/doc/source/dev/functional-test.rst
@@ -39,6 +39,12 @@ If you're using devstack, you can copy and modify the devstack configuration::
     source /opt/stack/devstack/openrc demo demo
     iniset functional_creds.conf auth password $OS_PASSWORD
 
+Set the DNS name server to be used in your bay nodes (e.g. 8.8.8.8)::
+
+    # update DNS name server
+    source /opt/stack/devstack/openrc demo demo
+    iniset functional_creds.conf magnum dns_nameserver <dns-svr-ip-address>
+
 Create the necessary keypair and flavor::
 
     source /opt/stack/devstack/openrc admin admin
diff --git a/magnum/tests/contrib/post_test_hook.sh b/magnum/tests/contrib/post_test_hook.sh
index f20f45c4ba..039f8b7f03 100755
--- a/magnum/tests/contrib/post_test_hook.sh
+++ b/magnum/tests/contrib/post_test_hook.sh
@@ -67,6 +67,7 @@ flavor_id = s1.magnum
 master_flavor_id = m1.magnum
 copy_logs = true
 csr_location = $MAGNUM_DIR/default.csr
+dns_nameserver = 8.8.8.8
 EOF
 
     # Note(eliqiao): Let's keep this only for debugging on gate.
diff --git a/magnum/tests/functional/common/config.py b/magnum/tests/functional/common/config.py
index 539c6bf8fc..fbafa7d6d2 100644
--- a/magnum/tests/functional/common/config.py
+++ b/magnum/tests/functional/common/config.py
@@ -103,6 +103,12 @@ class Config(object):
             raise Exception('config missing csr_location key')
         cls.csr_location = CONF.magnum.csr_location
 
+    @classmethod
+    def set_dns_nameserver(cls, config):
+        if 'dns_nameserver' not in CONF.magnum:
+            raise Exception('config missing dns_nameserver')
+        cls.dns_nameserver = CONF.magnum.dns_nameserver
+
     @classmethod
     def set_copy_logs(cls, config):
         if 'copy_logs' not in CONF.magnum:
@@ -125,4 +131,5 @@ class Config(object):
         cls.set_magnum_url(config)
         cls.set_master_flavor_id(config)
         cls.set_csr_location(config)
+        cls.set_dns_nameserver(config)
         cls.set_copy_logs(config)
diff --git a/magnum/tests/functional/common/datagen.py b/magnum/tests/functional/common/datagen.py
index f8506e8a15..8eb3f2a821 100644
--- a/magnum/tests/functional/common/datagen.py
+++ b/magnum/tests/functional/common/datagen.py
@@ -203,7 +203,7 @@ def valid_swarm_baymodel():
     return baymodel_data(image_id=config.Config.image_id,
                          fixed_network="192.168.0.0/24",
                          flavor_id=config.Config.flavor_id, public=False,
-                         dns_nameserver="8.8.8.8",
+                         dns_nameserver=config.Config.dns_nameserver,
                          master_flavor_id=config.Config.master_flavor_id,
                          keypair_id=config.Config.keypair_id, coe="swarm",
                          docker_volume_size=3, cluster_distro=None,
diff --git a/magnum/tests/functional/python_client_base.py b/magnum/tests/functional/python_client_base.py
index 06087f648b..df2164f94f 100644
--- a/magnum/tests/functional/python_client_base.py
+++ b/magnum/tests/functional/python_client_base.py
@@ -54,6 +54,7 @@ class BaseMagnumClient(base.BaseMagnumTest):
         flavor_id = cliutils.env('FLAVOR_ID')
         master_flavor_id = cliutils.env('MASTER_FLAVOR_ID')
         keypair_id = cliutils.env('KEYPAIR_ID')
+        dns_nameserver = cliutils.env('DNS_NAMESERVER')
         copy_logs = cliutils.env('COPY_LOGS')
 
         config = configparser.RawConfigParser()
@@ -71,6 +72,8 @@ class BaseMagnumClient(base.BaseMagnumTest):
             master_flavor_id = master_flavor_id or config.get(
                 'magnum', 'master_flavor_id')
             keypair_id = keypair_id or config.get('magnum', 'keypair_id')
+            dns_nameserver = dns_nameserver or config.get(
+                'magnum', 'dns_nameserver')
             try:
                 copy_logs = copy_logs or config.get('magnum', 'copy_logs')
             except configparser.NoOptionError:
@@ -81,6 +84,7 @@ class BaseMagnumClient(base.BaseMagnumTest):
         cls.flavor_id = flavor_id
         cls.master_flavor_id = master_flavor_id
         cls.keypair_id = keypair_id
+        cls.dns_nameserver = dns_nameserver
         cls.copy_logs = bool(copy_logs)
         cls.cs = v1client.Client(username=user,
                                  api_key=passwd,
@@ -132,6 +136,7 @@ class BaseMagnumClient(base.BaseMagnumTest):
             docker_volume_size=docker_volume_size,
             network_driver=network_driver,
             volume_driver=volume_driver,
+            dns_nameserver=cls.dns_nameserver,
             coe=coe,
             labels=labels,
             tls_disabled=tls_disabled,
diff --git a/magnum/tests/functional/swarm/test_swarm_python_client.py b/magnum/tests/functional/swarm/test_swarm_python_client.py
index 0176b4688f..bc111351ef 100644
--- a/magnum/tests/functional/swarm/test_swarm_python_client.py
+++ b/magnum/tests/functional/swarm/test_swarm_python_client.py
@@ -39,7 +39,6 @@ class TestSwarmAPIs(BayTest):
         "network_driver": None,
         "volume_driver": None,
         "fixed_network": '192.168.0.0/24',
-        "dns_nameserver": '8.8.8.8',
         "labels": {}
     }
 
diff --git a/magnum/tests/functional/tempest_tests/config.py b/magnum/tests/functional/tempest_tests/config.py
index d38ce185d0..bb29a4be25 100644
--- a/magnum/tests/functional/tempest_tests/config.py
+++ b/magnum/tests/functional/tempest_tests/config.py
@@ -56,6 +56,10 @@ MagnumGroup = [
                default="/opt/stack/new/magnum/default.csr",
                help="CSR location for certificates."),
 
+    cfg.StrOpt("dns_nameserver",
+               default="8.8.8.8",
+               help="DNS nameserver to use for baymodels."),
+
     cfg.StrOpt("copy_logs",
                default=True,
                help="Specify whether to copy nova server logs on failure."),