Add BEFORE notification event for subnet in ml2 plugin

Implements the BEFORE_CREATE notification in the
_before_create_subnet method.

Related-Bug: #1766380
Change-Id: I2ad73054b3b870314e8047e9a84ca60285c852e1
This commit is contained in:
Harald Jensås 2018-06-08 21:10:32 +02:00
parent 32b6846ae6
commit 19dccbf07e
2 changed files with 16 additions and 2 deletions

View File

@ -1023,8 +1023,9 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
self.notifier.network_delete(context, network['id'])
def _before_create_subnet(self, context, subnet):
# TODO(kevinbenton): BEFORE notification should be added here
pass
subnet_data = subnet[subnet_def.RESOURCE_NAME]
registry.notify(resources.SUBNET, events.BEFORE_CREATE, self,
context=context, subnet=subnet_data)
def _create_subnet_db(self, context, subnet):
with db_api.context_manager.writer.using(context):

View File

@ -498,6 +498,19 @@ class TestMl2NetworksWithAvailabilityZone(TestMl2NetworksV2):
class TestMl2SubnetsV2(test_plugin.TestSubnetsV2,
Ml2PluginV2TestCase):
def test_subnet_before_create_callback(self):
before_create = mock.Mock()
registry.subscribe(before_create, resources.SUBNET,
events.BEFORE_CREATE)
with self.subnet() as s:
before_create.assert_called_once_with(
resources.SUBNET, events.BEFORE_CREATE, mock.ANY,
context=mock.ANY, subnet=mock.ANY)
kwargs = before_create.mock_calls[0][2]
self.assertEqual(s['subnet']['cidr'], kwargs['subnet']['cidr'])
self.assertEqual(s['subnet']['network_id'],
kwargs['subnet']['network_id'])
def test_subnet_after_create_callback(self):
after_create = mock.Mock()
registry.subscribe(after_create, resources.SUBNET, events.AFTER_CREATE)