diff options
author | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2013-03-18 15:28:57 -0400 |
---|---|---|
committer | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2013-03-18 18:06:52 -0400 |
commit | 4664d2294aed498ef013afc1689740f03de80a6c (patch) | |
tree | 190346ebe622de6a6a933d3c8303d8cbb95b2051 | |
parent | 85aebeb8b864f990cdfb78b6deafc8a3fe3c1e23 (diff) | |
download | nova-4664d2294aed498ef013afc1689740f03de80a6c.tar.gz nova-4664d2294aed498ef013afc1689740f03de80a6c.tar.xz nova-4664d2294aed498ef013afc1689740f03de80a6c.zip |
Fix RequestContext crashes w/ no service catalog
Code introduced in a prev review assumed service_catalog will be
at least an empty list and will never be None. But missed one code
path where the service_catalog could potentially be set to None. So
this change switches back the default value of service_catalog in
the arguments to None and makes sure we tolerate anyone else
passing in a None or Empty list as service_catalog
Fix for LP# 1156730
Change-Id: I480b761d57c4699ea7ef72114160cdbeb281e454
-rw-r--r-- | nova/context.py | 12 | ||||
-rw-r--r-- | nova/tests/test_context.py | 8 |
2 files changed, 17 insertions, 3 deletions
diff --git a/nova/context.py b/nova/context.py index 714948e90..cd4428e58 100644 --- a/nova/context.py +++ b/nova/context.py @@ -47,7 +47,7 @@ class RequestContext(object): roles=None, remote_address=None, timestamp=None, request_id=None, auth_token=None, overwrite=True, quota_class=None, user_name=None, project_name=None, - service_catalog=[], instance_lock_checked=False, **kwargs): + service_catalog=None, instance_lock_checked=False, **kwargs): """ :param read_deleted: 'no' indicates deleted records are hidden, 'yes' indicates deleted records are visible, 'only' indicates that @@ -77,9 +77,15 @@ class RequestContext(object): request_id = generate_request_id() self.request_id = request_id self.auth_token = auth_token - # Only include required parts of service_catalog - self.service_catalog = [s for s in service_catalog + + 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')] + else: + # if list is empty or none + self.service_catalog = [] + self.instance_lock_checked = instance_lock_checked # NOTE(markmc): this attribute is currently only used by the diff --git a/nova/tests/test_context.py b/nova/tests/test_context.py index 99b5c705c..4639f75b0 100644 --- a/nova/tests/test_context.py +++ b/nova/tests/test_context.py @@ -79,6 +79,14 @@ class ContextTestCase(test.TestCase): ctxt = context.RequestContext('111', '222') self.assertEquals(ctxt.service_catalog, []) + ctxt = context.RequestContext('111', '222', + service_catalog=[]) + self.assertEquals(ctxt.service_catalog, []) + + ctxt = context.RequestContext('111', '222', + service_catalog=None) + self.assertEquals(ctxt.service_catalog, []) + def test_service_catalog_cinder_only(self): service_catalog = [ {u'type': u'compute', u'name': u'nova'}, |