NSX|V3: treat DHCP server max entries
Ensure two things:
1. DHCP server exception will rollback the neutron/nsx port
2. A more appropriate exception is raised
Change-Id: I480d53665c8aaaab5458cdac0fdd9d07938f6a96
(cherry picked from commit ea8afbabae
)
This commit is contained in:
parent
7c1c8bec56
commit
2bfbd59789
|
@ -2070,7 +2070,14 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||
|
||||
# Add Mac/IP binding to native DHCP server and neutron DB.
|
||||
if cfg.CONF.nsx_v3.native_dhcp_metadata:
|
||||
self._add_dhcp_binding(context, port_data)
|
||||
try:
|
||||
self._add_dhcp_binding(context, port_data)
|
||||
except nsx_lib_exc.ManagerError:
|
||||
# Rollback create port
|
||||
self.delete_port(context, port_data['id'])
|
||||
msg = _('Unable to create port. Please contact admin')
|
||||
LOG.exception(msg)
|
||||
raise nsx_exc.NsxPluginException(err_msg=msg)
|
||||
|
||||
if not cfg.CONF.nsx_v3.native_dhcp_metadata:
|
||||
nsx_rpc.handle_port_metadata_access(self, context, neutron_db)
|
||||
|
|
|
@ -49,6 +49,7 @@ from vmware_nsx.tests import unit as vmware
|
|||
from vmware_nsx.tests.unit.extensions import test_metadata
|
||||
from vmware_nsxlib.tests.unit.v3 import mocks as nsx_v3_mocks
|
||||
from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase
|
||||
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
|
||||
|
||||
|
||||
PLUGIN_NAME = 'vmware_nsx.plugin.NsxV3Plugin'
|
||||
|
@ -460,6 +461,16 @@ class TestPortsV2(test_plugin.TestPortsV2, NsxV3PluginTestCaseMixin,
|
|||
self._get_ports_with_fields(tenid, 'mac_address', 4)
|
||||
self._get_ports_with_fields(tenid, 'network_id', 4)
|
||||
|
||||
def test_port_failure_rollback_dhcp_exception(self):
|
||||
cfg.CONF.set_override('native_dhcp_metadata', True, 'nsx_v3')
|
||||
self.plugin = directory.get_plugin()
|
||||
with mock.patch.object(self.plugin, '_add_dhcp_binding',
|
||||
side_effect=nsxlib_exc.ManagerError):
|
||||
self.port()
|
||||
ctx = context.get_admin_context()
|
||||
networks = self.plugin.get_ports(ctx)
|
||||
self.assertListEqual([], networks)
|
||||
|
||||
|
||||
class DHCPOptsTestCase(test_dhcpopts.TestExtraDhcpOpt,
|
||||
NsxV3PluginTestCaseMixin):
|
||||
|
|
Loading…
Reference in New Issue