from quantum.common import topics
from quantum.db import agents_db
from quantum.db import agentschedulers_db
+from quantum.db import db_base_plugin_v2
from quantum.db import dhcp_rpc_base
from quantum.db import extraroute_db
from quantum.db import l3_gwmode_db
net = super(NECPluginV2, self).get_network(context, id)
tenant_id = net['tenant_id']
+ # Make sure auto-delete ports on OFC are deleted.
+ filter = {'network_id': [id],
+ 'device_owner': db_base_plugin_v2.AUTO_DELETE_PORT_OWNERS}
+ auto_delete_ports = self.get_ports(context, filters=filter)
+ for port in auto_delete_ports:
+ LOG.debug(_('delete_network(): deleting auto-delete port'
+ ' from OFC: %s'), port)
+ self.deactivate_port(context, port)
+
# get packet_filters associated with the network
if self.packet_filter_enabled:
filters = dict(network_id=[id])
super(TestNecPluginOfcManager, self).setUp()
self.ofc = self.plugin.ofc
+ def _create_resource(self, resource, data):
+ collection = resource + 's'
+ data = {resource: data}
+ req = self.new_create_request(collection, data)
+ res = self.deserialize(self.fmt, req.get_response(self.api))
+ return res[resource]
+
def _update_resource(self, resource, id, data):
collection = resource + 's'
data = {resource: data}
]
self.ofc.assert_has_calls(expected)
+ def test_delete_network_with_dhcp_port(self):
+ self.ofc.exists_ofc_tenant.return_value = False
+ self.ofc.exists_ofc_port.side_effect = [False, True]
+
+ ctx = mock.ANY
+ with self.network() as network:
+ with self.subnet(network=network):
+ net = network['network']
+ p = self._create_resource('port',
+ {'network_id': net['id'],
+ 'tenant_id': net['tenant_id'],
+ 'device_owner': 'network:dhcp',
+ 'device_id': 'dhcp-port1'})
+ # Make sure that the port is created on OFC.
+ portinfo = {'id': p['id'], 'port_no': 123}
+ self._rpcapi_update_ports(added=[portinfo])
+ # In a case of dhcp port, the port is deleted automatically
+ # when delete_network.
+
+ expected = [
+ mock.call.exists_ofc_tenant(ctx, self._tenant_id),
+ mock.call.create_ofc_tenant(ctx, self._tenant_id),
+ mock.call.create_ofc_network(ctx, self._tenant_id,
+ net['id'], net['name']),
+ mock.call.exists_ofc_port(ctx, p['id']),
+ mock.call.create_ofc_port(ctx, p['id'], mock.ANY),
+ mock.call.exists_ofc_port(ctx, p['id']),
+ mock.call.delete_ofc_port(ctx, p['id'], mock.ANY),
+ mock.call.delete_ofc_network(ctx, net['id'], mock.ANY),
+ mock.call.delete_ofc_tenant(ctx, self._tenant_id)
+ ]
+ self.ofc.assert_has_calls(expected)
+
def test_update_port(self):
self._test_update_port_with_admin_state(resource='port')