Merge "Fix binding:host_id is set to None when port update"
This commit is contained in:
commit
750dfd694d
@ -73,17 +73,17 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
|
||||
del port[portbindings.PROFILE]
|
||||
host = port_data.get(portbindings.HOST_ID)
|
||||
host_set = attributes.is_attr_set(host)
|
||||
if not host_set:
|
||||
self._extend_port_dict_binding_host(port, None)
|
||||
return
|
||||
with context.session.begin(subtransactions=True):
|
||||
bind_port = context.session.query(
|
||||
PortBindingPort).filter_by(port_id=port['id']).first()
|
||||
if not bind_port:
|
||||
context.session.add(PortBindingPort(port_id=port['id'],
|
||||
host=host))
|
||||
if host_set:
|
||||
if not bind_port:
|
||||
context.session.add(PortBindingPort(port_id=port['id'],
|
||||
host=host))
|
||||
else:
|
||||
bind_port.host = host
|
||||
else:
|
||||
bind_port.host = host
|
||||
host = (bind_port and bind_port.host or None)
|
||||
self._extend_port_dict_binding_host(port, host)
|
||||
|
||||
def get_port_host(self, context, port_id):
|
||||
|
@ -247,6 +247,24 @@ class PortBindingsHostTestCaseMixin(object):
|
||||
for port in ports:
|
||||
self.assertEqual('testhosttemp', port[portbindings.HOST_ID])
|
||||
|
||||
def test_ports_vif_non_host_update(self):
|
||||
host_arg = {portbindings.HOST_ID: self.hostname}
|
||||
with self.port(name='name', arg_list=(portbindings.HOST_ID,),
|
||||
**host_arg) as port:
|
||||
data = {'port': {'admin_state_up': False}}
|
||||
req = self.new_update_request('ports', data, port['port']['id'])
|
||||
res = self.deserialize(self.fmt, req.get_response(self.api))
|
||||
self.assertEqual(port['port'][portbindings.HOST_ID],
|
||||
res['port'][portbindings.HOST_ID])
|
||||
|
||||
def test_ports_vif_non_host_update_when_host_null(self):
|
||||
with self.port() as port:
|
||||
data = {'port': {'admin_state_up': False}}
|
||||
req = self.new_update_request('ports', data, port['port']['id'])
|
||||
res = self.deserialize(self.fmt, req.get_response(self.api))
|
||||
self.assertEqual(port['port'][portbindings.HOST_ID],
|
||||
res['port'][portbindings.HOST_ID])
|
||||
|
||||
def test_ports_vif_host_list(self):
|
||||
cfg.CONF.set_default('allow_overlapping_ips', True)
|
||||
host_arg = {portbindings.HOST_ID: self.hostname}
|
||||
|
Loading…
Reference in New Issue
Block a user