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
This commit is contained in:
Sean Dague 2015-05-14 07:06:05 -04:00
parent 0e35f2a2fa
commit 6379287480
4 changed files with 63 additions and 10 deletions

View File

@ -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.

View File

@ -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

View File

@ -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):

View File

@ -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