summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-28 08:37:35 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-31 08:59:59 -0600
commitc4eba6eaaa2f8e0a0ca40c40907fc9e04a65e6d9 (patch)
tree300fc72621cc56c589e57587f9333e90ec2c6bf2
parentb003647b70545008405294c4268e62fa87c18574 (diff)
Attempt to fix domain support.
The prior code treated *_domain_name & *_domain_id the same where the ID was taken first and the name was used as the fallback which was incorrect. This patch treats the name and ID fields as separate members. JIRA: SNAPS-154 Change-Id: I5219863de597c4db24579f4af74ece2d648b2b07 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--docs/how-to-use/LibraryUsage.rst2
-rw-r--r--snaps/openstack/os_credentials.py27
-rw-r--r--snaps/openstack/tests/conf/os_credentials_tests.py78
-rw-r--r--snaps/openstack/tests/openstack_tests.py8
-rw-r--r--snaps/openstack/utils/keystone_utils.py4
5 files changed, 77 insertions, 42 deletions
diff --git a/docs/how-to-use/LibraryUsage.rst b/docs/how-to-use/LibraryUsage.rst
index 353891e..16cf446 100644
--- a/docs/how-to-use/LibraryUsage.rst
+++ b/docs/how-to-use/LibraryUsage.rst
@@ -36,7 +36,9 @@ attributes are listed below:
- compute\_api\_version (Nova version 2 currently only validated)
- heat\_api\_version (Heat version 1 currently only validated)
- user\_domain\_id (default='default')
+- user\_domain\_name (default='default')
- project\_domain\_id (default='default')
+- project\_domain\_name (default='default')
- interface (default='admin', used to specify the endpoint type for keystone: public, admin, internal)
- cacert (default=False, expected values T|F to denote server certificate verification, else value contains the path to an HTTPS certificate)
- region_name (The region name default=None)
diff --git a/snaps/openstack/os_credentials.py b/snaps/openstack/os_credentials.py
index c93133a..fbecbfe 100644
--- a/snaps/openstack/os_credentials.py
+++ b/snaps/openstack/os_credentials.py
@@ -42,8 +42,10 @@ class OSCreds:
clients
:param heat_api_version: The OpenStack's API version to use for Heat
clients
- :param user_domain_id: Used for v3 APIs (default='default')
- :param project_domain_id: Used for v3 APIs (default='default')
+ :param user_domain_id: Used for v3 APIs (default=None)
+ :param user_domain_name: Used for v3 APIs (default='default')
+ :param project_domain_id: Used for v3 APIs (default=None)
+ :param project_domain_name: Used for v3 APIs (default='default')
:param interface: Used to specify the endpoint type for keystone as
public, admin, internal
:param proxy_settings: instance of os_credentials.ProxySettings class
@@ -83,15 +85,19 @@ class OSCreds:
else:
self.heat_api_version = float(kwargs['heat_api_version'])
- if kwargs.get('user_domain_id') is None:
- self.user_domain_id = 'default'
+ self.user_domain_id = kwargs.get('user_domain_id')
+
+ if kwargs.get('user_domain_name') is None:
+ self.user_domain_name = 'default'
else:
- self.user_domain_id = kwargs['user_domain_id']
+ self.user_domain_name = kwargs['user_domain_name']
+
+ self.project_domain_id = kwargs.get('project_domain_id')
- if kwargs.get('project_domain_id') is None:
- self.project_domain_id = 'default'
+ if kwargs.get('project_domain_name') is None:
+ self.project_domain_name = 'default'
else:
- self.project_domain_id = kwargs['project_domain_id']
+ self.project_domain_name = kwargs['project_domain_name']
if kwargs.get('interface') is None:
self.interface = 'admin'
@@ -141,8 +147,13 @@ class OSCreds:
', image_api_version=' + str(self.image_api_version) +
', network_api_version=' + str(self.network_api_version) +
', compute_api_version=' + str(self.compute_api_version) +
+ ', heat_api_version=' + str(self.heat_api_version) +
', user_domain_id=' + str(self.user_domain_id) +
+ ', user_domain_name=' + str(self.user_domain_name) +
+ ', project_domain_id=' + str(self.project_domain_id) +
+ ', project_domain_name=' + str(self.project_domain_name) +
', interface=' + str(self.interface) +
+ ', region_name=' + str(self.region_name) +
', proxy_settings=' + str(self.proxy_settings) +
', cacert=' + str(self.cacert))
diff --git a/snaps/openstack/tests/conf/os_credentials_tests.py b/snaps/openstack/tests/conf/os_credentials_tests.py
index 4a2ce3d..9c6fcdc 100644
--- a/snaps/openstack/tests/conf/os_credentials_tests.py
+++ b/snaps/openstack/tests/conf/os_credentials_tests.py
@@ -16,8 +16,8 @@
import logging
import unittest
-from snaps.openstack.os_credentials import OSCredsError, OSCreds, \
- ProxySettings, ProxySettingsError
+from snaps.openstack.os_credentials import (
+ OSCredsError, OSCreds, ProxySettings, ProxySettingsError)
__author__ = 'spisarski'
@@ -157,8 +157,10 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertEqual(2, os_creds.image_api_version)
self.assertEqual(2, os_creds.compute_api_version)
self.assertEqual(1, os_creds.heat_api_version)
- self.assertEqual('default', os_creds.user_domain_id)
- self.assertEqual('default', os_creds.project_domain_id)
+ self.assertIsNone(os_creds.user_domain_id)
+ self.assertEqual('default', os_creds.user_domain_name)
+ self.assertIsNone(os_creds.project_domain_id)
+ self.assertEqual('default', os_creds.project_domain_name)
self.assertEqual('admin', os_creds.interface)
self.assertFalse(os_creds.cacert)
self.assertIsNone(os_creds.proxy_settings)
@@ -176,8 +178,10 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertEqual(2, os_creds.image_api_version)
self.assertEqual(2, os_creds.compute_api_version)
self.assertEqual(1, os_creds.heat_api_version)
- self.assertEqual('default', os_creds.user_domain_id)
- self.assertEqual('default', os_creds.project_domain_id)
+ self.assertIsNone(os_creds.user_domain_id)
+ self.assertEqual('default', os_creds.user_domain_name)
+ self.assertIsNone(os_creds.project_domain_id)
+ self.assertEqual('default', os_creds.project_domain_name)
self.assertEqual('admin', os_creds.interface)
self.assertFalse(os_creds.cacert)
self.assertIsNone(os_creds.proxy_settings)
@@ -198,8 +202,10 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertEqual(6, os_creds.image_api_version)
self.assertEqual(7, os_creds.compute_api_version)
self.assertEqual(8.0, os_creds.heat_api_version)
- self.assertEqual('default', os_creds.user_domain_id)
- self.assertEqual('default', os_creds.project_domain_id)
+ self.assertIsNone(os_creds.user_domain_id)
+ self.assertEqual('default', os_creds.user_domain_name)
+ self.assertIsNone(os_creds.project_domain_id)
+ self.assertEqual('default', os_creds.project_domain_name)
self.assertEqual('admin', os_creds.interface)
self.assertTrue(os_creds.cacert)
self.assertIsNone(os_creds.proxy_settings)
@@ -220,8 +226,10 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertEqual(6, os_creds.image_api_version)
self.assertEqual(7, os_creds.compute_api_version)
self.assertEqual(8.0, os_creds.heat_api_version)
- self.assertEqual('default', os_creds.user_domain_id)
- self.assertEqual('default', os_creds.project_domain_id)
+ self.assertIsNone(os_creds.user_domain_id)
+ self.assertEqual('default', os_creds.user_domain_name)
+ self.assertIsNone(os_creds.project_domain_id)
+ self.assertEqual('default', os_creds.project_domain_name)
self.assertEqual('admin', os_creds.interface)
self.assertTrue(os_creds.cacert)
self.assertIsNone(os_creds.proxy_settings)
@@ -240,8 +248,10 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertEqual(2, os_creds.image_api_version)
self.assertEqual(2, os_creds.compute_api_version)
self.assertEqual(1, os_creds.heat_api_version)
- self.assertEqual('default', os_creds.user_domain_id)
- self.assertEqual('default', os_creds.project_domain_id)
+ self.assertIsNone(os_creds.user_domain_id)
+ self.assertEqual('default', os_creds.user_domain_name)
+ self.assertIsNone(os_creds.project_domain_id)
+ self.assertEqual('default', os_creds.project_domain_name)
self.assertEqual('admin', os_creds.interface)
self.assertFalse(os_creds.cacert)
self.assertEqual('foo', os_creds.proxy_settings.host)
@@ -251,11 +261,13 @@ class OSCredsUnitTests(unittest.TestCase):
def test_proxy_settings_obj_kwargs(self):
proxy_settings = ProxySettings(host='foo', port=1234)
- os_creds = OSCreds(**{'username': 'foo', 'password': 'bar',
- 'auth_url': 'http://foo.bar:5000/v2',
- 'project_name': 'hello',
- 'proxy_settings': proxy_settings,
- 'region_name': 'test_region'})
+ os_creds = OSCreds(
+ **{'username': 'foo', 'password': 'bar',
+ 'auth_url': 'http://foo.bar:5000/v2', 'project_name': 'hello',
+ 'proxy_settings': proxy_settings, 'region_name': 'test_region',
+ 'user_domain_id': 'domain1', 'user_domain_name': 'domain2',
+ 'project_domain_id': 'domain3',
+ 'project_domain_name': 'domain4'})
self.assertEqual('foo', os_creds.username)
self.assertEqual('bar', os_creds.password)
self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
@@ -264,8 +276,10 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertEqual(2, os_creds.image_api_version)
self.assertEqual(2, os_creds.compute_api_version)
self.assertEqual(1, os_creds.heat_api_version)
- self.assertEqual('default', os_creds.user_domain_id)
- self.assertEqual('default', os_creds.project_domain_id)
+ self.assertEqual('domain1', os_creds.user_domain_id)
+ self.assertEqual('domain2', os_creds.user_domain_name)
+ self.assertEqual('domain3', os_creds.project_domain_id)
+ self.assertEqual('domain4', os_creds.project_domain_name)
self.assertEqual('admin', os_creds.interface)
self.assertFalse(os_creds.cacert)
self.assertEqual('foo', os_creds.proxy_settings.host)
@@ -276,7 +290,9 @@ class OSCredsUnitTests(unittest.TestCase):
def test_proxy_settings_dict(self):
os_creds = OSCreds(
username='foo', password='bar', auth_url='http://foo.bar:5000/v2',
- project_name='hello', proxy_settings={'host': 'foo', 'port': 1234})
+ project_name='hello', proxy_settings={'host': 'foo', 'port': 1234},
+ user_domain_id='domain1', user_domain_name='domain2',
+ project_domain_id='domain3', project_domain_name='domain4')
self.assertEqual('foo', os_creds.username)
self.assertEqual('bar', os_creds.password)
self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
@@ -285,8 +301,10 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertEqual(2, os_creds.image_api_version)
self.assertEqual(2, os_creds.compute_api_version)
self.assertEqual(1, os_creds.heat_api_version)
- self.assertEqual('default', os_creds.user_domain_id)
- self.assertEqual('default', os_creds.project_domain_id)
+ self.assertEqual('domain1', os_creds.user_domain_id)
+ self.assertEqual('domain2', os_creds.user_domain_name)
+ self.assertEqual('domain3', os_creds.project_domain_id)
+ self.assertEqual('domain4', os_creds.project_domain_name)
self.assertEqual('admin', os_creds.interface)
self.assertFalse(os_creds.cacert)
self.assertEqual('foo', os_creds.proxy_settings.host)
@@ -294,11 +312,11 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertIsNone(os_creds.proxy_settings.ssh_proxy_cmd)
def test_proxy_settings_dict_kwargs(self):
- os_creds = OSCreds(**{'username': 'foo', 'password': 'bar',
- 'auth_url': 'http://foo.bar:5000/v2',
- 'project_name': 'hello',
- 'proxy_settings': {'host': 'foo', 'port': 1234},
- 'region_name': 'test_region'})
+ os_creds = OSCreds(
+ **{'username': 'foo', 'password': 'bar',
+ 'auth_url': 'http://foo.bar:5000/v2', 'project_name': 'hello',
+ 'proxy_settings': {'host': 'foo', 'port': 1234},
+ 'region_name': 'test_region'})
self.assertEqual('foo', os_creds.username)
self.assertEqual('bar', os_creds.password)
self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
@@ -307,8 +325,10 @@ class OSCredsUnitTests(unittest.TestCase):
self.assertEqual(2, os_creds.image_api_version)
self.assertEqual(2, os_creds.compute_api_version)
self.assertEqual(1, os_creds.heat_api_version)
- self.assertEqual('default', os_creds.user_domain_id)
- self.assertEqual('default', os_creds.project_domain_id)
+ self.assertIsNone(os_creds.user_domain_id)
+ self.assertEqual('default', os_creds.user_domain_name)
+ self.assertIsNone(os_creds.project_domain_id)
+ self.assertEqual('default', os_creds.project_domain_name)
self.assertEqual('admin', os_creds.interface)
self.assertFalse(os_creds.cacert)
self.assertEqual('foo', os_creds.proxy_settings.host)
diff --git a/snaps/openstack/tests/openstack_tests.py b/snaps/openstack/tests/openstack_tests.py
index 927b5b3..2dab75c 100644
--- a/snaps/openstack/tests/openstack_tests.py
+++ b/snaps/openstack/tests/openstack_tests.py
@@ -95,10 +95,10 @@ def get_credentials(os_env_file=None, proxy_settings_str=None,
'network_api_version': config.get('OS_NETWORK_API_VERSION'),
'compute_api_version': config.get('OS_COMPUTE_API_VERSION'),
'heat_api_version': config.get('OS_HEAT_API_VERSION'),
- 'user_domain_id': config.get(
- 'OS_USER_DOMAIN_ID', config.get('OS_USER_DOMAIN_NAME')),
- 'project_domain_id': config.get(
- 'OS_PROJECT_DOMAIN_ID', config.get('OS_PROJECT_DOMAIN_NAME')),
+ 'user_domain_id': config.get('OS_USER_DOMAIN_ID'),
+ 'user_domain_name': config.get('OS_USER_DOMAIN_NAME'),
+ 'project_domain_id': config.get('OS_PROJECT_DOMAIN_ID'),
+ 'project_domain_name': config.get('OS_PROJECT_DOMAIN_NAME'),
'interface': interface,
'proxy_settings': proxy_settings,
'cacert': https_cacert,
diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py
index e070a49..3fff469 100644
--- a/snaps/openstack/utils/keystone_utils.py
+++ b/snaps/openstack/utils/keystone_utils.py
@@ -41,7 +41,9 @@ def get_session_auth(os_creds):
password=os_creds.password,
project_name=os_creds.project_name,
user_domain_id=os_creds.user_domain_id,
- project_domain_id=os_creds.project_domain_id)
+ user_domain_name=os_creds.user_domain_name,
+ project_domain_id=os_creds.project_domain_id,
+ project_domain_name=os_creds.project_domain_name)
else:
auth = v2.Password(auth_url=os_creds.auth_url,
username=os_creds.username,