def _vm_port_deleted(self, ovs_port): ovs_port_id = ovs_port.id lport_id = ovs_port.iface_id lport = self.db_store.get_one(l2.LogicalPort(id=lport_id)) if lport is None: lport = self.ovs_to_lport_mapping.get(ovs_port_id) if lport is None: return topic = lport.topic del self.ovs_to_lport_mapping[ovs_port_id] self._del_from_topic_subscribed(topic, lport_id) return topic = lport.topic LOG.info("The logical port(%s) is offline", lport) try: self.controller.delete(lport) except Exception: LOG.exception('Failed to process logical port offline event %s', lport_id) finally: self.controller.notify_port_status(ovs_port, n_const.PORT_STATUS_DOWN) migration_obj = self.nb_api.get(migration.Migration(id=lport_id)) if migration_obj and migration_obj.chassis: LOG.info("Sending migrating event for %s", lport_id) migration_obj.lport = lport_id migration_obj.status = migration.MIGRATION_STATUS_SRC_UNPLUG self.nb_api.update(migration_obj) del self.ovs_to_lport_mapping[ovs_port_id] self._del_from_topic_subscribed(topic, lport_id)
def test_update_migration_flows(self): cfg.CONF.set_override('host', 'fake-local-host') lport = test_app_base.fake_local_port1 fake_lswitch = test_app_base.fake_logic_switch1 migration_obj = migration.Migration( id=lport.id, dest_chassis='fake-local-host', lport=lport, status=migration.MIGRATION_STATUS_SRC_UNPLUG) self.controller.nb_api.get.return_value = lport self.controller.db_store.update(fake_lswitch) self.controller.db_store.update(lport) self.controller.vswitch_api.get_chassis_ofport.return_value = 3 self.controller.vswitch_api.get_port_ofport_by_id.retrun_value = 2 mock_update_patch = mock.patch.object( self.controller.db_store, 'update', side_effect=self.controller.db_store.update) mock_update = mock_update_patch.start() self.addCleanup(mock_update_patch.stop) mock_emit_created_patch = mock.patch.object(lport, 'emit_local_created') mock_emit_created = mock_emit_created_patch.start() self.addCleanup(mock_emit_created_patch.stop) self.controller.update(migration_obj) self.assertEqual( [mock.call(lport), mock.call(migration_obj)], mock_update.call_args_list) mock_emit_created.assert_called_with()
def _vm_port_updated(self, ovs_port): lport_id = ovs_port.iface_id lport = self._get_lport(lport_id) if lport is None: LOG.warning("No logical port found for ovs port: %s", ovs_port) return topic = lport.topic if not topic: return self._add_to_topic_subscribed(topic, lport_id) self.ovs_to_lport_mapping[ovs_port.id] = OvsLportMapping( lport_id=lport_id, topic=topic) chassis = lport.chassis # check if migration occurs if chassis.id != self.chassis_name: device_owner = lport.device_owner if n_const.DEVICE_OWNER_COMPUTE_PREFIX in device_owner: LOG.info("Prepare migrate lport %(lport)s to %(chassis)s", { "lport": lport_id, "chassis": chassis }) self.nb_api.create( migration.Migration( id=lport_id, dest_chassis=self.chassis_name, status=migration.MIGRATION_STATUS_DEST_PLUG)) return cached_lport = self.db_store.get_one(l2.LogicalPort(id=lport_id)) if not cached_lport or not cached_lport.ofport: # If the logical port is not in db store or its ofport is not # valid. It has not been applied to dragonflow apps. We need to # update it in dragonflow controller. LOG.info("A local logical port(%s) is online", lport) try: self.controller.update(lport) except Exception: LOG.exception( 'Failed to process logical port online ' 'event: %s', lport)