From 392a695bbdabfc30ddc3f4a58a3a498828f78f3e Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Tue, 8 Oct 2019 11:04:51 +0300 Subject: [PATCH] NSX|v+v3+p: Allow resetting port binding host Change-Id: Ic9f3f080bbf51a04cea601b2c4b0614b9b5c4e33 --- vmware_nsx/db/nsx_portbindings_db.py | 5 +++++ vmware_nsx/tests/unit/nsx_v3/test_plugin.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/vmware_nsx/db/nsx_portbindings_db.py b/vmware_nsx/db/nsx_portbindings_db.py index ca9019dde5..185f56112c 100644 --- a/vmware_nsx/db/nsx_portbindings_db.py +++ b/vmware_nsx/db/nsx_portbindings_db.py @@ -95,6 +95,11 @@ class NsxPortBindingMixin(pbin_db.PortBindingMixin): def _process_portbindings_create_and_update( self, context, port, port_res, vif_type=nsx_constants.VIF_TYPE_DVS): + + # Allow clearing the host id + if pbin.HOST_ID in port and port[pbin.HOST_ID] is None: + port[pbin.HOST_ID] = '' + super(NsxPortBindingMixin, self)._process_portbindings_create_and_update( context, port, port_res) diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index 750ac24836..15632cc08a 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -1929,6 +1929,22 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin, def test_requested_subnet_id_v4_and_v6(self): return super(TestPortsV2, self).test_requested_subnet_id_v4_and_v6() + def test_port_binding_host(self): + with self.port() as port: + # add host + data = {'port': {portbindings.HOST_ID: 'abc'}} + req = self.new_update_request('ports', + data, port['port']['id']) + res = self.deserialize('json', req.get_response(self.api)) + self.assertEqual('abc', res['port'][portbindings.HOST_ID]) + + # remove host + data = {'port': {portbindings.HOST_ID: None}} + req = self.new_update_request('ports', + data, port['port']['id']) + res = self.deserialize('json', req.get_response(self.api)) + self.assertEqual('', res['port'][portbindings.HOST_ID]) + class DHCPOptsTestCase(test_dhcpopts.TestExtraDhcpOpt, NsxV3PluginTestCaseMixin):