Add support for dhcp extra opt

Change-Id: I30374cd64e9e5347025c319cb21916a0b3a768ec
This commit is contained in:
Aaron Rosen 2015-07-23 12:30:33 -07:00
parent a0d62a9516
commit efcbf63215
2 changed files with 17 additions and 0 deletions

View File

@ -35,6 +35,7 @@ from neutron.db import agentschedulers_db
from neutron.db import allowedaddresspairs_db as addr_pair_db
from neutron.db import db_base_plugin_v2
from neutron.db import external_net_db
from neutron.db import extradhcpopt_db
from neutron.db import extraroute_db
from neutron.db import l3_db
from neutron.db import l3_dvr_db
@ -46,6 +47,7 @@ from neutron.db import quota_db # noqa
from neutron.db import securitygroups_db
from neutron.extensions import allowedaddresspairs as addr_pair
from neutron.extensions import external_net as ext_net_extn
from neutron.extensions import extra_dhcp_opt as edo_ext
from neutron.extensions import extraroute
from neutron.extensions import l3
from neutron.extensions import multiprovidernet as mpnet
@ -94,6 +96,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
dhcpmeta_modes.DhcpMetadataAccess,
l3_dvr_db.L3_NAT_with_dvr_db_mixin,
external_net_db.External_net_db_mixin,
extradhcpopt_db.ExtraDhcpOptMixin,
extraroute_db.ExtraRoute_db_mixin,
l3_gwmode_db.L3_NAT_db_mixin,
mac_db.MacLearningDbMixin,
@ -117,6 +120,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
"qos-queue",
"quotas",
"external-net",
"extra_dhcp_opt",
"router",
"security-group",
constants.SUBNET_ALLOCATION_EXT_ALIAS]
@ -1076,6 +1080,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
# ATTR_NOT_SPECIFIED is for the case where a port is created on a
# shared network that is not owned by the tenant.
port_data = port['port']
dhcp_opts = port_data.get(edo_ext.EXTRADHCPOPTS, [])
# Set port status as 'DOWN'. This will be updated by backend sync.
port_data['status'] = constants.PORT_STATUS_DOWN
with context.session.begin(subtransactions=True):
@ -1127,6 +1132,8 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
self._process_portbindings_create_and_update(context,
port['port'],
port_data)
self._process_port_create_extra_dhcp_opts(context, port_data,
dhcp_opts)
# For some reason the port bindings DB mixin does not handle
# the VNIC_TYPE attribute, which is required by nova for
# setting up VIFs.
@ -1173,6 +1180,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
with context.session.begin(subtransactions=True):
ret_port = super(NsxPluginV2, self).update_port(
context, id, port)
# Save current mac learning state to check whether it's
# being updated or not
old_mac_learning_state = ret_port.get(mac_ext.MAC_LEARNING)
@ -1181,6 +1189,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
port['port'].pop('fixed_ips', None)
ret_port.update(port['port'])
tenant_id = self._get_tenant_id_for_create(context, ret_port)
self._update_extra_dhcp_opts_on_port(context, id, port, ret_port)
# populate port_security setting
if psec.PORTSECURITY not in port['port']:

View File

@ -31,6 +31,7 @@ from neutron.extensions import securitygroup as secgrp
from neutron import manager
from neutron.tests.unit import _test_extension_portbindings as test_bindings
import neutron.tests.unit.db.test_db_base_plugin_v2 as test_plugin
from neutron.tests.unit.extensions import test_extra_dhcp_opt as test_dhcpopts
import neutron.tests.unit.extensions.test_l3 as test_l3_plugin
import neutron.tests.unit.extensions.test_l3_ext_gw_mode as test_ext_gw_mode
import neutron.tests.unit.extensions.test_securitygroup as ext_sg
@ -1275,3 +1276,10 @@ class NeutronNsxOutOfSync(NsxPluginV2TestCase,
sec_group['security_group']['id'])
res = req.get_response(self.ext_api)
self.assertEqual(res.status_int, 204)
class DHCPOptsTestCase(test_dhcpopts.TestExtraDhcpOpt, NsxPluginV2TestCase):
def setUp(self, plugin=None):
super(test_dhcpopts.ExtraDhcpOptDBTestCase, self).setUp(
plugin=vmware.PLUGIN_NAME)