Use clouds.yaml from devstack for functional tests
devstack produces a file called clouds.yaml already with credentials in it. Rather than producing our own config file to run functional tests, just consume the clouds.yaml file that's already there. Closes-Bug: #1507386 Change-Id: Ie15b5da2e61f5b35e3bdeb75f0ba21c58ddfca76
This commit is contained in:
parent
72a2d1f622
commit
51b2e71add
|
@ -1,8 +0,0 @@
|
|||
# Credentials for functional testing
|
||||
[auth]
|
||||
uri = http://10.42.0.50:5000/v2.0
|
||||
|
||||
[admin]
|
||||
user = admin
|
||||
tenant = admin
|
||||
pass = secrete
|
|
@ -12,66 +12,53 @@
|
|||
|
||||
import os
|
||||
|
||||
from six.moves import configparser
|
||||
import os_client_config
|
||||
from tempest_lib.cli import base
|
||||
|
||||
|
||||
_CREDS_FILE = 'functional_creds.conf'
|
||||
|
||||
|
||||
def credentials():
|
||||
def credentials(cloud='devstack-admin'):
|
||||
"""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.
|
||||
Credentials are either read via os-client-config from the environment
|
||||
or from a config file ('clouds.yaml'). 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).
|
||||
devstack produces a clouds.yaml with two named clouds - one named
|
||||
'devstack' which has user privs and one named 'devstack-admin' which
|
||||
has admin privs. This function will default to getting the devstack-admin
|
||||
cloud as that is the current expected behavior.
|
||||
"""
|
||||
return get_cloud_config(cloud=cloud).get_auth_args()
|
||||
|
||||
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
|
||||
}
|
||||
def get_cloud_config(cloud='devstack-admin'):
|
||||
return os_client_config.OpenStackConfig().get_one_cloud(cloud=cloud)
|
||||
|
||||
|
||||
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.
|
||||
|
||||
This only exercises client commands that are read only.
|
||||
This should test commands:
|
||||
* as a regular user
|
||||
* as a admin user
|
||||
* as an admin user
|
||||
* with and without optional parameters
|
||||
* initially just check return codes, and later test command outputs
|
||||
|
||||
"""
|
||||
|
||||
def _get_clients(self):
|
||||
creds = credentials()
|
||||
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=creds['username'],
|
||||
password=creds['password'],
|
||||
tenant_name=creds['tenant_name'],
|
||||
uri=creds['auth_url'],
|
||||
cli_dir=cli_dir)
|
||||
|
||||
return base.CLIClient(
|
||||
username=self.creds['username'],
|
||||
password=self.creds['password'],
|
||||
tenant_name=self.creds['project_name'],
|
||||
uri=self.creds['auth_url'],
|
||||
cli_dir=cli_dir)
|
||||
|
||||
def neutron(self, *args, **kwargs):
|
||||
return self.clients.neutron(*args,
|
||||
|
|
|
@ -39,17 +39,22 @@ class Libv2HTTPClientTestBase(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=creds['auth_url'])
|
||||
# At the moment, we use keystone v2 API
|
||||
v2_auth_url = ks_discover.url_for('2.0')
|
||||
return v2_client.Client(username=creds['username'],
|
||||
password=creds['password'],
|
||||
tenant_name=creds['tenant_name'],
|
||||
auth_url=creds['auth_url'])
|
||||
tenant_name=creds['project_name'],
|
||||
auth_url=v2_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,
|
||||
|
@ -60,7 +65,7 @@ class Libv2SessionClientTestBase(LibraryTestBase):
|
|||
v2_auth_url,
|
||||
username=creds['username'],
|
||||
password=creds['password'],
|
||||
tenant_name=creds['tenant_name'])
|
||||
tenant_name=creds['project_name'])
|
||||
return v2_client.Client(session=ks_session)
|
||||
|
||||
|
||||
|
|
|
@ -52,23 +52,6 @@ owner=jenkins
|
|||
|
||||
sudo chown -R $owner: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
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ discover
|
|||
fixtures>=1.3.1
|
||||
mox3>=0.7.0
|
||||
mock>=1.2
|
||||
os-client-config>=1.4.0,!=1.6.2
|
||||
oslosphinx>=2.5.0 # Apache-2.0
|
||||
oslotest>=1.10.0 # Apache-2.0
|
||||
python-subunit>=0.0.18
|
||||
|
|
Loading…
Reference in New Issue