Fix functional tests and tox 2.0 errors

With the recent update to tox 2.0.x, environment variables such as
OS_AUTH_URL are not passed by default, resulting in tests errors
mentionning Keystone authentication failures.

This patch reads credentials from the 'functional_creds.conf' config
file, like it is done in novaclient, glanceclient, manilaclient and
soon in cinderclient.

Reading credentials the old way (the environment) is still possible.

Change-Id: Ief0f050044ecd90a14bbaf044e2b93ade0a6173f
Closes-Bug: #1455102
This commit is contained in:
Adrien Vergé 2015-05-16 17:58:27 +02:00
parent da39d9e0a8
commit 7eb3241650
4 changed files with 76 additions and 18 deletions

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

@ -12,9 +12,44 @@
import os
from six.moves import configparser
from tempest_lib.cli import base
_CREDS_FILE = 'functional_creds.conf'
def credentials():
"""Retrieves credentials to run functional tests
Credentials are either read from the environment or from a config file
('functional_creds.conf'). Environment variables override those from the
config file.
The 'functional_creds.conf' file is the clean and new way to use (by
default tox 2.0 does not pass environment variables).
"""
username = os.environ.get('OS_USERNAME')
password = os.environ.get('OS_PASSWORD')
tenant_name = os.environ.get('OS_TENANT_NAME')
auth_url = os.environ.get('OS_AUTH_URL')
config = configparser.RawConfigParser()
if config.read(_CREDS_FILE):
username = username or config.get('admin', 'user')
password = password or config.get('admin', 'pass')
tenant_name = tenant_name or config.get('admin', 'tenant')
auth_url = auth_url or config.get('auth', 'uri')
return {
'username': username,
'password': password,
'tenant_name': tenant_name,
'auth_url': auth_url
}
class ClientTestBase(base.ClientTestBase):
"""This is a first pass at a simple read only python-neutronclient test.
This only exercises client commands that are read only.
@ -28,16 +63,15 @@ class ClientTestBase(base.ClientTestBase):
"""
def _get_clients(self):
creds = credentials()
cli_dir = os.environ.get(
'OS_NEUTRONCLIENT_EXEC_DIR',
os.path.join(os.path.abspath('.'), '.tox/functional/bin'))
return 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'),
cli_dir=cli_dir)
return base.CLIClient(username=creds['username'],
password=creds['password'],
tenant_name=creds['tenant_name'],
uri=creds['auth_url'],
cli_dir=cli_dir)
def neutron(self, *args, **kwargs):
return self.clients.neutron(*args,

View File

@ -28,15 +28,28 @@ function generate_testr_results {
export NEUTRONCLIENT_DIR="$BASE/new/python-neutronclient"
sudo chown -R jenkins:stack $NEUTRONCLIENT_DIR
# Get admin credentials
cd $BASE/new/devstack
source openrc admin admin
# Store these credentials into the config file
CREDS_FILE=$NEUTRONCLIENT_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 neutronclient dir
cd $NEUTRONCLIENT_DIR
sudo chown -R jenkins:stack $NEUTRONCLIENT_DIR
# Run tests
echo "Running neutronclient functional test suite"
set +e

View File

@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import uuid
from keystoneclient.auth.identity import v2 as v2_auth
@ -20,6 +19,7 @@ from tempest_lib import base
import testtools
from neutronclient.common import exceptions
from neutronclient.tests.functional import base as func_base
from neutronclient.v2_0 import client as v2_client
# This module tests client library functionalities with
@ -38,26 +38,29 @@ class LibraryTestBase(base.BaseTestCase):
class Libv2HTTPClientTestBase(LibraryTestBase):
def _get_client(self):
return v2_client.Client(username=os.environ.get('OS_USERNAME'),
password=os.environ.get('OS_PASSWORD'),
tenant_name=os.environ.get('OS_TENANT_NAME'),
auth_url=os.environ.get('OS_AUTH_URL'))
creds = func_base.credentials()
return v2_client.Client(username=creds['username'],
password=creds['password'],
tenant_name=creds['tenant_name'],
auth_url=creds['auth_url'])
class Libv2SessionClientTestBase(LibraryTestBase):
def _get_client(self):
creds = func_base.credentials()
session_params = {}
ks_session = session.Session.construct(session_params)
ks_discover = discover.Discover(session=ks_session,
auth_url=os.environ.get('OS_AUTH_URL'))
auth_url=creds['auth_url'])
# At the moment, we use keystone v2 API
v2_auth_url = ks_discover.url_for('2.0')
ks_session.auth = v2_auth.Password(
v2_auth_url,
username=os.environ.get('OS_USERNAME'),
password=os.environ.get('OS_PASSWORD'),
tenant_name=os.environ.get('OS_TENANT_NAME'))
username=creds['username'],
password=creds['password'],
tenant_name=creds['tenant_name'])
return v2_client.Client(session=ks_session)