NSX|v+v3+p: Allow resetting port binding host

Change-Id: Ic9f3f080bbf51a04cea601b2c4b0614b9b5c4e33
This commit is contained in:
Adit Sarfaty 2019-10-08 11:04:51 +03:00
parent 4a749bc35e
commit 392a695bbd
2 changed files with 21 additions and 0 deletions

View File

@ -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)

View File

@ -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):