diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index a5620fa09b2..407c4999c4c 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -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() diff --git a/cinder/tests/unit/test_db_api.py b/cinder/tests/unit/test_db_api.py index c1165f9a22e..daa3eaf0d4a 100644 --- a/cinder/tests/unit/test_db_api.py +++ b/cinder/tests/unit/test_db_api.py @@ -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,