]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
allow subclasses to modify the parents model hooks
authorMark McClain <mark.mcclain@dreamhost.com>
Fri, 9 Aug 2013 04:53:33 +0000 (00:53 -0400)
committerMark McClain <mark.mcclain@dreamhost.com>
Fri, 9 Aug 2013 04:53:33 +0000 (00:53 -0400)
fixes bug 1210387

This change modifies the model hook processing to call the method on the
instance if a hook is registered as a string.  If the hook is a
callable, then callable is called with the hook arguments.

Change-Id: Id14ae89f3f12a500920d248226e0ecba8e35e74c

neutron/db/db_base_plugin_v2.py
neutron/db/l3_db.py
neutron/db/portbindings_db.py

index 84d0ed840b1383a9a78dacdfc6cd20bc6abec1c2..0a9176b55351cdc2f61be3b5dff844ee77f1cc11 100644 (file)
@@ -100,11 +100,16 @@ class CommonDbMixin(object):
         for _name, hooks in self._model_query_hooks.get(model,
                                                         {}).iteritems():
             query_hook = hooks.get('query')
-            filter_hook = hooks.get('filter')
+            if isinstance(query_hook, basestring):
+                query_hook = getattr(self, query_hook, None)
             if query_hook:
-                query = query_hook(self, context, model, query)
+                query = query_hook(context, model, query)
+
+            filter_hook = hooks.get('filter')
+            if isinstance(filter_hook, basestring):
+                filter_hook = getattr(self, filter_hook, None)
             if filter_hook:
-                query_filter = filter_hook(self, context, model, query_filter)
+                query_filter = filter_hook(context, model, query_filter)
 
         # NOTE(salvatore-orlando): 'if query_filter' will try to evaluate the
         # condition, raising an exception
@@ -142,8 +147,11 @@ class CommonDbMixin(object):
             for _name, hooks in self._model_query_hooks.get(model,
                                                             {}).iteritems():
                 result_filter = hooks.get('result_filters', None)
+                if isinstance(result_filter, basestring):
+                    result_filter = getattr(self, result_filter, None)
+
                 if result_filter:
-                    query = result_filter(self, query, filters)
+                    query = result_filter(query, filters)
         return query
 
     def _get_collection_query(self, context, model, filters=None,
index 5e84c2ceee52dd7e93fe88041234c1dd93472458..d1830778d6058242331a835dc842764b3e674cf8 100644 (file)
@@ -120,9 +120,9 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
     db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(
         models_v2.Network,
         "external_net",
-        _network_model_hook,
-        _network_filter_hook,
-        _network_result_filter_hook)
+        '_network_model_hook',
+        '_network_filter_hook',
+        '_network_result_filter_hook')
 
     def _get_router(self, context, id):
         try:
index 8340e0f0985c268d8c765d71abc5d19907de67a4..678f7433453ab42da1ef953a49d5aa95f4c2d786 100644 (file)
@@ -61,9 +61,9 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
     db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(
         models_v2.Port,
         "portbindings_port",
-        _port_model_hook,
+        '_port_model_hook',
         None,
-        _port_result_filter_hook)
+        '_port_result_filter_hook')
 
     def _process_portbindings_create_and_update(self, context, port_data,
                                                 port):