Fix binding:host_id is set to None when port update

when updating a port 'binding:host_id' is reset if not specified among
the parameter to be updated. As a result, a None value for
'binding:host_id' is sent from the notifier which might potentially
cause consumers to not work properly.

Closes-Bug: #1245310
Change-Id: Icfb5179940cca9f8a705eb36bdbfcbc8a421a272
This commit is contained in:
hyunsun 2013-12-18 18:03:34 +09:00 committed by Gerrit Code Review
parent 9a9627e351
commit 32e0e2178d
2 changed files with 25 additions and 7 deletions

View File

@ -73,17 +73,17 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
del port[portbindings.PROFILE] del port[portbindings.PROFILE]
host = port_data.get(portbindings.HOST_ID) host = port_data.get(portbindings.HOST_ID)
host_set = attributes.is_attr_set(host) 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): with context.session.begin(subtransactions=True):
bind_port = context.session.query( bind_port = context.session.query(
PortBindingPort).filter_by(port_id=port['id']).first() PortBindingPort).filter_by(port_id=port['id']).first()
if not bind_port: if host_set:
context.session.add(PortBindingPort(port_id=port['id'], if not bind_port:
host=host)) context.session.add(PortBindingPort(port_id=port['id'],
host=host))
else:
bind_port.host = host
else: else:
bind_port.host = host host = (bind_port and bind_port.host or None)
self._extend_port_dict_binding_host(port, host) self._extend_port_dict_binding_host(port, host)
def get_port_host(self, context, port_id): def get_port_host(self, context, port_id):

View File

@ -247,6 +247,24 @@ class PortBindingsHostTestCaseMixin(object):
for port in ports: for port in ports:
self.assertEqual('testhosttemp', port[portbindings.HOST_ID]) 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): def test_ports_vif_host_list(self):
cfg.CONF.set_default('allow_overlapping_ips', True) cfg.CONF.set_default('allow_overlapping_ips', True)
host_arg = {portbindings.HOST_ID: self.hostname} host_arg = {portbindings.HOST_ID: self.hostname}