Repository: libcloud Updated Branches: refs/heads/trunk 102608f16 -> 112f15833
openstack: handle missing user email Keystone may not always return an "email" entry for a user account. Prior to this change, we could crash if we queried a user that lacked an email record. Gracefully handle this case by setting email to None. Signed-off-by: Rick van de Loo <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/8efa20a6 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8efa20a6 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8efa20a6 Branch: refs/heads/trunk Commit: 8efa20a62a82ff89b535031e5619071fa083a9ce Parents: 102608f Author: Ken Dreyer <[email protected]> Authored: Mon Oct 22 11:07:38 2018 -0600 Committer: Rick van de Loo <[email protected]> Committed: Fri Oct 26 18:48:36 2018 +0200 ---------------------------------------------------------------------- libcloud/common/openstack_identity.py | 2 +- libcloud/test/common/test_openstack_identity.py | 13 +++++++++++++ .../fixtures/openstack_identity/v3/v3_users_b.json | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/8efa20a6/libcloud/common/openstack_identity.py ---------------------------------------------------------------------- diff --git a/libcloud/common/openstack_identity.py b/libcloud/common/openstack_identity.py index 3d09681..f608244 100644 --- a/libcloud/common/openstack_identity.py +++ b/libcloud/common/openstack_identity.py @@ -1380,7 +1380,7 @@ class OpenStackIdentity_3_0_Connection(OpenStackIdentityConnection): user = OpenStackIdentityUser(id=data['id'], domain_id=data['domain_id'], name=data['name'], - email=data['email'], + email=data.get('email'), description=data.get('description', None), enabled=data['enabled']) http://git-wip-us.apache.org/repos/asf/libcloud/blob/8efa20a6/libcloud/test/common/test_openstack_identity.py ---------------------------------------------------------------------- diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py index 916193f..e91c0b9 100644 --- a/libcloud/test/common/test_openstack_identity.py +++ b/libcloud/test/common/test_openstack_identity.py @@ -373,6 +373,12 @@ class OpenStackIdentity_3_0_ConnectionTests(unittest.TestCase): self.assertEqual(user.enabled, True) self.assertEqual(user.email, 'openstack-test@localhost') + def test_get_user_without_email(self): + user = self.auth_instance.get_user(user_id='b') + self.assertEqual(user.id, 'b') + self.assertEqual(user.name, 'userwithoutemail') + self.assertEqual(user.email, None) + def test_create_user(self): user = self.auth_instance.create_user(email='test2@localhost', password='test1', name='test2', domain_id='default') @@ -699,6 +705,13 @@ class OpenStackIdentity_3_0_MockHttp(MockHttp): return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) raise NotImplementedError() + def _v3_users_b(self, method, url, body, headers): + if method == 'GET': + # look up a user + body = self.fixtures.load('v3_users_b.json') + return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) + raise NotImplementedError() + def _v3_roles(self, method, url, body, headers): if method == 'GET': body = self.fixtures.load('v3_roles.json') http://git-wip-us.apache.org/repos/asf/libcloud/blob/8efa20a6/libcloud/test/compute/fixtures/openstack_identity/v3/v3_users_b.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/openstack_identity/v3/v3_users_b.json b/libcloud/test/compute/fixtures/openstack_identity/v3/v3_users_b.json new file mode 100644 index 0000000..293ac5b --- /dev/null +++ b/libcloud/test/compute/fixtures/openstack_identity/v3/v3_users_b.json @@ -0,0 +1,17 @@ +{ + "user": + { + "name": "userwithoutemail", + "links": { + "self": "http://192.168.18.100:5000/v3/users/b" + }, + "domain_id": "default", + "enabled": true, + "id": "b" + }, + "links": { + "self": "http://192.168.18.100:5000/v3/users", + "previous": null, + "next": null + } +}
