RequestContext initialization failed in cinder.

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
This commit is contained in:
LiuSheng 2013-11-07 09:27:05 +08:00 committed by liusheng
parent 54b117d26e
commit 539eaaab89
2 changed files with 18 additions and 1 deletions

View 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 = []

View 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)