summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--os_client_config/config.py8
-rw-r--r--os_client_config/tests/test_config.py97
-rw-r--r--test-requirements.txt2
-rw-r--r--tox.ini4
4 files changed, 107 insertions, 4 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 83ec6c4..6bc84e2 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -209,7 +209,7 @@ class OpenStackConfig(object):
os_args = dict()
new_args = dict()
- for (key, val) in args.iteritems():
+ for (key, val) in iter(args.items()):
key = key.replace('-', '_')
if key.startswith('os'):
os_args[key[3:]] = val
@@ -297,7 +297,7 @@ class OpenStackConfig(object):
config['auth'] = dict()
# Can't just do update, because None values take over
- for (key, val) in args.iteritems():
+ for (key, val) in iter(args.items()):
if val is not None:
config[key] = val
@@ -306,6 +306,10 @@ class OpenStackConfig(object):
if type(config[key]) is not bool:
config[key] = get_boolean(config[key])
+ if 'auth_plugin' in config:
+ if config['auth_plugin'] in ('', 'None', None):
+ validate = False
+
if validate and ksc_auth:
config = self._validate_auth(config)
diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py
new file mode 100644
index 0000000..b19899a
--- /dev/null
+++ b/os_client_config/tests/test_config.py
@@ -0,0 +1,97 @@
+# Copyright (c) 2014 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 tempfile
+
+import extras
+import fixtures
+import testtools
+import yaml
+
+from os_client_config import cloud_config
+from os_client_config import config
+
+VENDOR_CONF = {
+ 'public-clouds': {
+ '_test_cloud_in_our_cloud': {
+ 'auth': {
+ 'username': 'testotheruser',
+ 'project_name': 'testproject',
+ },
+ },
+ }
+}
+USER_CONF = {
+ 'clouds': {
+ '_test_cloud_': {
+ 'cloud': '_test_cloud_in_our_cloud',
+ 'auth': {
+ 'username': 'testuser',
+ 'password': 'testpass',
+ },
+ 'region_name': 'test-region',
+ },
+ '_test_cloud_no_vendor': {
+ 'cloud': '_test_non_existant_cloud',
+ 'auth': {
+ 'username': 'testuser',
+ 'password': 'testpass',
+ 'project_name': 'testproject',
+ },
+ 'region_name': 'test-region',
+ },
+ },
+ 'cache': {'max_age': 1},
+}
+
+
+def _write_yaml(obj):
+ # Assume NestedTempfile so we don't have to cleanup
+ with tempfile.NamedTemporaryFile(delete=False) as obj_yaml:
+ obj_yaml.write(yaml.safe_dump(obj).encode('utf-8'))
+ return obj_yaml.name
+
+
+class TestConfig(testtools.TestCase):
+ def test_get_one_cloud(self):
+ c = config.OpenStackConfig()
+ self.assertIsInstance(c.get_one_cloud(), cloud_config.CloudConfig)
+
+ def test_get_one_cloud_with_config_files(self):
+ self.useFixture(fixtures.NestedTempfile())
+ conf = dict(USER_CONF)
+ tdir = self.useFixture(fixtures.TempDir())
+ conf['cache']['path'] = tdir.path
+ cloud_yaml = _write_yaml(conf)
+ vendor_yaml = _write_yaml(VENDOR_CONF)
+ c = config.OpenStackConfig(config_files=[cloud_yaml],
+ vendor_files=[vendor_yaml])
+ self.assertIsInstance(c.cloud_config, dict)
+ self.assertIn('cache', c.cloud_config)
+ self.assertIsInstance(c.cloud_config['cache'], dict)
+ self.assertIn('max_age', c.cloud_config['cache'])
+ self.assertIn('path', c.cloud_config['cache'])
+ cc = c.get_one_cloud('_test_cloud_')
+ self._assert_cloud_details(cc)
+ cc = c.get_one_cloud('_test_cloud_no_vendor')
+ self._assert_cloud_details(cc)
+
+ def _assert_cloud_details(self, cc):
+ self.assertIsInstance(cc, cloud_config.CloudConfig)
+ self.assertTrue(extras.safe_hasattr(cc, 'auth'))
+ self.assertIsInstance(cc.auth, dict)
+ self.assertIsNone(cc.cloud)
+ self.assertIn('username', cc.auth)
+ self.assertEqual('testuser', cc.auth['username'])
+ self.assertEqual('testproject', cc.auth['project_name'])
diff --git a/test-requirements.txt b/test-requirements.txt
index d494076..03e0194 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -5,6 +5,8 @@
hacking>=0.9.2,<0.10
coverage>=3.6
+extras
+fixtures>=0.3.14
discover
python-subunit
sphinx>=1.1.2
diff --git a/tox.ini b/tox.ini
index 9be310a..860e337 100644
--- a/tox.ini
+++ b/tox.ini
@@ -19,7 +19,7 @@ commands = flake8
commands = {posargs}
[testenv:cover]
-commands = python setup.py testr --coverage --testr-args='{posargs}'
+commands = python setup.py test --coverage --coverage-package-name=os_client_config --testr-args='{posargs}'
[testenv:docs]
commands = python setup.py build_sphinx
@@ -31,4 +31,4 @@ commands = python setup.py build_sphinx
show-source = True
ignore = E123,E125,H803
builtins = _
-exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build \ No newline at end of file
+exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build