def test_from_legacy_dict(self): obj = migrate_data.HyperVLiveMigrateData(is_shared_instance_path=False) legacy = obj.to_legacy_dict() obj2 = migrate_data.HyperVLiveMigrateData() obj2.from_legacy_dict(legacy) self.assertEqual(obj.is_shared_instance_path, obj2.is_shared_instance_path)
def test_obj_make_compatible(self): obj = migrate_data.HyperVLiveMigrateData( is_shared_instance_path=True, old_vol_attachment_ids={'yes': 'no'}) primitive = obj.obj_to_primitive(target_version='1.0') self.assertNotIn('is_shared_instance_path', primitive) primitive = obj.obj_to_primitive(target_version='1.1') self.assertNotIn('old_vol_attachment_ids', primitive)
def test_to_legacy_dict(self): obj = migrate_data.HyperVLiveMigrateData( is_shared_instance_path=False) expected = { 'is_shared_instance_path': False, } self.assertEqual(expected, obj.to_legacy_dict())
def check_can_live_migrate_destination(self, ctxt, instance_ref, src_compute_info, dst_compute_info, block_migration=False, disk_over_commit=False): LOG.debug("check_can_live_migrate_destination called", instance_ref) return migrate_data_obj.HyperVLiveMigrateData()
def check_can_live_migrate_destination(self, ctxt, instance_ref, src_compute_info, dst_compute_info, block_migration=False, disk_over_commit=False): LOG.debug("check_can_live_migrate_destination called", instance=instance_ref) migrate_data = migrate_data_obj.HyperVLiveMigrateData() migrate_data.is_shared_instance_path = ( self._pathutils.check_remote_instances_dir_shared( instance_ref.host)) return migrate_data
def test_obj_make_compatible(self): obj = migrate_data.HyperVLiveMigrateData( is_shared_instance_path=True, old_vol_attachment_ids={'yes': 'no'}, wait_for_vif_plugged=True) data = lambda x: x['nova_object.data'] primitive = data(obj.obj_to_primitive()) self.assertIn('is_shared_instance_path', primitive) primitive = data(obj.obj_to_primitive(target_version='1.0')) self.assertNotIn('is_shared_instance_path', primitive) primitive = data(obj.obj_to_primitive(target_version='1.1')) self.assertNotIn('old_vol_attachment_ids', primitive) primitive = data(obj.obj_to_primitive(target_version='1.2')) self.assertNotIn('wait_for_vif_plugged', primitive)
def live_migration(self, context, instance_ref, dest, post_method, recover_method, block_migration=False, migrate_data=None): LOG.debug("live_migration called", instance=instance_ref) instance_name = instance_ref["name"] if migrate_data and 'is_shared_instance_path' in migrate_data: shared_storage = migrate_data.is_shared_instance_path else: shared_storage = ( self._pathutils.check_remote_instances_dir_shared(dest)) if migrate_data: migrate_data.is_shared_instance_path = shared_storage else: migrate_data = migrate_data_obj.HyperVLiveMigrateData( is_shared_instance_path=shared_storage) try: # We must make sure that the console log workers are stopped, # otherwise we won't be able to delete / move VM log files. self._serial_console_ops.stop_console_handler(instance_name) if not shared_storage: self._pathutils.copy_vm_console_logs(instance_name, dest) self._vmops.copy_vm_dvd_disks(instance_name, dest) self._livemigrutils.live_migrate_vm( instance_name, dest, migrate_disks=not shared_storage) except Exception: with excutils.save_and_reraise_exception(): LOG.debug( "Calling live migration recover_method " "for instance: %s", instance_name) recover_method(context, instance_ref, dest, migrate_data) LOG.debug("Calling live migration post_method for instance: %s", instance_name) post_method(context, instance_ref, dest, block_migration, migrate_data)
def _test_post_live_migration(self, mock_disconnect_volumes, shared_storage=False): migrate_data = migrate_data_obj.HyperVLiveMigrateData( is_shared_instance_path=shared_storage) self._livemigrops.post_live_migration(self.context, mock.sentinel.instance, mock.sentinel.block_device_info, migrate_data) mock_disconnect_volumes.assert_called_once_with( mock.sentinel.block_device_info) mock_get_inst_dir = self._pathutils.get_instance_dir if not shared_storage: mock_get_inst_dir.assert_called_once_with( mock.sentinel.instance.name, create_dir=False, remove_dir=True) else: self.assertFalse(mock_get_inst_dir.called)
def check_can_live_migrate_destination(self, ctxt, instance_ref, src_compute_info, dst_compute_info, block_migration=False, disk_over_commit=False): LOG.debug("check_can_live_migrate_destination called", instance=instance_ref) migrate_data = migrate_data_obj.HyperVLiveMigrateData() try: # The remote instance dir might not exist or other issue to cause # OSError in check_remote_instances_dir_shared function migrate_data.is_shared_instance_path = ( self._pathutils.check_remote_instances_dir_shared( instance_ref.host)) except exception.FileNotFound as e: reason = _('Unavailable instance location: %s') % e raise exception.MigrationPreCheckError(reason=reason) return migrate_data
def _test_live_migration(self, mock_copy_dvd_disk, mock_stop_console_handler, side_effect=None, shared_storage=False, migrate_data_received=True, migrate_data_version='1.1'): mock_instance = fake_instance.fake_instance_obj(self.context) mock_post = mock.MagicMock() mock_recover = mock.MagicMock() mock_copy_logs = self._livemigrops._pathutils.copy_vm_console_logs fake_dest = mock.sentinel.DESTINATION mock_check_shared_inst_dir = ( self._pathutils.check_remote_instances_dir_shared) mock_check_shared_inst_dir.return_value = shared_storage self._livemigrops._livemigrutils.live_migrate_vm.side_effect = [ side_effect ] if migrate_data_received: migrate_data = migrate_data_obj.HyperVLiveMigrateData() if migrate_data_version != '1.0': migrate_data.is_shared_instance_path = shared_storage else: migrate_data = None if side_effect is os_win_exc.HyperVException: self.assertRaises(os_win_exc.HyperVException, self._livemigrops.live_migration, self.context, mock_instance, fake_dest, mock_post, mock_recover, mock.sentinel.block_migr, migrate_data) mock_recover.assert_called_once_with(self.context, mock_instance, fake_dest, migrate_data) else: self._livemigrops.live_migration( context=self.context, instance_ref=mock_instance, dest=fake_dest, post_method=mock_post, recover_method=mock_recover, block_migration=(mock.sentinel.block_migr), migrate_data=migrate_data) post_call_args = mock_post.call_args_list self.assertEqual(1, len(post_call_args)) post_call_args_list = post_call_args[0][0] self.assertEqual((self.context, mock_instance, fake_dest, mock.sentinel.block_migr), post_call_args_list[:-1]) # The last argument, the migrate_data object, should be created # by the callee if not received. migrate_data_arg = post_call_args_list[-1] self.assertIsInstance(migrate_data_arg, migrate_data_obj.HyperVLiveMigrateData) self.assertEqual(shared_storage, migrate_data_arg.is_shared_instance_path) if not migrate_data_received or migrate_data_version == '1.0': mock_check_shared_inst_dir.assert_called_once_with(fake_dest) else: self.assertFalse(mock_check_shared_inst_dir.called) mock_stop_console_handler.assert_called_once_with(mock_instance.name) if not shared_storage: mock_copy_logs.assert_called_once_with(mock_instance.name, fake_dest) mock_copy_dvd_disk.assert_called_once_with(mock_instance.name, fake_dest) else: self.assertFalse(mock_copy_logs.called) self.assertFalse(mock_copy_dvd_disk.called) mock_live_migr = self._livemigrops._livemigrutils.live_migrate_vm mock_live_migr.assert_called_once_with(mock_instance.name, fake_dest)
def test_obj_make_compatible(self): obj = migrate_data.HyperVLiveMigrateData(is_shared_instance_path=True) primitive = obj.obj_to_primitive(target_version='1.0') self.assertNotIn('is_shared_instance_path', primitive)