use neutron-lib trunk resource names

The trunk callback resource names now live in neutron-lib [1].
This patch switches over to use those constants from lib and they
will be removed from neutron in a later patch once consumers switch
over to lib as well.

[1] https://review.openstack.org/#/c/635209/

Change-Id: I79dfe76c1b698fe634393e469157014f1914cc8e
This commit is contained in:
Boden R 2019-02-14 09:47:50 -07:00
parent 83c4f9f7bb
commit ff70e20acc
7 changed files with 43 additions and 43 deletions

View File

@ -17,8 +17,8 @@ import abc
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron.services.trunk import constants as trunk_consts
from neutron.services.trunk.rpc import backend
@ -61,7 +61,7 @@ class DriverBase(object):
"""True if the driver is compatible with the agent type."""
return agent_type == self.agent_type
@registry.receives(trunk_consts.TRUNK_PLUGIN, [events.AFTER_INIT])
@registry.receives(resources.TRUNK_PLUGIN, [events.AFTER_INIT])
def register(self, resource, event, trigger, payload=None):
"""Register the trunk driver.

View File

@ -18,7 +18,6 @@ import oslo_messaging
from neutron.api.rpc.callbacks.consumer import registry
from neutron.api.rpc.callbacks import events
from neutron.api.rpc.callbacks import resources
from neutron.services.trunk import constants
from neutron.services.trunk.drivers.openvswitch.agent import ovsdb_handler
from neutron.services.trunk.drivers.openvswitch.agent import trunk_manager
from neutron.services.trunk.rpc import agent
@ -75,7 +74,7 @@ class OVSTrunkSkeleton(agent.TrunkSkeleton):
"%(subports)s: %(err)s",
{'event': event_type, 'subports': subports, 'err': e})
@local_registry.receives(constants.TRUNK, [local_events.BEFORE_CREATE])
@local_registry.receives(resources.TRUNK, [local_events.BEFORE_CREATE])
def check_trunk_dependencies(
self, resource, event, trigger, **kwargs):
# The OVS trunk driver does not work with iptables firewall and QoS.

View File

@ -18,6 +18,7 @@ import functools
import eventlet
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import context as n_context
from oslo_concurrency import lockutils
from oslo_context import context as o_context
@ -379,7 +380,7 @@ class OVSDBHandler(object):
try:
registry.notify(
constants.TRUNK, events.BEFORE_CREATE, self,
resources.TRUNK, events.BEFORE_CREATE, self,
context=ctx, trunk=trunk)
self.trunk_manager.create_trunk(
trunk.id, trunk.port_id,

View File

@ -61,7 +61,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
drivers.register()
registry.subscribe(rules.enforce_port_deletion_rules,
resources.PORT, events.BEFORE_DELETE)
registry.publish(constants.TRUNK_PLUGIN, events.AFTER_INIT, self)
registry.publish(resources.TRUNK_PLUGIN, events.AFTER_INIT, self)
for driver in self._drivers:
LOG.debug('Trunk plugin loaded with driver %s', driver.name)
self.check_compatibility()
@ -227,10 +227,10 @@ class TrunkPlugin(service_base.ServicePluginBase,
payload = callbacks.TrunkPayload(context, trunk_obj.id,
current_trunk=trunk_obj)
registry.notify(
constants.TRUNK, events.PRECOMMIT_CREATE, self,
resources.TRUNK, events.PRECOMMIT_CREATE, self,
payload=payload)
registry.notify(
constants.TRUNK, events.AFTER_CREATE, self, payload=payload)
resources.TRUNK, events.AFTER_CREATE, self, payload=payload)
return trunk_obj
@db_base_plugin_common.convert_result_to_dict
@ -249,9 +249,9 @@ class TrunkPlugin(service_base.ServicePluginBase,
payload = events.DBEventPayload(
context, resource_id=trunk_id, states=(original_trunk,),
desired_state=trunk_obj, request_body=trunk_data)
registry.publish(constants.TRUNK, events.PRECOMMIT_UPDATE, self,
registry.publish(resources.TRUNK, events.PRECOMMIT_UPDATE, self,
payload=payload)
registry.notify(constants.TRUNK, events.AFTER_UPDATE, self,
registry.notify(resources.TRUNK, events.AFTER_UPDATE, self,
payload=callbacks.TrunkPayload(
context, trunk_id,
original_trunk=original_trunk,
@ -272,11 +272,11 @@ class TrunkPlugin(service_base.ServicePluginBase,
trunk.delete()
payload = callbacks.TrunkPayload(context, trunk_id,
original_trunk=trunk)
registry.notify(constants.TRUNK, events.PRECOMMIT_DELETE, self,
registry.notify(resources.TRUNK, events.PRECOMMIT_DELETE, self,
payload=payload)
else:
raise trunk_exc.TrunkInUse(trunk_id=trunk_id)
registry.notify(constants.TRUNK, events.AFTER_DELETE, self,
registry.notify(resources.TRUNK, events.AFTER_DELETE, self,
payload=payload)
@db_base_plugin_common.convert_result_to_dict
@ -325,11 +325,11 @@ class TrunkPlugin(service_base.ServicePluginBase,
original_trunk=original_trunk,
subports=added_subports)
if added_subports:
registry.notify(constants.SUBPORTS, events.PRECOMMIT_CREATE,
registry.notify(resources.SUBPORTS, events.PRECOMMIT_CREATE,
self, payload=payload)
if added_subports:
registry.notify(
constants.SUBPORTS, events.AFTER_CREATE, self, payload=payload)
resources.SUBPORTS, events.AFTER_CREATE, self, payload=payload)
return trunk
@db_base_plugin_common.convert_result_to_dict
@ -377,11 +377,11 @@ class TrunkPlugin(service_base.ServicePluginBase,
original_trunk=original_trunk,
subports=removed_subports)
if removed_subports:
registry.notify(constants.SUBPORTS, events.PRECOMMIT_DELETE,
registry.notify(resources.SUBPORTS, events.PRECOMMIT_DELETE,
self, payload=payload)
if removed_subports:
registry.notify(
constants.SUBPORTS, events.AFTER_DELETE, self, payload=payload)
resources.SUBPORTS, events.AFTER_DELETE, self, payload=payload)
return trunk
@db_base_plugin_common.filter_fields

View File

@ -14,9 +14,9 @@
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from oslo_log import log as logging
from neutron.services.trunk import constants as trunk_consts
from neutron.services.trunk.rpc import server
LOG = logging.getLogger(__name__)
@ -37,21 +37,21 @@ class ServerSideRpcBackend(object):
# to agents as needed. These are designed to work with any
# agent-based driver that may integrate with the trunk service
# plugin, e.g. linux bridge or ovs.
@registry.receives(trunk_consts.TRUNK,
@registry.receives(resources.TRUNK,
[events.AFTER_CREATE, events.AFTER_DELETE])
@registry.receives(trunk_consts.SUBPORTS,
@registry.receives(resources.SUBPORTS,
[events.AFTER_CREATE, events.AFTER_DELETE])
def process_event(self, resource, event, trunk_plugin, payload):
"""Emit RPC notifications to registered subscribers."""
context = payload.context
LOG.debug("RPC notification needed for trunk %s", payload.trunk_id)
if resource == trunk_consts.SUBPORTS:
if resource == resources.SUBPORTS:
payload = payload.subports
method = {
events.AFTER_CREATE: self._stub.subports_added,
events.AFTER_DELETE: self._stub.subports_deleted,
}
elif resource == trunk_consts.TRUNK:
elif resource == resources.TRUNK:
# On AFTER_DELETE event, current_trunk is None
payload = payload.current_trunk or payload.original_trunk
method = {

View File

@ -13,11 +13,11 @@
import mock
from neutron_lib.callbacks import events
from neutron_lib.callbacks import resources
from neutron_lib import fixture
from neutron.api.rpc.callbacks import resource_manager
from neutron.services.trunk import callbacks
from neutron.services.trunk import constants as trunk_consts
from neutron.services.trunk.rpc import backend
from neutron.tests import base
from neutron.tests import tools
@ -39,22 +39,22 @@ class ServerSideRpcBackendTest(base.BaseTestCase):
calls = [mock.call(
*tools.get_subscribe_args(
test_obj.process_event,
trunk_consts.TRUNK,
resources.TRUNK,
events.AFTER_CREATE)),
mock.call(
*tools.get_subscribe_args(
test_obj.process_event,
trunk_consts.TRUNK,
resources.TRUNK,
events.AFTER_DELETE)),
mock.call(
*tools.get_subscribe_args(
test_obj.process_event,
trunk_consts.SUBPORTS,
resources.SUBPORTS,
events.AFTER_CREATE)),
mock.call(
*tools.get_subscribe_args(
test_obj.process_event,
trunk_consts.SUBPORTS,
resources.SUBPORTS,
events.AFTER_DELETE))
]
self._mgr.subscribe.assert_has_calls(calls, any_order=True)
@ -65,12 +65,12 @@ class ServerSideRpcBackendTest(base.BaseTestCase):
trunk_plugin = mock.Mock()
test_obj.process_event(
trunk_consts.TRUNK, events.AFTER_CREATE, trunk_plugin,
resources.TRUNK, events.AFTER_CREATE, trunk_plugin,
callbacks.TrunkPayload("context",
"id",
current_trunk="current_trunk"))
test_obj.process_event(
trunk_consts.TRUNK, events.AFTER_DELETE, trunk_plugin,
resources.TRUNK, events.AFTER_DELETE, trunk_plugin,
callbacks.TrunkPayload("context",
"id",
original_trunk="original_trunk"))

View File

@ -112,13 +112,13 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
def _test_trunk_create_notify(self, event):
with self.port() as parent_port:
callback = register_mock_callback(constants.TRUNK, event)
callback = register_mock_callback(resources.TRUNK, event)
trunk = self._create_test_trunk(parent_port)
trunk_obj = self._get_trunk_obj(trunk['id'])
payload = callbacks.TrunkPayload(self.context, trunk['id'],
current_trunk=trunk_obj)
callback.assert_called_once_with(
constants.TRUNK, event, self.trunk_plugin, payload=payload)
resources.TRUNK, event, self.trunk_plugin, payload=payload)
def test_create_trunk_notify_after_create(self):
self._test_trunk_create_notify(events.AFTER_CREATE)
@ -128,7 +128,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
def _test_trunk_update_notify(self, event):
with self.port() as parent_port:
callback = register_mock_callback(constants.TRUNK, event)
callback = register_mock_callback(resources.TRUNK, event)
trunk = self._create_test_trunk(parent_port)
orig_trunk_obj = self._get_trunk_obj(trunk['id'])
trunk_req = {'trunk': {'name': 'foo'}}
@ -139,7 +139,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
original_trunk=orig_trunk_obj,
current_trunk=trunk_obj)
callback.assert_called_once_with(
constants.TRUNK, event, self.trunk_plugin, payload=payload)
resources.TRUNK, event, self.trunk_plugin, payload=payload)
def test_trunk_update_notify_after_update(self):
self._test_trunk_update_notify(events.AFTER_UPDATE)
@ -149,7 +149,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
# once all code uses neutron-lib payloads
with self.port() as parent_port:
callback = register_mock_callback(
constants.TRUNK, events.PRECOMMIT_UPDATE)
resources.TRUNK, events.PRECOMMIT_UPDATE)
trunk = self._create_test_trunk(parent_port)
orig_trunk_obj = self._get_trunk_obj(trunk['id'])
trunk_req = {'trunk': {'name': 'foo'}}
@ -157,7 +157,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
trunk_req)
trunk_obj = self._get_trunk_obj(trunk['id'])
callback.assert_called_once_with(
constants.TRUNK, events.PRECOMMIT_UPDATE,
resources.TRUNK, events.PRECOMMIT_UPDATE,
self.trunk_plugin, payload=mock.ANY)
call_payload = callback.call_args[1]['payload']
self.assertEqual(orig_trunk_obj, call_payload.states[0])
@ -165,14 +165,14 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
def _test_trunk_delete_notify(self, event):
with self.port() as parent_port:
callback = register_mock_callback(constants.TRUNK, event)
callback = register_mock_callback(resources.TRUNK, event)
trunk = self._create_test_trunk(parent_port)
trunk_obj = self._get_trunk_obj(trunk['id'])
self.trunk_plugin.delete_trunk(self.context, trunk['id'])
payload = callbacks.TrunkPayload(self.context, trunk['id'],
original_trunk=trunk_obj)
callback.assert_called_once_with(
constants.TRUNK, event, self.trunk_plugin, payload=payload)
resources.TRUNK, event, self.trunk_plugin, payload=payload)
def test_delete_trunk_notify_after_delete(self):
self._test_trunk_delete_notify(events.AFTER_DELETE)
@ -183,7 +183,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
def _test_subport_action_empty_list_no_notify(self, event, subport_method):
with self.port() as parent_port:
trunk = self._create_test_trunk(parent_port)
callback = register_mock_callback(constants.SUBPORTS, event)
callback = register_mock_callback(resources.SUBPORTS, event)
subport_method(self.context, trunk['id'], {'sub_ports': []})
callback.assert_not_called()
@ -212,7 +212,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
trunk = self._create_test_trunk(parent_port)
orig_trunk_obj = self._get_trunk_obj(trunk['id'])
subport = create_subport_dict(child_port['port']['id'])
callback = register_mock_callback(constants.SUBPORTS, event)
callback = register_mock_callback(resources.SUBPORTS, event)
self.trunk_plugin.add_subports(
self.context, trunk['id'], {'sub_ports': [subport]})
trunk_obj = self._get_trunk_obj(trunk['id'])
@ -222,7 +222,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
original_trunk=orig_trunk_obj,
subports=[subport_obj])
callback.assert_called_once_with(
constants.SUBPORTS, event, self.trunk_plugin, payload=payload)
resources.SUBPORTS, event, self.trunk_plugin, payload=payload)
def test_add_subports_notify_after_create(self):
self._test_add_subports_notify(events.AFTER_CREATE)
@ -235,7 +235,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
subport = create_subport_dict(child_port['port']['id'])
trunk = self._create_test_trunk(parent_port, [subport])
orig_trunk_obj = self._get_trunk_obj(trunk['id'])
callback = register_mock_callback(constants.SUBPORTS, event)
callback = register_mock_callback(resources.SUBPORTS, event)
subport_obj = self._get_subport_obj(subport['port_id'])
self.trunk_plugin.remove_subports(
self.context, trunk['id'], {'sub_ports': [subport]})
@ -245,7 +245,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
original_trunk=orig_trunk_obj,
subports=[subport_obj])
callback.assert_called_once_with(
constants.SUBPORTS, event, self.trunk_plugin, payload=payload)
resources.SUBPORTS, event, self.trunk_plugin, payload=payload)
def test_remove_subports_notify_after_delete(self):
self._test_remove_subports_notify(events.AFTER_DELETE)
@ -294,7 +294,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
self.assertEqual(constants.DOWN_STATUS, trunk['status'])
def test__trigger_trunk_status_change_vif_type_changed_unbound(self):
callback = register_mock_callback(constants.TRUNK, events.AFTER_UPDATE)
callback = register_mock_callback(resources.TRUNK, events.AFTER_UPDATE)
with self.port() as parent:
parent[portbindings.VIF_TYPE] = portbindings.VIF_TYPE_UNBOUND
original_port = {portbindings.VIF_TYPE: 'fakeviftype'}
@ -306,7 +306,7 @@ class TrunkPluginTestCase(test_plugin.Ml2PluginV2TestCase):
original_trunk=original_trunk,
current_trunk=current_trunk)
callback.assert_called_once_with(
constants.TRUNK, events.AFTER_UPDATE,
resources.TRUNK, events.AFTER_UPDATE,
self.trunk_plugin, payload=payload)
def test__trigger_trunk_status_change_vif_type_unchanged(self):