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:
8
functional_creds.conf.sample
Normal file
8
functional_creds.conf.sample
Normal 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
|
@@ -12,9 +12,44 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from six.moves import configparser
|
||||||
from tempest_lib.cli import base
|
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):
|
class ClientTestBase(base.ClientTestBase):
|
||||||
"""This is a first pass at a simple read only python-neutronclient test.
|
"""This is a first pass at a simple read only python-neutronclient test.
|
||||||
This only exercises client commands that are read only.
|
This only exercises client commands that are read only.
|
||||||
@@ -28,15 +63,14 @@ class ClientTestBase(base.ClientTestBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_clients(self):
|
def _get_clients(self):
|
||||||
|
creds = credentials()
|
||||||
cli_dir = os.environ.get(
|
cli_dir = os.environ.get(
|
||||||
'OS_NEUTRONCLIENT_EXEC_DIR',
|
'OS_NEUTRONCLIENT_EXEC_DIR',
|
||||||
os.path.join(os.path.abspath('.'), '.tox/functional/bin'))
|
os.path.join(os.path.abspath('.'), '.tox/functional/bin'))
|
||||||
|
return base.CLIClient(username=creds['username'],
|
||||||
return base.CLIClient(
|
password=creds['password'],
|
||||||
username=os.environ.get('OS_USERNAME'),
|
tenant_name=creds['tenant_name'],
|
||||||
password=os.environ.get('OS_PASSWORD'),
|
uri=creds['auth_url'],
|
||||||
tenant_name=os.environ.get('OS_TENANT_NAME'),
|
|
||||||
uri=os.environ.get('OS_AUTH_URL'),
|
|
||||||
cli_dir=cli_dir)
|
cli_dir=cli_dir)
|
||||||
|
|
||||||
def neutron(self, *args, **kwargs):
|
def neutron(self, *args, **kwargs):
|
||||||
|
@@ -28,15 +28,28 @@ function generate_testr_results {
|
|||||||
|
|
||||||
export NEUTRONCLIENT_DIR="$BASE/new/python-neutronclient"
|
export NEUTRONCLIENT_DIR="$BASE/new/python-neutronclient"
|
||||||
|
|
||||||
|
sudo chown -R jenkins:stack $NEUTRONCLIENT_DIR
|
||||||
|
|
||||||
# Get admin credentials
|
# Get admin credentials
|
||||||
cd $BASE/new/devstack
|
cd $BASE/new/devstack
|
||||||
source openrc admin admin
|
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
|
# Go to the neutronclient dir
|
||||||
cd $NEUTRONCLIENT_DIR
|
cd $NEUTRONCLIENT_DIR
|
||||||
|
|
||||||
sudo chown -R jenkins:stack $NEUTRONCLIENT_DIR
|
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
echo "Running neutronclient functional test suite"
|
echo "Running neutronclient functional test suite"
|
||||||
set +e
|
set +e
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from keystoneclient.auth.identity import v2 as v2_auth
|
from keystoneclient.auth.identity import v2 as v2_auth
|
||||||
@@ -20,6 +19,7 @@ from tempest_lib import base
|
|||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from neutronclient.common import exceptions
|
from neutronclient.common import exceptions
|
||||||
|
from neutronclient.tests.functional import base as func_base
|
||||||
from neutronclient.v2_0 import client as v2_client
|
from neutronclient.v2_0 import client as v2_client
|
||||||
|
|
||||||
# This module tests client library functionalities with
|
# This module tests client library functionalities with
|
||||||
@@ -38,26 +38,29 @@ class LibraryTestBase(base.BaseTestCase):
|
|||||||
class Libv2HTTPClientTestBase(LibraryTestBase):
|
class Libv2HTTPClientTestBase(LibraryTestBase):
|
||||||
|
|
||||||
def _get_client(self):
|
def _get_client(self):
|
||||||
return v2_client.Client(username=os.environ.get('OS_USERNAME'),
|
creds = func_base.credentials()
|
||||||
password=os.environ.get('OS_PASSWORD'),
|
return v2_client.Client(username=creds['username'],
|
||||||
tenant_name=os.environ.get('OS_TENANT_NAME'),
|
password=creds['password'],
|
||||||
auth_url=os.environ.get('OS_AUTH_URL'))
|
tenant_name=creds['tenant_name'],
|
||||||
|
auth_url=creds['auth_url'])
|
||||||
|
|
||||||
|
|
||||||
class Libv2SessionClientTestBase(LibraryTestBase):
|
class Libv2SessionClientTestBase(LibraryTestBase):
|
||||||
|
|
||||||
def _get_client(self):
|
def _get_client(self):
|
||||||
|
creds = func_base.credentials()
|
||||||
|
|
||||||
session_params = {}
|
session_params = {}
|
||||||
ks_session = session.Session.construct(session_params)
|
ks_session = session.Session.construct(session_params)
|
||||||
ks_discover = discover.Discover(session=ks_session,
|
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
|
# At the moment, we use keystone v2 API
|
||||||
v2_auth_url = ks_discover.url_for('2.0')
|
v2_auth_url = ks_discover.url_for('2.0')
|
||||||
ks_session.auth = v2_auth.Password(
|
ks_session.auth = v2_auth.Password(
|
||||||
v2_auth_url,
|
v2_auth_url,
|
||||||
username=os.environ.get('OS_USERNAME'),
|
username=creds['username'],
|
||||||
password=os.environ.get('OS_PASSWORD'),
|
password=creds['password'],
|
||||||
tenant_name=os.environ.get('OS_TENANT_NAME'))
|
tenant_name=creds['tenant_name'])
|
||||||
return v2_client.Client(session=ks_session)
|
return v2_client.Client(session=ks_session)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user