diff --git a/functional_creds.conf.sample b/functional_creds.conf.sample deleted file mode 100644 index 081a7368..00000000 --- a/functional_creds.conf.sample +++ /dev/null @@ -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 diff --git a/glanceclient/tests/functional/base.py b/glanceclient/tests/functional/base.py index 9488595a..6029a06e 100644 --- a/glanceclient/tests/functional/base.py +++ b/glanceclient/tests/functional/base.py @@ -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): diff --git a/glanceclient/tests/functional/hooks/post_test_hook.sh b/glanceclient/tests/functional/hooks/post_test_hook.sh index 02aa2f1a..e0c2de08 100755 --- a/glanceclient/tests/functional/hooks/post_test_hook.sh +++ b/glanceclient/tests/functional/hooks/post_test_hook.sh @@ -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 < $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 diff --git a/glanceclient/tests/functional/test_readonly_glance.py b/glanceclient/tests/functional/test_readonly_glance.py index 93029275..72ded1f8 100644 --- a/glanceclient/tests/functional/test_readonly_glance.py +++ b/glanceclient/tests/functional/test_readonly_glance.py @@ -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) diff --git a/test-requirements.txt b/test-requirements.txt index 57221066..9af0f2aa 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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