]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix NoneType error in service_get_all
authorlisali <xiaoyan.li@intel.com>
Thu, 25 Feb 2016 02:19:13 +0000 (02:19 +0000)
committerlisali <xiaoyan.li@intel.com>
Thu, 25 Feb 2016 02:20:40 +0000 (02:20 +0000)
When calling service_get_all without filters,
it raises NoneType error which is imported by
this patch I21775106693176ca128dbfd9db0d43cfc58de00a.

Change-Id: I473a9bbd2caea21c6fcd82b483bece1337ab6535
Closes-Bug: 1549563

cinder/db/sqlalchemy/api.py
cinder/tests/unit/test_db_api.py

index a5620fa09b2a8893ee39e1b345d3c08b1f37f79b..407c4999c4c8ac857b6d616c1e4f724d91550bae 100644 (file)
@@ -379,15 +379,16 @@ def service_get_all(context, filters=None):
 
     query = model_query(context, models.Service)
 
-    try:
-        host = filters.pop('host')
-        host_attr = models.Service.host
-        conditions = or_(host_attr == host, host_attr.op('LIKE')(host + '@%'))
-        query = query.filter(conditions)
-    except KeyError:
-        pass
-
     if filters:
+        try:
+            host = filters.pop('host')
+            host_attr = models.Service.host
+            conditions = or_(host_attr ==
+                             host, host_attr.op('LIKE')(host + '@%'))
+            query = query.filter(conditions)
+        except KeyError:
+            pass
+
         query = query.filter_by(**filters)
 
     return query.all()
index c1165f9a22eba7c084b3f30d48ad2a01fc54da03..daa3eaf0d4aeefad87133a20974471673d406b7b 100644 (file)
@@ -191,6 +191,7 @@ class DBAPIServiceTestCase(BaseTest):
         expected_bin = services[1:3]
         compares = [
             (services, db.service_get_all(self.ctxt, {})),
+            (services, db.service_get_all(self.ctxt)),
             (expected, db.service_get_all(self.ctxt, {'host': 'host1'})),
             (expected_bin, db.service_get_all(self.ctxt, {'binary': 'b2'})),
             (disabled_services, db.service_get_all(self.ctxt,