From 94c1ad5c0eb0fd574f659a9477b222a7d6c84c4b Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Wed, 6 Nov 2013 15:26:35 +0800 Subject: [PATCH] Fixes RequestContext initialization failure. RequestContext initialization failed in nova 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 "volume" service_catalog. Change-Id: Ie0de50fcafbeabf4698696add610d4e6804f45eb Closes-Bug: #1248424 --- nova/context.py | 2 +- nova/tests/test_context.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nova/context.py b/nova/context.py index c6aca913a4ba..b704ef2497c8 100644 --- a/nova/context.py +++ b/nova/context.py @@ -82,7 +82,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 ('volume')] + if s.get('type') in ('volume',)] else: # if list is empty or none self.service_catalog = [] diff --git a/nova/tests/test_context.py b/nova/tests/test_context.py index 5f2d72a63404..c655b3b27fc3 100644 --- a/nova/tests/test_context.py +++ b/nova/tests/test_context.py @@ -95,7 +95,9 @@ class ContextTestCase(test.NoDBTestCase): {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': u'identity', u'name': u'keystone'}, + {u'type': None, u'name': u'S_withouttype'}, + {u'type': u'vo', u'name': u'S_partofvolume'}] volume_catalog = [{u'type': u'volume', u'name': u'cinder'}] ctxt = context.RequestContext('111', '222',