Moves the uuid generation event listener from the plugin to the DB API
to decouple test expectations from the plugin.
This commit is contained in:
Matt Dietz
2013-07-19 19:20:58 +00:00
parent 78223887fe
commit e9ea926465
3 changed files with 18 additions and 22 deletions

View File

@@ -16,13 +16,10 @@
"""
v2 Neutron Plug-in API Quark Implementation
"""
import inspect
import netaddr
from oslo.config import cfg
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy import event
from zope import sqlalchemy as zsa
from neutron.api.v2 import attributes
@@ -124,20 +121,6 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
def __init__(self):
# NOTE(jkoelker) init event listener that will ensure id is filled in
# on object creation (prior to commit).
def _perhaps_generate_id(target, args, kwargs):
if hasattr(target, 'id') and target.id is None:
target.id = uuidutils.generate_uuid()
# NOTE(jkoelker) Register the event on all models that have ids
for _name, klass in inspect.getmembers(models, inspect.isclass):
if klass is models.HasId:
continue
if models.HasId in klass.mro():
event.listen(klass, "init", _perhaps_generate_id)
neutron_db_api.configure_db()
self._initDBMaker()
self.net_driver = (importutils.import_class(CONF.QUARK.net_driver))()