summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2015-05-14 07:06:05 -0400
committerSean Dague <sean@dague.net>2015-05-14 10:48:01 -0400
commit6379287480bf6bc0a8f80bc93f01005a31882aec (patch)
tree247067c738811458e74d835713a01c521ee42010
parent0e35f2a2fabe5beae065cc92c44f653ff76e6558 (diff)
downloadpython-novaclient-6379287480bf6bc0a8f80bc93f01005a31882aec.tar.gz
pass credentials via config file instead of magic
Passing credentials via an assumed environment inheritance is bad form, and breaks under new tox. Honestly, we only really need 2 vars passed in, so we might as well make it a config file that we'll parse. Add a functional_creds.conf.sample for people to know what one should look like. Update README to explain it. Related-Bug: #1455102 Change-Id: Ifdab38a03c94f51d30449149c0dbd9c6265460a5
-rw-r--r--README.rst13
-rw-r--r--functional_creds.conf.sample8
-rw-r--r--novaclient/tests/functional/base.py35
-rwxr-xr-xnovaclient/tests/functional/hooks/post_test_hook.sh17
4 files changed, 63 insertions, 10 deletions
diff --git a/README.rst b/README.rst
index 84bf9c17..edf26ec6 100644
--- a/README.rst
+++ b/README.rst
@@ -83,3 +83,16 @@ To use with nova, with keystone as the authentication system::
* Documentation: http://docs.openstack.org/developer/python-novaclient
* Source: http://git.openstack.org/cgit/openstack/python-novaclient
* Bugs: http://bugs.launchpad.net/python-novaclient
+
+Testing
+-------
+
+There are multiple test targets that can be run to validate the code.
+
+* tox -e pep8 - style guidelines enforcement
+* tox -e py27 - traditional unit testing
+* tox -e functional - live functional testing against an existing
+ openstack
+
+Functional testing assumes the existance of a functional_creds.conf in
+the root directory. See the .sample for example format.
diff --git a/functional_creds.conf.sample b/functional_creds.conf.sample
new file mode 100644
index 00000000..081a7368
--- /dev/null
+++ b/functional_creds.conf.sample
@@ -0,0 +1,8 @@
+# Credentials for functional testing
+[auth]
+uri = http://10.42.0.50:5000/v2.0
+
+[admin]
+user = admin
+tenant = admin
+pass = secrete
diff --git a/novaclient/tests/functional/base.py b/novaclient/tests/functional/base.py
index 2ccdbf44..ac795325 100644
--- a/novaclient/tests/functional/base.py
+++ b/novaclient/tests/functional/base.py
@@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import ConfigParser
import os
import fixtures
@@ -90,14 +91,32 @@ class ClientTestBase(testtools.TestCase):
format=self.log_format,
level=None))
+ # Collecting of credentials:
+ #
+ # Support the existence of a functional_creds.conf for
+ # testing. This makes it possible to use a config file.
+ #
+ # Those variables can be overridden by environmental variables
+ # as well to support existing users running these the old
+ # way. We should deprecate that.
+
# TODO(sdague): while we collect this information in
# tempest-lib, we do it in a way that's not available for top
# level tests. Long term this probably needs to be in the base
# class.
- user = os.environ['OS_USERNAME']
- passwd = os.environ['OS_PASSWORD']
- tenant = os.environ['OS_TENANT_NAME']
- auth_url = os.environ['OS_AUTH_URL']
+ user = os.environ.get('OS_USERNAME')
+ passwd = os.environ.get('OS_PASSWORD')
+ tenant = os.environ.get('OS_TENANT_NAME')
+ auth_url = os.environ.get('OS_AUTH_URL')
+
+ config = ConfigParser.RawConfigParser()
+ if config.read('functional_creds.conf'):
+ # the OR pattern means the environment is preferred for
+ # override
+ user = user or config.get('admin', 'user')
+ passwd = passwd or config.get('admin', 'pass')
+ tenant = tenant or config.get('admin', 'tenant')
+ auth_url = auth_url or config.get('auth', 'uri')
# TODO(sdague): we made a lot of fun of the glanceclient team
# for version as int in first parameter. I guess we know where
@@ -120,10 +139,10 @@ class ClientTestBase(testtools.TestCase):
os.path.join(os.path.abspath('.'), '.tox/functional/bin'))
self.cli_clients = tempest_lib.cli.base.CLIClient(
- username=os.environ.get('OS_USERNAME'),
- password=os.environ.get('OS_PASSWORD'),
- tenant_name=os.environ.get('OS_TENANT_NAME'),
- uri=os.environ.get('OS_AUTH_URL'),
+ username=user,
+ password=passwd,
+ tenant_name=tenant,
+ uri=auth_url,
cli_dir=cli_dir)
def nova(self, *args, **kwargs):
diff --git a/novaclient/tests/functional/hooks/post_test_hook.sh b/novaclient/tests/functional/hooks/post_test_hook.sh
index e9e35b24..5878ace9 100755
--- a/novaclient/tests/functional/hooks/post_test_hook.sh
+++ b/novaclient/tests/functional/hooks/post_test_hook.sh
@@ -28,15 +28,28 @@ function generate_testr_results {
export NOVACLIENT_DIR="$BASE/new/python-novaclient"
+sudo chown -R jenkins:stack $NOVACLIENT_DIR
+
# Get admin credentials
cd $BASE/new/devstack
source openrc admin admin
+# pass the appropriate variables via a config file
+CREDS_FILE=$NOVACLIENT_DIR/functional_creds.conf
+cat <<EOF > $CREDS_FILE
+# Credentials for functional testing
+[auth]
+uri = $OS_AUTH_URL
+
+[admin]
+user = $OS_USERNAME
+tenant = $OS_TENANT_NAME
+pass = $OS_PASSWORD
+
+EOF
# Go to the novaclient dir
cd $NOVACLIENT_DIR
-sudo chown -R jenkins:stack $NOVACLIENT_DIR
-
# Run tests
echo "Running novaclient functional test suite"
set +e