← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1104379] Re: Code duplication. db_base_plugin_v2.py and loadbalancer_db.py duplicate code

 

** Changed in: neutron
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1104379

Title:
  Code duplication. db_base_plugin_v2.py and loadbalancer_db.py
  duplicate code

Status in OpenStack Neutron (virtual network service):
  Fix Released

Bug description:
  quantum/db/db_base_plugin_v2.py and quantum/db/loadbalancer/loadbalancer_db.py duplicate code.
  Here is the duplicated code:

    def _fields(self, resource, fields):
          if fields:
              return dict((key, item) for key, item in resource.iteritems()
                          if key in fields)
          return resource

      def _apply_filters_to_query(self, query, model, filters):
          if filters:
              for key, value in filters.iteritems():
                  column = getattr(model, key, None)
                  if column:
                      query = query.filter(column.in_(value))
          return query

      def _get_collection_query(self, context, model, filters=None):
          collection = self._model_query(context, model)
          collection = self._apply_filters_to_query(collection, model, filters)
          return collection

      def _get_collection(self, context, model, dict_func, filters=None,
                          fields=None):
          query = self._get_collection_query(context, model, filters)
          return [dict_func(c, fields) for c in query.all()]

      def _get_collection_count(self, context, model, filters=None):
          return self._get_collection_query(context, model, filters).count()

  Needs to have common parent to support this code.

To manage notifications about this bug go to:
https://bugs.launchpad.net/neutron/+bug/1104379/+subscriptions