Repository: libcloud
Updated Branches:
  refs/heads/trunk 080b343e0 -> 9f3147172


openstack: handle missing user "enabled" attribute

Keystone may not always return an "enabled" attribute for a user
account. Prior to this change, we could crash if we queried a user that
lacked an "enabled" attribute. Gracefully handle this case by setting
"enabled" 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/a61877de
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a61877de
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a61877de

Branch: refs/heads/trunk
Commit: a61877de33c868f4c20515706a0fbb73464ac2e7
Parents: 080b343
Author: Ken Dreyer <[email protected]>
Authored: Wed Nov 28 13:46:55 2018 -0700
Committer: Rick van de Loo <[email protected]>
Committed: Thu Nov 29 08:36:06 2018 +0100

----------------------------------------------------------------------
 libcloud/common/openstack_identity.py                 |  2 +-
 libcloud/test/common/test_openstack_identity.py       | 13 +++++++++++++
 .../fixtures/openstack_identity/v3/v3_users_c.json    | 14 ++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a61877de/libcloud/common/openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack_identity.py 
b/libcloud/common/openstack_identity.py
index f608244..53646a3 100644
--- a/libcloud/common/openstack_identity.py
+++ b/libcloud/common/openstack_identity.py
@@ -1383,7 +1383,7 @@ class 
OpenStackIdentity_3_0_Connection(OpenStackIdentityConnection):
                                      email=data.get('email'),
                                      description=data.get('description',
                                                           None),
-                                     enabled=data['enabled'])
+                                     enabled=data.get('enabled'))
         return user
 
     def _to_roles(self, data):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/a61877de/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 e91c0b9..91dba7e 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -379,6 +379,12 @@ class 
OpenStackIdentity_3_0_ConnectionTests(unittest.TestCase):
         self.assertEqual(user.name, 'userwithoutemail')
         self.assertEqual(user.email, None)
 
+    def test_get_user_without_enabled(self):
+        user = self.auth_instance.get_user(user_id='c')
+        self.assertEqual(user.id, 'c')
+        self.assertEqual(user.name, 'userwithoutenabled')
+        self.assertEqual(user.enabled, None)
+
     def test_create_user(self):
         user = self.auth_instance.create_user(email='test2@localhost', 
password='test1',
                                               name='test2', 
domain_id='default')
@@ -712,6 +718,13 @@ class OpenStackIdentity_3_0_MockHttp(MockHttp):
             return (httplib.OK, body, self.json_content_headers, 
httplib.responses[httplib.OK])
         raise NotImplementedError()
 
+    def _v3_users_c(self, method, url, body, headers):
+        if method == 'GET':
+            # look up a user
+            body = self.fixtures.load('v3_users_c.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/a61877de/libcloud/test/compute/fixtures/openstack_identity/v3/v3_users_c.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/openstack_identity/v3/v3_users_c.json 
b/libcloud/test/compute/fixtures/openstack_identity/v3/v3_users_c.json
new file mode 100644
index 0000000..f254dcf
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_identity/v3/v3_users_c.json
@@ -0,0 +1,14 @@
+{
+    "user":
+      {
+          "name": "userwithoutenabled",
+          "links": {
+              "self": "http://192.168.18.100:5000/v3/users/c";
+          },
+          "domain_id": "default",
+          "id": "c",
+          "email": "[email protected]",
+          "password_expires_at": null,
+          "options": {}
+      }
+}

Reply via email to