@Test public void testRemoveImageFromSnapshotConfiguration() throws OvfReaderException { Guid vmId = Guid.newGuid(); VM vm = new VM(); vm.setId(vmId); vm.setStoragePoolId(Guid.newGuid()); vm.setVmtName(RandomUtils.instance().nextString(10)); vm.setOrigin(OriginType.OVIRT); vm.setDbGeneration(1L); Guid vmSnapshotId = Guid.newGuid(); DiskImage disk1 = addTestDisk(vm, vmSnapshotId); DiskImage disk2 = addTestDisk(vm, vmSnapshotId); OvfManager ovfManager = new OvfManager(); ArrayList<DiskImage> disks = new ArrayList<DiskImage>(Arrays.asList(disk1, disk2)); String ovf = ovfManager.ExportVm(vm, disks, Version.v3_1); Snapshot snap = new Snapshot(); snap.setVmConfiguration(ovf); snap.setId(vmSnapshotId); when(snapshotDAO.get(vmSnapshotId)).thenReturn(snap); doReturn(disk2).when(cmd).getDiskImage(); doReturn(disk2).when(cmd).getImage(); doReturn(disk2.getId()).when(cmd).getImageId(); Snapshot actual = cmd.prepareSnapshotConfigWithoutImageSingleImage(vmSnapshotId, disk2.getImageId()); String actualOvf = actual.getVmConfiguration(); ArrayList<DiskImage> actualImages = new ArrayList<DiskImage>(); ovfManager.ImportVm(actualOvf, new VM(), actualImages, new ArrayList<VmNetworkInterface>()); assertEquals("Wrong number of disks", 1, actualImages.size()); assertEquals("Wrong disk", disk1, actualImages.get(0)); }
/** Adds the given vm metadata to the given map */ private String buildMetadataDictionaryForVm(VM vm) { ArrayList<DiskImage> AllVmImages = new ArrayList<DiskImage>(); List<DiskImage> filteredDisks = ImagesHandler.filterImageDisks(vm.getDiskList(), false, true, true); for (DiskImage diskImage : filteredDisks) { List<DiskImage> images = ImagesHandler.getAllImageSnapshots(diskImage.getImageId()); AllVmImages.addAll(images); } return ovfManager.ExportVm(vm, AllVmImages, ClusterUtils.getCompatibilityVersion(vm)); }