summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-09-16 12:30:12 +0200
committerMonty Taylor <mordred@inaugust.com>2015-09-16 23:16:02 +0200
commitaef90e7ec82326e63136be3ace1fa0a0590ee325 (patch)
tree54c5b12275b4101e9261f79f7728512fb2664c85
parent2be0553eb0d168ea0dc57e098c8dcc86566b6622 (diff)
downloados-client-config-aef90e7ec82326e63136be3ace1fa0a0590ee325.tar.gz
Allow configuring domain id once
In the most common case, a use has one and only one domain id that they care about, and it's associated with their user and project. Instead of making them set it for both user_domain_id and project_domain_id, allow for domain_{id, name} and then fill in any missing values for {user,project}_domain_{id,name} with the given value. This is mainly because I wind up with config files looking like this: user_domain_id: d0919bd5e8d74e49adf0e145807ffc38 project_domain_id: d0919bd5e8d74e49adf0e145807ffc38 Which offends my tender sensibilities. Change-Id: I12342dfa9f1b539a3fea5dd8874c42d027c59739
-rw-r--r--os_client_config/config.py23
-rw-r--r--os_client_config/tests/base.py11
-rw-r--r--os_client_config/tests/test_config.py12
3 files changed, 45 insertions, 1 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index ec35548..e8e76a5 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -279,15 +279,38 @@ class OpenStackConfig(object):
cloud = self._fix_backwards_project(cloud)
cloud = self._fix_backwards_auth_plugin(cloud)
cloud = self._fix_backwards_interface(cloud)
+ cloud = self._handle_domain_id(cloud)
+ return cloud
+
+ def _handle_domain_id(self, cloud):
+ # Allow people to just specify domain once if it's the same
+ mappings = {
+ 'domain_id': ('user_domain_id', 'project_domain_id'),
+ 'domain_name': ('user_domain_name', 'project_domain_name'),
+ }
+ for target_key, possible_values in mappings.items():
+ for key in possible_values:
+ if target_key in cloud['auth'] and key not in cloud['auth']:
+ cloud['auth'][key] = cloud['auth'][target_key]
+ cloud['auth'].pop(target_key, None)
return cloud
def _fix_backwards_project(self, cloud):
# Do the lists backwards so that project_name is the ultimate winner
+ # Also handle moving domain names into auth so that domain mapping
+ # is easier
mappings = {
'project_id': ('tenant_id', 'tenant-id',
'project_id', 'project-id'),
'project_name': ('tenant_name', 'tenant-name',
'project_name', 'project-name'),
+ 'domain_id': ('domain_id', 'domain-id'),
+ 'domain_name': ('domain_name', 'domain-name'),
+ 'user_domain_id': ('user_domain_id', 'user-domain-id'),
+ 'user_domain_name': ('user_domain_name', 'user-domain-name'),
+ 'project_domain_id': ('project_domain_id', 'project-domain-id'),
+ 'project_domain_name': (
+ 'project_domain_name', 'project-domain-name'),
}
for target_key, possible_values in mappings.items():
target = None
diff --git a/os_client_config/tests/base.py b/os_client_config/tests/base.py
index 9a29237..cbf58da 100644
--- a/os_client_config/tests/base.py
+++ b/os_client_config/tests/base.py
@@ -71,6 +71,17 @@ USER_CONF = {
},
'region_name': 'test-region',
},
+ '_test-cloud-domain-id_': {
+ 'auth': {
+ 'username': 'testuser',
+ 'password': 'testpass',
+ 'project_id': 12345,
+ 'auth_url': 'http://example.com/v2',
+ 'domain_id': '6789',
+ 'project_domain_id': '123456789',
+ },
+ 'region_name': 'test-region',
+ },
'_test_cloud_regions': {
'auth': {
'username': 'testuser',
diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py
index 82f2fb9..36fe15d 100644
--- a/os_client_config/tests/test_config.py
+++ b/os_client_config/tests/test_config.py
@@ -91,6 +91,15 @@ class TestConfig(base.TestCase):
cc = c.get_one_cloud('_test-cloud-int-project_')
self.assertEqual('12345', cc.auth['project_id'])
+ def test_get_one_cloud_with_domain_id(self):
+ c = config.OpenStackConfig(config_files=[self.cloud_yaml],
+ vendor_files=[self.vendor_yaml])
+ cc = c.get_one_cloud('_test-cloud-domain-id_')
+ self.assertEqual('6789', cc.auth['user_domain_id'])
+ self.assertEqual('123456789', cc.auth['project_domain_id'])
+ self.assertNotIn('domain_id', cc.auth)
+ self.assertNotIn('domain-id', cc.auth)
+
def test_get_one_cloud_with_hyphenated_project_id(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
@@ -132,7 +141,8 @@ class TestConfig(base.TestCase):
def test_get_cloud_names(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml])
self.assertEqual(
- ['_test-cloud-int-project_',
+ ['_test-cloud-domain-id_',
+ '_test-cloud-int-project_',
'_test-cloud_',
'_test_cloud_hyphenated',
'_test_cloud_no_vendor',