bp: pxeboot-port, provide pxeboot on ports

Add extra_dhcp_opts extension to Ml2 plugin.

Implements:bp:pxeboot-ports

Change-Id: Id1d3923c4d2e3cf86731e2f2e9013fbee4ed68c7
This commit is contained in:
dekehn 2013-09-11 14:26:35 -06:00
parent 3e564f8e03
commit 096ce8707e
3 changed files with 22 additions and 4 deletions

View File

@ -25,10 +25,12 @@ from neutron.db import agentschedulers_db
from neutron.db import allowedaddresspairs_db as addr_pair_db from neutron.db import allowedaddresspairs_db as addr_pair_db
from neutron.db import db_base_plugin_v2 from neutron.db import db_base_plugin_v2
from neutron.db import external_net_db from neutron.db import external_net_db
from neutron.db import extradhcpopt_db
from neutron.db import models_v2 from neutron.db import models_v2
from neutron.db import quota_db # noqa from neutron.db import quota_db # noqa
from neutron.db import securitygroups_rpc_base as sg_db_rpc from neutron.db import securitygroups_rpc_base as sg_db_rpc
from neutron.extensions import allowedaddresspairs as addr_pair from neutron.extensions import allowedaddresspairs as addr_pair
from neutron.extensions import extra_dhcp_opt as edo_ext
from neutron.extensions import multiprovidernet as mpnet from neutron.extensions import multiprovidernet as mpnet
from neutron.extensions import portbindings from neutron.extensions import portbindings
from neutron.extensions import providernet as provider from neutron.extensions import providernet as provider
@ -58,7 +60,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
external_net_db.External_net_db_mixin, external_net_db.External_net_db_mixin,
sg_db_rpc.SecurityGroupServerRpcMixin, sg_db_rpc.SecurityGroupServerRpcMixin,
agentschedulers_db.DhcpAgentSchedulerDbMixin, agentschedulers_db.DhcpAgentSchedulerDbMixin,
addr_pair_db.AllowedAddressPairsMixin): addr_pair_db.AllowedAddressPairsMixin,
extradhcpopt_db.ExtraDhcpOptMixin):
"""Implement the Neutron L2 abstractions using modules. """Implement the Neutron L2 abstractions using modules.
@ -80,7 +83,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
_supported_extension_aliases = ["provider", "external-net", "binding", _supported_extension_aliases = ["provider", "external-net", "binding",
"quotas", "security-group", "agent", "quotas", "security-group", "agent",
"dhcp_agent_scheduler", "dhcp_agent_scheduler",
"multi-provider", "allowed-address-pairs"] "multi-provider", "allowed-address-pairs",
"extra_dhcp_opt"]
@property @property
def supported_extension_aliases(self): def supported_extension_aliases(self):
@ -441,6 +445,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
with session.begin(subtransactions=True): with session.begin(subtransactions=True):
self._ensure_default_security_group_on_port(context, port) self._ensure_default_security_group_on_port(context, port)
sgids = self._get_security_groups_on_port(context, port) sgids = self._get_security_groups_on_port(context, port)
dhcp_opts = port['port'].get(edo_ext.EXTRADHCPOPTS, [])
result = super(Ml2Plugin, self).create_port(context, port) result = super(Ml2Plugin, self).create_port(context, port)
self._process_port_create_security_group(context, result, sgids) self._process_port_create_security_group(context, result, sgids)
network = self.get_network(context, result['network_id']) network = self.get_network(context, result['network_id'])
@ -451,6 +456,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
self._process_create_allowed_address_pairs( self._process_create_allowed_address_pairs(
context, result, context, result,
attrs.get(addr_pair.ADDRESS_PAIRS))) attrs.get(addr_pair.ADDRESS_PAIRS)))
self._process_port_create_extra_dhcp_opts(context, result,
dhcp_opts)
self.mechanism_manager.create_port_precommit(mech_context) self.mechanism_manager.create_port_precommit(mech_context)
try: try:
@ -481,6 +488,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
need_port_update_notify |= self.update_security_group_on_port( need_port_update_notify |= self.update_security_group_on_port(
context, id, port, original_port, updated_port) context, id, port, original_port, updated_port)
network = self.get_network(context, original_port['network_id']) network = self.get_network(context, original_port['network_id'])
need_port_update_notify |= self._update_extra_dhcp_opts_on_port(
context, id, port, updated_port)
mech_context = driver_context.PortContext( mech_context = driver_context.PortContext(
self, context, updated_port, network, self, context, updated_port, network,
original_port=original_port) original_port=original_port)

View File

@ -19,6 +19,7 @@ from neutron.extensions import providernet as pnet
from neutron.plugins.ml2 import config from neutron.plugins.ml2 import config
from neutron.tests.unit import _test_extension_portbindings as test_bindings from neutron.tests.unit import _test_extension_portbindings as test_bindings
from neutron.tests.unit import test_db_plugin as test_plugin from neutron.tests.unit import test_db_plugin as test_plugin
from neutron.tests.unit import test_extension_extradhcpopts as test_dhcpopts
from neutron.tests.unit import test_security_groups_rpc as test_sg_rpc from neutron.tests.unit import test_security_groups_rpc as test_sg_rpc
@ -194,3 +195,10 @@ class TestMultiSegmentNetworks(Ml2PluginV2TestCase):
network_req = self.new_create_request('networks', data) network_req = self.new_create_request('networks', data)
res = network_req.get_response(self.api) res = network_req.get_response(self.api)
self.assertEqual(res.status_int, 400) self.assertEqual(res.status_int, 400)
class DHCPOptsTestCase(test_dhcpopts.TestExtraDhcpOpt):
def setUp(self, plugin=None):
super(test_dhcpopts.ExtraDhcpOptDBTestCase, self).setUp(
plugin=PLUGIN_NAME)

View File

@ -55,8 +55,9 @@ class ExtraDhcpOptTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
class ExtraDhcpOptDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase): class ExtraDhcpOptDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
def setUp(self, plugin=None):
super(ExtraDhcpOptDBTestCase, self).setUp(plugin=DB_PLUGIN_KLASS) def setUp(self, plugin=DB_PLUGIN_KLASS):
super(ExtraDhcpOptDBTestCase, self).setUp(plugin=plugin)
class TestExtraDhcpOpt(ExtraDhcpOptDBTestCase): class TestExtraDhcpOpt(ExtraDhcpOptDBTestCase):