diff --git a/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py b/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py index fda7bdd932..e9be365b60 100755 --- a/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py +++ b/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py @@ -199,17 +199,13 @@ class OVSQuantumAgent(object): def port_update(self, context, **kwargs): LOG.debug("port_update received") port = kwargs.get('port') + network_type = kwargs.get('network_type') + segmentation_id = kwargs.get('segmentation_id') + physical_network = kwargs.get('physical_network') vif_port = self.int_br.get_vif_port_by_id(port['id']) - if vif_port: - if port['admin_state_up']: - vlan_id = kwargs.get('vlan_id') - # create the networking for the port - self.int_br.set_db_attribute("Port", vif_port.port_name, - "tag", str(vlan_id)) - self.int_br.delete_flows(in_port=vif_port.ofport) - else: - self.int_br.clear_db_attribute("Port", vif_port.port_name, - "tag") + self.treat_vif_port(vif_port, port['id'], port['network_id'], + network_type, physical_network, + segmentation_id, port['admin_state_up']) def tunnel_update(self, context, **kwargs): LOG.debug("tunnel_update received") @@ -607,6 +603,17 @@ class OVSQuantumAgent(object): 'added': added, 'removed': removed} + def treat_vif_port(self, vif_port, port_id, network_id, network_type, + physical_network, segmentation_id, admin_state_up): + if vif_port: + if admin_state_up: + self.port_bound(vif_port, network_id, network_type, + physical_network, segmentation_id) + else: + self.port_dead(vif_port) + else: + LOG.debug("No VIF port for port %s defined on agent.", port_id) + def treat_devices_added(self, devices): resync = False for device in devices: @@ -619,19 +626,19 @@ class OVSQuantumAgent(object): LOG.debug("Unable to get port details for %s: %s", device, e) resync = True continue + port = self.int_br.get_vif_port_by_id(details['device']) if 'port_id' in details: LOG.info("Port %s updated. Details: %s", device, details) - port = self.int_br.get_vif_port_by_id(details['port_id']) - if port: - if details['admin_state_up']: - self.port_bound(port, details['network_id'], - details['network_type'], - details['physical_network'], - details['segmentation_id']) - else: - self.port_unbound(port, details['network_id']) + self.treat_vif_port(port, details['port_id'], + details['network_id'], + details['network_type'], + details['physical_network'], + details['segmentation_id'], + details['admin_state_up']) else: LOG.debug("Device %s not defined on plugin", device) + if (port and int(port.ofport) != -1): + self.port_dead(port) return resync def treat_devices_removed(self, devices): diff --git a/quantum/plugins/openvswitch/ovs_quantum_plugin.py b/quantum/plugins/openvswitch/ovs_quantum_plugin.py index 3b6673f0ad..41d347e7aa 100644 --- a/quantum/plugins/openvswitch/ovs_quantum_plugin.py +++ b/quantum/plugins/openvswitch/ovs_quantum_plugin.py @@ -151,11 +151,14 @@ class AgentNotifierApi(proxy.RpcProxy): network_id=network_id), topic=self.topic_network_delete) - def port_update(self, context, port, vlan_id): + def port_update(self, context, port, network_type, segmentation_id, + physical_network): self.fanout_cast(context, self.make_msg('port_update', port=port, - vlan_id=vlan_id), + network_type=network_type, + segmentation_id=segmentation_id, + physical_network=physical_network), topic=self.topic_port_update) def tunnel_update(self, context, tunnel_ip, tunnel_id): @@ -425,10 +428,10 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2, if original_port['admin_state_up'] != port['admin_state_up']: binding = ovs_db_v2.get_network_binding(None, port['network_id']) - # REVISIT(rkukura): Either all binding data or no - # binding data needed. self.notifier.port_update(self.rpc_context, port, - binding.segmentation_id) + binding.network_type, + binding.segmentation_id, + binding.physical_network) return port def delete_port(self, context, id, l3_port_check=True): diff --git a/quantum/tests/unit/openvswitch/test_ovs_rpcapi.py b/quantum/tests/unit/openvswitch/test_ovs_rpcapi.py index 32ea25da96..6f5a25d050 100644 --- a/quantum/tests/unit/openvswitch/test_ovs_rpcapi.py +++ b/quantum/tests/unit/openvswitch/test_ovs_rpcapi.py @@ -75,7 +75,10 @@ class rpcApiTestCase(unittest2.TestCase): topics.PORT, topics.UPDATE), 'port_update', rpc_method='fanout_cast', - port='fake_port', vlan_id='fake_vlan_id') + port='fake_port', + network_type='fake_network_type', + segmentation_id='fake_segmentation_id', + physical_network='fake_physical_network') def test_tunnel_update(self): rpcapi = povs.AgentNotifierApi(topics.AGENT)