コード例 #1
0
  @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));
  }
コード例 #2
0
 @Test
 public void canAddCloneVmFromSnapshotNoConfiguration() {
   final int domainSizeGB = 15;
   final Guid sourceSnapshotId = Guid.newGuid();
   AddVmFromSnapshotCommand<AddVmFromSnapshotParameters> cmd =
       setupCanAddVmFromSnapshotTests(domainSizeGB, sourceSnapshotId);
   cmd.getVm().setName("vm1");
   mockNonInterestingMethodsForCloneVmFromSnapshot(cmd);
   SnapshotsValidator sv = spy(new SnapshotsValidator());
   doReturn(ValidationResult.VALID).when(sv).vmNotDuringSnapshot(any(Guid.class));
   doReturn(sv).when(cmd).createSnapshotsValidator();
   when(snapshotDao.get(sourceSnapshotId)).thenReturn(new Snapshot());
   ValidateTestUtils.runAndAssertValidateFailure(
       cmd, EngineMessage.ACTION_TYPE_FAILED_VM_SNAPSHOT_HAS_NO_CONFIGURATION);
 }
コード例 #3
0
 private void setUpDaoMocks() {
   when(snapshotDaoMock.getAll(vmId, getUser().getId(), getQueryParameters().isFiltered()))
       .thenReturn(Collections.singletonList(snapshot));
 }