]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
RequestContext initialization failed in cinder.
authorLiuSheng <liusheng@huawei.com>
Thu, 7 Nov 2013 01:27:05 +0000 (09:27 +0800)
committerliusheng <liusheng@huawei.com>
Thu, 7 Nov 2013 02:33:09 +0000 (10:33 +0800)
RequestContext initialization failed in cinder because of the following
error:
"TypeError: 'in <string>' requires string as left operand, not NoneType"

It must traverses in tuple not in string when find the "compute"
service_catalog.

Change-Id: I46f4bbd0ffb9d1db8bdcb0254ca95551fea08baf
Closes-Bug: #1248434

cinder/context.py
cinder/tests/test_context.py

index 05b5396f7aef602606b7d7390b29b48668cf739c..2e077d79fdbeae76c576c49c96841d08279e2e16 100644 (file)
@@ -91,7 +91,7 @@ class RequestContext(object):
         if service_catalog:
             # Only include required parts of service_catalog
             self.service_catalog = [s for s in service_catalog
-                                    if s.get('type') in ('compute')]
+                                    if s.get('type') in ('compute',)]
         else:
             # if list is empty or none
             self.service_catalog = []
index 46722d91f236a5134ff5a1d83422ddf5f825a3fc..48323c7a9b28055adaa91a1c8d07dd8da197fa62 100644 (file)
@@ -70,3 +70,20 @@ class ContextTestCase(test.TestCase):
         self.assertTrue(c)
         self.assertIn("'extra_arg1': 'meow'", info['log_msg'])
         self.assertIn("'extra_arg2': 'wuff'", info['log_msg'])
+
+    def test_service_catalog_nova_only(self):
+        service_catalog = [
+            {u'type': u'compute', u'name': u'nova'},
+            {u'type': u's3', u'name': u's3'},
+            {u'type': u'image', u'name': u'glance'},
+            {u'type': u'volume', u'name': u'cinder'},
+            {u'type': u'ec2', u'name': u'ec2'},
+            {u'type': u'object-store', u'name': u'swift'},
+            {u'type': u'identity', u'name': u'keystone'},
+            {u'type': None, u'name': u'S_withtypeNone'},
+            {u'type': u'co', u'name': u'S_partofcompute'}]
+
+        compute_catalog = [{u'type': u'compute', u'name': u'nova'}]
+        ctxt = context.RequestContext('111', '222',
+                                      service_catalog=service_catalog)
+        self.assertEquals(ctxt.service_catalog, compute_catalog)