def pre_live_migration(self, context, block_device_info, network_infos,
                           disk_info, migrate_data, vol_drvs):
        """Prepare an instance for live migration

        :param context: security context
        :param block_device_info: instance block device information
        :param network_infos: instance network information
        :param disk_info: instance disk information
        :param migrate_data: a PowerVMLiveMigrateData object
        :param vol_drvs: volume drivers for the attached volumes
        """
        LOG.debug(
            'Running pre live migration on destination. Migration data: '
            '%s',
            migrate_data,
            instance=self.instance)

        # Set the ssh auth key.
        mgmt_task.add_authorized_key(self.drvr.adapter,
                                     migrate_data.public_key)

        # For each network info, run the pre-live migration.  This tells the
        # system what the target vlans will be.
        vea_vlan_mappings = {}
        for network_info in network_infos:
            vif.pre_live_migrate_at_destination(self.drvr.adapter,
                                                self.drvr.host_uuid,
                                                self.instance, network_info,
                                                vea_vlan_mappings)
        migrate_data.vea_vlan_mappings = vea_vlan_mappings

        # For each volume, make sure it's ready to migrate
        for vol_drv in vol_drvs:
            LOG.info('Performing pre migration for volume %(volume)s',
                     dict(volume=vol_drv.volume_id),
                     instance=self.instance)
            try:
                vol_drv.pre_live_migration_on_destination(
                    migrate_data.vol_data)
            except Exception:
                LOG.exception(
                    "PowerVM error preparing instance for live "
                    "migration.",
                    instance=self.instance)
                # It failed.
                vol_exc = LiveMigrationVolume(
                    host=self.drvr.host_wrapper.system_name,
                    name=self.instance.name,
                    volume=vol_drv.volume_id)
                raise exception.MigrationPreCheckError(reason=vol_exc.message)

        # Scrub stale/orphan mappings and storage to minimize probability of
        # collisions on the destination.
        stor_task.ComprehensiveScrub(self.drvr.adapter).execute()

        # Save the migration data, we'll use it if the LPM fails
        self.pre_live_vol_data = migrate_data.vol_data
        return migrate_data
Exemple #2
0
    def test_pre_live_migrate_at_destination(self, mock_build_vif_drv):
        mock_drv = mock.MagicMock()
        mock_build_vif_drv.return_value = mock_drv
        mock_vif = mock.MagicMock()

        vif.pre_live_migrate_at_destination(self.adpt, 'host_uuid',
                                            mock.Mock(), mock_vif, {})

        mock_drv.pre_live_migrate_at_destination.assert_called_once_with(
            mock_vif, {})