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: I82c071b2cd903b9578d1f2ec515882c815812692
This commit is contained in:
Monty Taylor
2015-10-18 12:16:25 -04:00
parent 8cf2bfce3c
commit 84538d8870
5 changed files with 24 additions and 52 deletions

View File

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

View File

@@ -10,12 +10,28 @@
# License for the specific language governing permissions and limitations
# under the License.
import ConfigParser
import os
import os_client_config
from tempest_lib.cli import base
def credentials(cloud='devstack-admin'):
"""Retrieves credentials to run functional tests
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.
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 os_client_config.OpenStackConfig().get_one_cloud(cloud=cloud)
class ClientTestBase(base.ClientTestBase):
"""This is a first pass at a simple read only python-glanceclient test.
@@ -28,37 +44,17 @@ class ClientTestBase(base.ClientTestBase):
"""
def __init__(self, *args, **kwargs):
super(ClientTestBase, self).__init__(*args, **kwargs)
# Collecting of credentials:
#
# Support the existence of a functional_creds.conf for
# testing. This makes it possible to use a config file.
self.username = os.environ.get('OS_USERNAME')
self.password = os.environ.get('OS_PASSWORD')
self.tenant_name = os.environ.get('OS_TENANT_NAME')
self.uri = 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
self.username = self.username or config.get('admin', 'user')
self.password = self.password or config.get('admin', 'pass')
self.tenant_name = self.tenant_name or config.get('admin',
'tenant')
self.uri = self.uri or config.get('auth', 'uri')
def _get_clients(self):
self.creds = credentials().get_auth_args()
cli_dir = os.environ.get(
'OS_GLANCECLIENT_EXEC_DIR',
os.path.join(os.path.abspath('.'), '.tox/functional/bin'))
return base.CLIClient(
username=self.username,
password=self.password,
tenant_name=self.tenant_name,
uri=self.uri,
username=self.creds['username'],
password=self.creds['password'],
tenant_name=self.creds['project_name'],
uri=self.creds['auth_url'],
cli_dir=cli_dir)
def glance(self, *args, **kwargs):

View File

@@ -30,23 +30,6 @@ export GLANCECLIENT_DIR="$BASE/new/python-glanceclient"
sudo chown -R jenkins:stack $GLANCECLIENT_DIR
# Get admin credentials
cd $BASE/new/devstack
source openrc admin admin
# pass the appropriate variables via a config file
CREDS_FILE=$GLANCECLIENT_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 glanceclient dir
cd $GLANCECLIENT_DIR

View File

@@ -42,7 +42,7 @@ class SimpleReadOnlyGlanceClientTest(base.ClientTestBase):
'this-does-not-exist')
def test_member_list_v1(self):
tenant_name = '--tenant-id %s' % self.tenant_name
tenant_name = '--tenant-id %s' % self.creds['project_name']
out = self.glance('--os-image-api-version 1 member-list',
params=tenant_name)
endpoints = self.parser.listing(out)

View File

@@ -6,6 +6,7 @@ hacking<0.11,>=0.10.0
coverage>=3.6
discover
mock>=1.2
os-client-config>=1.4.0,!=1.6.2
oslosphinx>=2.5.0 # Apache-2.0
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
testrepository>=0.0.18