From 960e4441b80dd1e5d25858b785e463fe42e53048 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 14 May 2015 20:14:08 -0700 Subject: [PATCH] Add class to deal with clouds.yaml support For running functional tests on devstack nodes, it's important to be able to get the appropriate credentials. Use the clouds.yaml that is newly written by devstack and os-client-config to pull a few well defined sets of credentials. Change-Id: Ibd2d473fce878424e8a6d1c76e81088e575e619b --- oslotest/functional.py | 59 ++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 60 insertions(+) create mode 100644 oslotest/functional.py diff --git a/oslotest/functional.py b/oslotest/functional.py new file mode 100644 index 0000000..32448a6 --- /dev/null +++ b/oslotest/functional.py @@ -0,0 +1,59 @@ +# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os_client_config + + +def _get_openstack_auth(openstack_config, cloud_name, override_name): + try: + cloud_config = openstack_config.get_one_cloud(cloud_name) + except os_client_config.exceptions.OpenStackConfigException: + try: + cloud_config = openstack_config.get_one_cloud( + 'devstack', auth=dict( + username=override_name, project_name=override_name)) + except os_client_config.exceptions.OpenStackConfigException: + try: + cloud_config = openstack_config.get_one_cloud('envvars') + except os_client_config.exceptions.OpenStackConfigException: + cloud_config = None + return cloud_config + + +class FunctionalAuth(object): + + def __init__(self): + # Collecting of credentials: + # + # 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. + openstack_config = os_client_config.config.OpenStackConfig() + self._cloud_config = {} + self._cloud_config['admin'] = _get_openstack_auth( + openstack_config, 'functional_admin', 'admin') + self._cloud_config['user'] = _get_openstack_auth( + openstack_config, 'functional_user', 'demo') + + def get_auth_info(self, name): + return self._cloud_config[name].config['auth'] diff --git a/requirements.txt b/requirements.txt index 16332e2..37c3012 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ testscenarios>=0.4 testtools>=0.9.36,!=1.2.0 mock>=1.0 mox3>=0.7.0 +os-client-config