def _test_check_ephemeral_disks(self, exc, resize): mock_ephemerals = [dict(), dict()] mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance.ephemeral_gb = 2 mock_pathutils = self._migrationops._pathutils mock_lookup_eph_path = mock_pathutils.lookup_ephemeral_vhd_path mock_lookup_eph_path.side_effect = [mock.sentinel.PATH0, None] mock_get_eph_vhd_path = mock_pathutils.get_ephemeral_vhd_path mock_get_eph_vhd_path.return_value = mock.sentinel.PATH1 mock_vhdutils = self._migrationops._vhdutils mock_get_vhd_format = mock_vhdutils.get_best_supported_vhd_format mock_get_vhd_format.return_value = mock.sentinel.VHD_FORMAT if exc: self.assertRaises(exception.DiskNotFound, self._migrationops._check_ephemeral_disks, mock_instance, mock_ephemerals) else: self._migrationops._check_ephemeral_disks(mock_instance, mock_ephemerals, resize) self.assertEqual(mock.sentinel.PATH0, mock_ephemerals[0]['path']) if resize: self.assertEqual(mock.sentinel.PATH1, mock_ephemerals[1]['path']) mock_get_vhd_format.assert_called_once_with() self.assertEqual(mock.sentinel.VHD_FORMAT, mock_ephemerals[1]['format']) self.assertEqual(mock_instance.ephemeral_gb * units.Gi, mock_ephemerals[1]['size']) mock_vmops = self._migrationops._vmops mock_vmops._create_ephemeral_disk.assert_called_once_with( mock_instance.name, mock_ephemerals[1])
def _test_pre_live_migration(self, mock_connect_volumes, mock_get_cached_image, mock_get_disk_path_mapping, phys_disks_attached=True): mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance.image_ref = "fake_image_ref" bdman = self._livemigrops._block_dev_man mock_is_boot_from_vol = bdman.is_boot_from_volume mock_is_boot_from_vol.return_value = None mock_get_disk_path_mapping.return_value = ( mock.sentinel.disk_path_mapping if phys_disks_attached else None) CONF.set_override('use_cow_images', True) self._livemigrops.pre_live_migration( self.context, mock_instance, block_device_info=mock.sentinel.BLOCK_INFO, network_info=mock.sentinel.NET_INFO) check_config = ( self._livemigrops._livemigrutils.check_live_migration_config) check_config.assert_called_once_with() mock_is_boot_from_vol.assert_called_once_with( mock.sentinel.BLOCK_INFO) mock_get_cached_image.assert_called_once_with(self.context, mock_instance) mock_connect_volumes.assert_called_once_with( mock.sentinel.BLOCK_INFO) if phys_disks_attached: livemigrutils = self._livemigrops._livemigrutils livemigrutils.create_planned_vm.assert_called_once_with( mock_instance.name, mock_instance.host, mock.sentinel.disk_path_mapping)
def _test_check_target_flavor(self, root_gb, bdi): mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance.root_gb = root_gb mock_flavor = mock.MagicMock(root_gb=1, ephemeral_gb=1) self.assertRaises(exception.InstanceFaultRollback, self._migrationops._check_target_flavor, mock_instance, mock_flavor, bdi)
def test_get_instance_by_name(self, mock_get_by_uuid): mock_instance = fake_instance.fake_instance_obj(self.context) mock_get_by_uuid.return_value = mock_instance self.clusterops._instance_map[mock_instance.name] = mock_instance.uuid ret = self.clusterops._get_instance_by_name(mock_instance.name) self.assertEqual(ret, mock_instance)
def test_remove_from_cluster_exception(self, mock_LOG): mock_instance = fake_instance.fake_instance_obj(self.context) mock_delete = self.clusterops._clustutils.delete mock_delete.side_effect = os_win_exc.HyperVClusterException self.clusterops.remove_from_cluster(mock_instance) self.assertTrue(mock_LOG.exception.called)
def _test_pre_live_migration(self, mock_connect_volumes, mock_get_cached_image, mock_get_disk_path_mapping, phys_disks_attached=True): mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance.image_ref = "fake_image_ref" mock_get_disk_path_mapping.return_value = ( mock.sentinel.disk_path_mapping if phys_disks_attached else None) bdman = self._livemigrops._block_dev_man mock_is_boot_from_vol = bdman.is_boot_from_volume mock_is_boot_from_vol.return_value = None CONF.set_override('use_cow_images', True) self._livemigrops.pre_live_migration( self.context, mock_instance, block_device_info=mock.sentinel.BLOCK_INFO, network_info=mock.sentinel.NET_INFO) check_config = ( self._livemigrops._livemigrutils.check_live_migration_config) check_config.assert_called_once_with() mock_is_boot_from_vol.assert_called_once_with(mock.sentinel.BLOCK_INFO) mock_get_cached_image.assert_called_once_with(self.context, mock_instance) mock_connect_volumes.assert_called_once_with(mock.sentinel.BLOCK_INFO) mock_get_disk_path_mapping.assert_called_once_with( mock.sentinel.BLOCK_INFO, block_dev_only=True) if phys_disks_attached: livemigrutils = self._livemigrops._livemigrutils livemigrutils.create_planned_vm.assert_called_once_with( mock_instance.name, mock_instance.host, mock.sentinel.disk_path_mapping)
def _test_live_migration(self, mock_get_vm_dvd_paths, mock_stop_console_handler, side_effect): mock_instance = fake_instance.fake_instance_obj(self.context) mock_post = mock.MagicMock() mock_recover = mock.MagicMock() fake_dest = mock.sentinel.DESTINATION self._livemigrops._livemigrutils.live_migrate_vm.side_effect = [ side_effect] if side_effect is vmutils.HyperVException: self.assertRaises(vmutils.HyperVException, self._livemigrops.live_migration, self.context, mock_instance, fake_dest, mock_post, mock_recover, False, None) mock_recover.assert_called_once_with(self.context, mock_instance, fake_dest, False) else: self._livemigrops.live_migration(context=self.context, instance_ref=mock_instance, dest=fake_dest, post_method=mock_post, recover_method=mock_recover) mock_stop_console_handler.assert_called_once_with( mock_instance.name) mock_copy_logs = self._livemigrops._pathutils.copy_vm_console_logs mock_copy_logs.assert_called_once_with(mock_instance.name, fake_dest) mock_live_migr = self._livemigrops._livemigrutils.live_migrate_vm mock_live_migr.assert_called_once_with(mock_instance.name, fake_dest) mock_post.assert_called_once_with(self.context, mock_instance, fake_dest, False)
def test_post_migration(self): mock_instance = fake_instance.fake_instance_obj(self.context) self.clusterops.post_migration(mock_instance) self.assertEqual( self.clusterops._instance_map[mock_instance.name], mock_instance.uuid)
def test_migrate_disk_and_power_off(self, mock_check_flavor, mock_migrate_disk_files): instance = fake_instance.fake_instance_obj(self.context) flavor = mock.MagicMock() network_info = mock.MagicMock() disk_files = [mock.MagicMock()] volume_drives = [mock.MagicMock()] mock_get_vm_st_path = self._migrationops._vmutils.get_vm_storage_paths mock_get_vm_st_path.return_value = (disk_files, volume_drives) self._migrationops.migrate_disk_and_power_off( self.context, instance, mock.sentinel.FAKE_DEST, flavor, network_info, mock.sentinel.fake_bdi, self._FAKE_TIMEOUT, self._FAKE_RETRY_INTERVAL) mock_check_flavor.assert_called_once_with(instance, flavor, mock.sentinel.fake_bdi) self._migrationops._vmops.power_off.assert_called_once_with( instance, self._FAKE_TIMEOUT, self._FAKE_RETRY_INTERVAL) mock_get_vm_st_path.assert_called_once_with(instance.name) mock_migrate_disk_files.assert_called_once_with( instance.name, disk_files, mock.sentinel.FAKE_DEST) self._migrationops._vmops.destroy.assert_called_once_with( instance, destroy_disks=False)
def test_check_target_flavor(self): mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance.flavor.root_gb = 1 mock_flavor = mock.MagicMock(root_gb=0) self.assertRaises(exception.InstanceFaultRollback, self._migrationops._check_target_flavor, mock_instance, mock_flavor)
def test_add_to_cluster_exception(self, mock_LOG): mock_instance = fake_instance.fake_instance_obj(self.context) mock_add_vm = self.clusterops._clustutils.add_vm_to_cluster mock_add_vm.side_effect = os_win_exc.HyperVClusterException self.clusterops.add_to_cluster(mock_instance) self.assertTrue(mock_LOG.exception.called)
def _test_live_migration(self, mock_get_vm_dvd_paths, mock_stop_console_handler, side_effect): mock_instance = fake_instance.fake_instance_obj(self.context) mock_post = mock.MagicMock() mock_recover = mock.MagicMock() fake_dest = mock.sentinel.DESTINATION self._livemigrops._livemigrutils.live_migrate_vm.side_effect = [ side_effect ] if side_effect is vmutils.HyperVException: self.assertRaises(vmutils.HyperVException, self._livemigrops.live_migration, self.context, mock_instance, fake_dest, mock_post, mock_recover, False, None) mock_recover.assert_called_once_with(self.context, mock_instance, fake_dest, False) else: self._livemigrops.live_migration(context=self.context, instance_ref=mock_instance, dest=fake_dest, post_method=mock_post, recover_method=mock_recover) mock_stop_console_handler.assert_called_once_with( mock_instance.name) mock_copy_logs = self._livemigrops._pathutils.copy_vm_console_logs mock_copy_logs.assert_called_once_with(mock_instance.name, fake_dest) mock_live_migr = self._livemigrops._livemigrutils.live_migrate_vm mock_live_migr.assert_called_once_with(mock_instance.name, fake_dest) mock_post.assert_called_once_with(self.context, mock_instance, fake_dest, False)
def test_failover_migrate_networks(self): mock_instance = fake_instance.fake_instance_obj(self.context) fake_source = mock.MagicMock() fake_migration = { 'source_compute': fake_source, 'dest_compute': self.clusterops._this_node } self.clusterops._failover_migrate_networks(mock_instance, fake_source) mock_network_api = self.clusterops._network_api calls = [ mock.call(self.clusterops._context, mock_instance, self.clusterops._this_node), mock.call(self.clusterops._context, mock_instance, self.clusterops._this_node), mock.call(self.clusterops._context, mock_instance, self.clusterops._this_node), mock.call(self.clusterops._context, mock_instance, fake_source, teardown=True) ] mock_network_api.setup_networks_on_host.assert_has_calls(calls) mock_network_api.migrate_instance_start.assert_called_once_with( self.clusterops._context, mock_instance, fake_migration) mock_network_api.migrate_instance_finish.assert_called_once_with( self.clusterops._context, mock_instance, fake_migration)
def _test_snapshot(self, mock_save_glance_image, base_disk_path): mock_instance = fake_instance.fake_instance_obj(self.context) mock_update = mock.MagicMock() fake_src_path = os.path.join('fake', 'path') self._snapshotops._pathutils.lookup_root_vhd_path.return_value = ( fake_src_path) fake_exp_dir = os.path.join(os.path.join('fake', 'exp'), 'dir') self._snapshotops._pathutils.get_export_dir.return_value = fake_exp_dir self._snapshotops._vhdutils.get_vhd_parent_path.return_value = ( base_disk_path) fake_snapshot_path = ( self._snapshotops._vmutils.take_vm_snapshot.return_value) self._snapshotops.snapshot(context=self.context, instance=mock_instance, image_id=mock.sentinel.IMAGE_ID, update_task_state=mock_update) self._snapshotops._vmutils.take_vm_snapshot.assert_called_once_with( mock_instance.name) mock_lookup_path = self._snapshotops._pathutils.lookup_root_vhd_path mock_lookup_path.assert_called_once_with(mock_instance.name) mock_get_vhd_path = self._snapshotops._vhdutils.get_vhd_parent_path mock_get_vhd_path.assert_called_once_with(fake_src_path) self._snapshotops._pathutils.get_export_dir.assert_called_once_with( mock_instance.name) expected = [ mock.call( fake_src_path, os.path.join(fake_exp_dir, os.path.basename(fake_src_path))) ] dest_vhd_path = os.path.join(fake_exp_dir, os.path.basename(fake_src_path)) if base_disk_path: basename = os.path.basename(base_disk_path) base_dest_disk_path = os.path.join(fake_exp_dir, basename) expected.append(mock.call(base_disk_path, base_dest_disk_path)) mock_reconnect = self._snapshotops._vhdutils.reconnect_parent_vhd mock_reconnect.assert_called_once_with(dest_vhd_path, base_dest_disk_path) self._snapshotops._vhdutils.merge_vhd.assert_called_once_with( dest_vhd_path, base_dest_disk_path) mock_save_glance_image.assert_called_once_with( self.context, mock.sentinel.IMAGE_ID, base_dest_disk_path) else: mock_save_glance_image.assert_called_once_with( self.context, mock.sentinel.IMAGE_ID, dest_vhd_path) self._snapshotops._pathutils.copyfile.has_calls(expected) expected_update = [ mock.call(task_state=task_states.IMAGE_PENDING_UPLOAD), mock.call(task_state=task_states.IMAGE_UPLOADING, expected_state=task_states.IMAGE_PENDING_UPLOAD) ] mock_update.has_calls(expected_update) self._snapshotops._vmutils.remove_vm_snapshot.assert_called_once_with( fake_snapshot_path) self._snapshotops._pathutils.rmtree.assert_called_once_with( fake_exp_dir)
def test_add_to_cluster(self): mock_instance = fake_instance.fake_instance_obj(self.context) self.clusterops.add_to_cluster(mock_instance) mock_add_vm = self.clusterops._clustutils.add_vm_to_cluster mock_add_vm.assert_called_once_with(mock_instance.name) self.assertEqual(mock_instance.uuid, self.clusterops._instance_map[mock_instance.name])
def test_remove_from_cluster(self): mock_instance = fake_instance.fake_instance_obj(self.context) self.clusterops.remove_from_cluster(mock_instance) self.clusterops._clustutils.delete.assert_called_once_with( mock_instance.name) self.assertIsNone(self.clusterops._instance_map.get( mock_instance.name))
def setUp(self): super(ImageCacheTestCase, self).setUp() self.context = 'fake-context' self.instance = fake_instance.fake_instance_obj(self.context) self.imagecache = imagecache.ImageCache() self.imagecache._pathutils = mock.MagicMock() self.imagecache._vhdutils = mock.MagicMock()
def test_confirm_migration(self): mock_instance = fake_instance.fake_instance_obj(self.context) self._migrationops.confirm_migration( migration=mock.sentinel.migration, instance=mock_instance, network_info=mock.sentinel.network_info) get_instance_migr_revert_dir = ( self._migrationops._pathutils.get_instance_migr_revert_dir) get_instance_migr_revert_dir.assert_called_with(mock_instance.name, remove_dir=True)
def test_check_and_attach_config_drive_unknown_path(self): instance = fake_instance.fake_instance_obj( self.context, expected_attrs=['system_metadata']) instance.config_drive = 'True' self._migrationops._pathutils.lookup_configdrive_path.return_value = ( None) self.assertRaises(exception.ConfigDriveNotFound, self._migrationops._check_and_attach_config_drive, instance, mock.sentinel.FAKE_VM_GEN)
def _test_snapshot(self, mock_save_glance_image, base_disk_path): mock_instance = fake_instance.fake_instance_obj(self.context) mock_update = mock.MagicMock() fake_src_path = os.path.join('fake', 'path') self._snapshotops._pathutils.lookup_root_vhd_path.return_value = ( fake_src_path) fake_exp_dir = os.path.join(os.path.join('fake', 'exp'), 'dir') self._snapshotops._pathutils.get_export_dir.return_value = fake_exp_dir self._snapshotops._vhdutils.get_vhd_parent_path.return_value = ( base_disk_path) fake_snapshot_path = ( self._snapshotops._vmutils.take_vm_snapshot.return_value) self._snapshotops.snapshot(context=self.context, instance=mock_instance, image_id=mock.sentinel.IMAGE_ID, update_task_state=mock_update) self._snapshotops._vmutils.take_vm_snapshot.assert_called_once_with( mock_instance.name) mock_lookup_path = self._snapshotops._pathutils.lookup_root_vhd_path mock_lookup_path.assert_called_once_with(mock_instance.name) mock_get_vhd_path = self._snapshotops._vhdutils.get_vhd_parent_path mock_get_vhd_path.assert_called_once_with(fake_src_path) self._snapshotops._pathutils.get_export_dir.assert_called_once_with( mock_instance.name) expected = [mock.call(fake_src_path, os.path.join(fake_exp_dir, os.path.basename(fake_src_path)))] dest_vhd_path = os.path.join(fake_exp_dir, os.path.basename(fake_src_path)) if base_disk_path: basename = os.path.basename(base_disk_path) base_dest_disk_path = os.path.join(fake_exp_dir, basename) expected.append(mock.call(base_disk_path, base_dest_disk_path)) mock_reconnect = self._snapshotops._vhdutils.reconnect_parent_vhd mock_reconnect.assert_called_once_with(dest_vhd_path, base_dest_disk_path) self._snapshotops._vhdutils.merge_vhd.assert_called_once_with( dest_vhd_path) mock_save_glance_image.assert_called_once_with( self.context, mock.sentinel.IMAGE_ID, base_dest_disk_path) else: mock_save_glance_image.assert_called_once_with( self.context, mock.sentinel.IMAGE_ID, dest_vhd_path) self._snapshotops._pathutils.copyfile.has_calls(expected) expected_update = [ mock.call(task_state=task_states.IMAGE_PENDING_UPLOAD), mock.call(task_state=task_states.IMAGE_UPLOADING, expected_state=task_states.IMAGE_PENDING_UPLOAD)] mock_update.has_calls(expected_update) self._snapshotops._vmutils.remove_vm_snapshot.assert_called_once_with( fake_snapshot_path) self._snapshotops._pathutils.rmtree.assert_called_once_with( fake_exp_dir)
def test_finish_revert_migration_no_root_vhd(self): mock_instance = fake_instance.fake_instance_obj(self.context) self._migrationops._pathutils.lookup_root_vhd_path.return_value = None bdi = {'root_disk': {'type': constants.DISK}, 'ephemerals': []} self.assertRaises( exception.DiskNotFound, self._migrationops.finish_revert_migration, self.context, mock_instance, mock.sentinel.network_info, bdi, True)
def test_get_instance_by_name_not_in_cache(self, mock_get_by_uuid): mock_instance = fake_instance.fake_instance_obj(self.context) self.clusterops._vmutils.get_instance_uuid.return_value = ( mock_instance.uuid) mock_get_by_uuid.return_value = mock_instance ret = self.clusterops._get_instance_by_name(mock_instance.name) self.assertEqual(ret, mock_instance) self.assertEqual(mock_instance.uuid, self.clusterops._instance_map[mock_instance.name])
def test_check_ephemeral_disks_exception(self): mock_instance = fake_instance.fake_instance_obj(self.context) mock_ephemerals = [dict()] lookup_eph_path = ( self._migrationops._pathutils.lookup_ephemeral_vhd_path) lookup_eph_path.return_value = None self.assertRaises(exception.DiskNotFound, self._migrationops._check_ephemeral_disks, mock_instance, mock_ephemerals)
def setUp(self): super(HyperVOVSVIFDriverTestCase, self).setUp() self.context = 'fake-context' self.instance = fake_instance.fake_instance_obj(self.context) self._vif = vif.HyperVOVSVIFDriver() self._vif._vmutils = mock.MagicMock() self._vif._netutils = mock.MagicMock() self._fake_vif = dict(test_virtual_interface.fake_vif, network={'bridge': 'fake_bridge'})
def _check_finish_migration(self, mock_check_eph_disks, mock_check_resize_vhd, mock_check_base_disk, mock_check_attach_config_drive, disk_type=constants.DISK): mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance.flavor.ephemeral_gb = 1 root_device = {'type': disk_type} block_device_info = {'root_disk': root_device, 'ephemerals': []} lookup_root_vhd = self._migrationops._pathutils.lookup_root_vhd_path get_vhd_info = self._migrationops._vhdutils.get_vhd_info mock_vhd_info = get_vhd_info.return_value expected_check_resize = [] expected_get_info = [] self._migrationops.finish_migration( context=self.context, migration=mock.sentinel.migration, instance=mock_instance, disk_info=mock.sentinel.disk_info, network_info=mock.sentinel.network_info, image_meta=mock.sentinel.image_meta, resize_instance=True, block_device_info=block_device_info) if root_device['type'] == constants.DISK: root_device_path = lookup_root_vhd.return_value lookup_root_vhd.assert_called_with(mock_instance.name) expected_get_info = [mock.call(root_device_path)] mock_vhd_info.get.assert_called_once_with("ParentPath") mock_check_base_disk.assert_called_once_with( self.context, mock_instance, root_device_path, mock_vhd_info.get.return_value) expected_check_resize.append( mock.call(root_device_path, mock_vhd_info, mock_instance.flavor.root_gb * units.Gi)) ephemerals = block_device_info['ephemerals'] mock_check_eph_disks.assert_called_once_with( mock_instance, ephemerals, True) mock_check_resize_vhd.assert_has_calls(expected_check_resize) self._migrationops._vhdutils.get_vhd_info.assert_has_calls( expected_get_info) get_image_vm_gen = self._migrationops._vmops.get_image_vm_generation get_image_vm_gen.assert_called_once_with(mock_instance.uuid, mock.sentinel.image_meta) self._migrationops._vmops.create_instance.assert_called_once_with( self.context, mock_instance, mock.sentinel.network_info, root_device, block_device_info, get_image_vm_gen.return_value, mock.sentinel.image_meta) mock_check_attach_config_drive.assert_called_once_with( mock_instance, get_image_vm_gen.return_value) self._migrationops._vmops.power_on.assert_called_once_with( mock_instance)
def test_finish_migration_no_root(self): root_device = {'type': constants.DISK} bdi = {'root_disk': root_device, 'ephemerals': []} mock_instance = fake_instance.fake_instance_obj(self.context) self._migrationops._pathutils.lookup_root_vhd_path.return_value = None self.assertRaises(exception.DiskNotFound, self._migrationops.finish_migration, self.context, mock.sentinel.migration, mock_instance, mock.sentinel.disk_info, mock.sentinel.network_info, mock.sentinel.image_meta, True, bdi, True)
def test_finish_migration_no_root(self): mock_instance = fake_instance.fake_instance_obj(self.context) mock_ebs_root_in_block_devices = ( self._migrationops._volumeops.ebs_root_in_block_devices) mock_ebs_root_in_block_devices.return_value = False self._migrationops._pathutils.lookup_root_vhd_path.return_value = None self.assertRaises(vmutils.HyperVException, self._migrationops.finish_migration, self.context, mock.sentinel.migration, mock_instance, mock.sentinel.disk_info, mock.sentinel.network_info, mock.sentinel.image_meta, True, None, True)
def test_check_and_attach_config_drive(self): mock_instance = fake_instance.fake_instance_obj( self.context, expected_attrs=['system_metadata']) mock_instance.config_drive = 'True' self._migrationops._check_and_attach_config_drive( mock_instance, mock.sentinel.vm_gen) self._migrationops._vmops.attach_config_drive.assert_called_once_with( mock_instance, self._migrationops._pathutils.lookup_configdrive_path.return_value, mock.sentinel.vm_gen)
def test_snapshot_instance_not_found(self, mock_snapshot): mock_instance = fake_instance.fake_instance_obj(self.context) mock_snapshot.side_effect = os_win_exc.HyperVVMNotFoundException( vm_name=mock_instance.name) self.assertRaises(exception.InstanceNotFound, self._snapshotops.snapshot, self.context, mock_instance, mock.sentinel.image_id, mock.sentinel.update_task_state) mock_snapshot.assert_called_once_with(self.context, mock_instance, mock.sentinel.image_id, mock.sentinel.update_task_state)
def test_get_instance_by_name_not_update_map(self, mock_get_by_uuid): mock_instance = fake_instance.fake_instance_obj(self.context) self.clusterops._vmutils.get_instance_uuid.side_effect = ( os_win_exc.HyperVVMNotFoundException(vm_name=mock_instance.name)) self.clusterops._update_instance_map = mock.MagicMock() self.clusterops._instance_map = mock.MagicMock() self.clusterops._instance_map.get.side_effect = [None, mock_instance.uuid] mock_get_by_uuid.return_value = mock_instance ret = self.clusterops._get_instance_by_name(mock_instance.name) self.assertEqual(ret, mock_instance) self.clusterops._update_instance_map.assert_called_with()
def test_check_ephemeral_disks_multiple_eph_warn(self, mock_warn, mock_check_resize_vhd): mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance.ephemeral_gb = 3 mock_ephemerals = [{'size': 1}, {'size': 1}] self._migrationops._check_ephemeral_disks(mock_instance, mock_ephemerals, True) mock_warn.assert_called_once_with( "Cannot resize multiple ephemeral disks for instance.", instance=mock_instance)
def test_check_can_live_migrate_destination(self, mock_migr_data_cls): mock_instance = fake_instance.fake_instance_obj(self.context) migr_data = self._livemigrops.check_can_live_migrate_destination( mock.sentinel.context, mock_instance, mock.sentinel.src_comp_info, mock.sentinel.dest_comp_info) mock_check_shared_inst_dir = ( self._pathutils.check_remote_instances_dir_shared) mock_check_shared_inst_dir.assert_called_once_with(mock_instance.host) self.assertEqual(mock_migr_data_cls.return_value, migr_data) self.assertEqual(mock_check_shared_inst_dir.return_value, migr_data.is_shared_instance_path)
def test_finish_migration_no_root(self): root_device = {'type': constants.DISK} bdi = {'root_disk': root_device, 'ephemerals': [] } mock_instance = fake_instance.fake_instance_obj(self.context) self._migrationops._pathutils.lookup_root_vhd_path.return_value = None self.assertRaises(exception.DiskNotFound, self._migrationops.finish_migration, self.context, mock.sentinel.migration, mock_instance, mock.sentinel.disk_info, mock.sentinel.network_info, mock.sentinel.image_meta, True, bdi, True)
def test_check_base_disk(self): mock_instance = fake_instance.fake_instance_obj(self.context) fake_src_vhd_path = 'fake/src/path' fake_base_vhd = 'fake/vhd' get_cached_image = self._migrationops._imagecache.get_cached_image get_cached_image.return_value = fake_base_vhd self._migrationops._check_base_disk( context=self.context, instance=mock_instance, diff_vhd_path=mock.sentinel.diff_vhd_path, src_base_disk_path=fake_src_vhd_path) get_cached_image.assert_called_once_with(self.context, mock_instance) recon_parent_vhd = self._migrationops._vhdutils.reconnect_parent_vhd recon_parent_vhd.assert_called_once_with( mock.sentinel.diff_vhd_path, fake_base_vhd)
def test_live_migration_outside_cluster(self, mock_super_live_migration): mock_instance = fake_instance.fake_instance_obj(self._fake_context) self.livemigrops._clustutils.vm_exists.return_value = True dest = 'fake_dest' node_names = ['fake_node1', 'fake_node2'] get_nodes = self.livemigrops._clustutils.get_cluster_node_names get_nodes.return_value = node_names self.livemigrops.live_migration( self._fake_context, mock_instance, dest, mock.sentinel.post_method, mock.sentinel.recover_method, block_migration=False, migrate_data=None) mock_super_live_migration.assert_called_once_with( self._fake_context, mock_instance, dest, mock.sentinel.post_method, mock.sentinel.recover_method, False, None)
def setUp(self): super(ImageCacheTestCase, self).setUp() self.context = 'fake-context' self.instance = fake_instance.fake_instance_obj(self.context) # utilsfactory will check the host OS version via get_hostutils, # in order to return the proper Utils Class, so it must be mocked. patched_func = mock.patch.object(imagecache.utilsfactory, "get_hostutils") patched_get_pathutils = mock.patch.object(imagecache.utilsfactory, "get_pathutils") patched_func.start() patched_get_pathutils.start() self.addCleanup(patched_func.stop) self.addCleanup(patched_get_pathutils.stop) self.imagecache = imagecache.ImageCache() self.imagecache._pathutils = mock.MagicMock() self.imagecache._vhdutils = mock.MagicMock()
def test_pre_live_migration(self, mock_initialize_connection, mock_get_cached_image, mock_ebs_root_in_block_devices): mock_instance = fake_instance.fake_instance_obj(self.context) mock_instance.image_ref = "fake_image_ref" mock_ebs_root_in_block_devices.return_value = None CONF.set_override('use_cow_images', True) self._livemigrops.pre_live_migration( self.context, mock_instance, block_device_info=mock.sentinel.BLOCK_INFO, network_info=mock.sentinel.NET_INFO) check_config = ( self._livemigrops._livemigrutils.check_live_migration_config) check_config.assert_called_once_with() mock_ebs_root_in_block_devices.assert_called_once_with( mock.sentinel.BLOCK_INFO) mock_get_cached_image.assert_called_once_with(self.context, mock_instance) mock_initialize_connection.assert_called_once_with( mock.sentinel.BLOCK_INFO)