From 539eaaab89eea42f3f92a4ce069183c7730034af Mon Sep 17 00:00:00 2001 From: LiuSheng Date: Thu, 7 Nov 2013 09:27:05 +0800 Subject: [PATCH] RequestContext initialization failed in cinder. RequestContext initialization failed in cinder because of the following error: "TypeError: 'in ' 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 | 2 +- cinder/tests/test_context.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cinder/context.py b/cinder/context.py index 05b5396f7ae..2e077d79fdb 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -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 = [] diff --git a/cinder/tests/test_context.py b/cinder/tests/test_context.py index 46722d91f23..48323c7a9b2 100644 --- a/cinder/tests/test_context.py +++ b/cinder/tests/test_context.py @@ -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)