Use clouds.yaml for functional test credentials

devstack emits a clouds.yaml file now, so it can be used for finding the
credentials needed to connect to the cloud for functional testing.

Depends-On: I1150b943f52f10d19f8434b27e8dde73a14d7843
Change-Id: If278565ef07de1a8fef3ff96fc3608e41f3ceea3
This commit is contained in:
Monty Taylor 2015-05-14 12:18:02 -04:00
parent 6379287480
commit 22569f218e
5 changed files with 51 additions and 45 deletions

View File

@ -94,5 +94,8 @@ There are multiple test targets that can be run to validate the code.
* 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.
Functional testing assumes the existance of a `clouds.yaml` file as supported
by `os-client-config` (http://docs.openstack.org/developer/os-client-config)
It assumes the existence of a cloud named `devstack` that behaves like a normal
devstack installation with a demo and an admin user/tenant - or clouds named
`functional_admin` and `functional_nonadmin`.

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,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import ConfigParser
import os
import fixtures
import os_client_config
import tempest_lib.cli.base
import testtools
@ -50,6 +50,11 @@ class NoFlavorException(Exception):
pass
class NoCloudConfigException(Exception):
"""We couldn't find a cloud configuration."""
pass
class ClientTestBase(testtools.TestCase):
"""
This is a first pass at a simple read only python-novaclient test. This
@ -93,30 +98,47 @@ class ClientTestBase(testtools.TestCase):
# Collecting of credentials:
#
# Support the existence of a functional_creds.conf for
# testing. This makes it possible to use a config file.
# Grab the cloud config from a user's clouds.yaml file.
# First look for a functional_admin cloud, as this is a cloud
# that the user may have defined for functional testing that has
# admin credentials.
# If that is not found, get the devstack config and override the
# username and project_name to be admin so that admin credentials
# will be used.
#
# Finally, fall back to looking for environment variables to support
# existing users running these the old way. We should deprecate that
# as tox 2.0 blanks out environment.
#
# 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.get('OS_USERNAME')
passwd = os.environ.get('OS_PASSWORD')
tenant = os.environ.get('OS_TENANT_NAME')
auth_url = os.environ.get('OS_AUTH_URL')
openstack_config = os_client_config.config.OpenStackConfig()
try:
cloud_config = openstack_config.get_one_cloud('functional_admin')
except os_client_config.exceptions.OpenStackConfigException:
try:
cloud_config = openstack_config.get_one_cloud(
'devstack', auth=dict(
username='admin', project_name='admin'))
except os_client_config.exceptions.OpenStackConfigException:
try:
cloud_config = openstack_config.get_one_cloud('envvars')
except os_client_config.exceptions.OpenStackConfigException:
cloud_config = None
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')
if cloud_config is None:
raise NoCloudConfigException(
"Cloud not find a cloud named functional_admin or a cloud"
" named devstack. Please check your clouds.yaml file and"
" try again.")
auth_info = cloud_config.config['auth']
user = auth_info['username']
passwd = auth_info['password']
tenant = auth_info['project_name']
auth_url = auth_info['auth_url']
# TODO(sdague): we made a lot of fun of the glanceclient team
# for version as int in first parameter. I guess we know where

View File

@ -30,22 +30,10 @@ 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
# ensure clouds.yaml exists
mkdir -p ~/.config/openstack
sudo cp -a ~stack/.config/openstack/clouds.yaml ~/.config/openstack
sudo chown -R jenkins:stack ~/.config/openstack
# Go to the novaclient dir
cd $NOVACLIENT_DIR

View File

@ -10,6 +10,7 @@ keyring>=2.1,!=3.3
mock>=1.0
requests-mock>=0.6.0 # Apache-2.0
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
os-client-config
oslosphinx>=2.5.0 # Apache-2.0
testrepository>=0.0.18
testscenarios>=0.4