Fixes #130
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:
@@ -14,9 +14,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import inspect
|
||||||
|
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.openstack.common import timeutils
|
from neutron.openstack.common import timeutils
|
||||||
|
from neutron.openstack.common import uuidutils
|
||||||
|
from sqlalchemy import event
|
||||||
from sqlalchemy import func as sql_func
|
from sqlalchemy import func as sql_func
|
||||||
from sqlalchemy import orm, or_
|
from sqlalchemy import orm, or_
|
||||||
|
|
||||||
@@ -32,6 +35,21 @@ ONE = "one"
|
|||||||
ALL = "all"
|
ALL = "all"
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
def _listify(filters):
|
def _listify(filters):
|
||||||
for key in ["name", "network_id", "id", "device_id", "tenant_id",
|
for key in ["name", "network_id", "id", "device_id", "tenant_id",
|
||||||
"mac_address", "shared"]:
|
"mac_address", "shared"]:
|
||||||
|
|||||||
@@ -16,13 +16,10 @@
|
|||||||
"""
|
"""
|
||||||
v2 Neutron Plug-in API Quark Implementation
|
v2 Neutron Plug-in API Quark Implementation
|
||||||
"""
|
"""
|
||||||
import inspect
|
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from sqlalchemy.orm import sessionmaker, scoped_session
|
from sqlalchemy.orm import sessionmaker, scoped_session
|
||||||
from sqlalchemy import event
|
|
||||||
from zope import sqlalchemy as zsa
|
from zope import sqlalchemy as zsa
|
||||||
|
|
||||||
from neutron.api.v2 import attributes
|
from neutron.api.v2 import attributes
|
||||||
@@ -124,20 +121,6 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||||||
|
|
||||||
def __init__(self):
|
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()
|
neutron_db_api.configure_db()
|
||||||
self._initDBMaker()
|
self._initDBMaker()
|
||||||
self.net_driver = (importutils.import_class(CONF.QUARK.net_driver))()
|
self.net_driver = (importutils.import_class(CONF.QUARK.net_driver))()
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from oslo.config import cfg
|
|||||||
|
|
||||||
from quark.db import models
|
from quark.db import models
|
||||||
import quark.ipam
|
import quark.ipam
|
||||||
import quark.plugin
|
|
||||||
|
|
||||||
from quark.tests import test_base
|
from quark.tests import test_base
|
||||||
|
|
||||||
@@ -36,10 +35,6 @@ class QuarkIpamBaseTest(test_base.TestBase):
|
|||||||
models.BASEV2.metadata.create_all(neutron_session._ENGINE)
|
models.BASEV2.metadata.create_all(neutron_session._ENGINE)
|
||||||
self.ipam = quark.ipam.QuarkIpam()
|
self.ipam = quark.ipam.QuarkIpam()
|
||||||
|
|
||||||
# FIXME(mdietz): refactor around issue #130 and remove this
|
|
||||||
# Ensures that the perhaps_generate_uuid event handler is initialized
|
|
||||||
self.plugin = quark.plugin.Plugin()
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
neutron_db_api.clear_db()
|
neutron_db_api.clear_db()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user