@Before
 @Override
 public void setUp() throws Exception {
   super.setUp();
   vmID = Guid.newGuid();
   Guid snapshotId = Guid.newGuid();
   pluggedDisk = createDiskImage(true);
   unpluggedDisk = createDiskImage(true);
   pluggedDiskSnapshot = createDiskImage(false);
   pluggedDiskSnapshot.setVmSnapshotId(snapshotId);
   unpluggedDiskSnapshot = createDiskImage(false);
   unpluggedDiskSnapshot.setVmSnapshotId(snapshotId);
   setUpDaoMocks();
 }
  public static DiskImage cloneDiskImage(
      Guid storageDomainId,
      Guid newImageGroupId,
      Guid newImageGuid,
      DiskImage srcDiskImage,
      Guid diskProfileId,
      Guid snapshotId,
      DiskImage diskImageFromClient) {

    DiskImage clonedDiskImage = DiskImage.copyOf(srcDiskImage);
    clonedDiskImage.setImageId(newImageGuid);
    clonedDiskImage.setParentId(Guid.Empty);
    clonedDiskImage.setImageTemplateId(Guid.Empty);
    clonedDiskImage.setVmSnapshotId(snapshotId);
    clonedDiskImage.setId(newImageGroupId);
    clonedDiskImage.setLastModifiedDate(new Date());
    clonedDiskImage.setvolumeFormat(srcDiskImage.getVolumeFormat());
    clonedDiskImage.setVolumeType(srcDiskImage.getVolumeType());
    ArrayList<Guid> storageIds = new ArrayList<>();
    storageIds.add(storageDomainId);
    clonedDiskImage.setStorageIds(storageIds);
    clonedDiskImage.setDiskProfileId(diskProfileId);

    // If volume information was changed at client , use its volume information.
    // If volume information was not changed at client - use the volume information of the ancestral
    // image
    if (diskImageFromClient != null) {
      if (volumeInfoChanged(diskImageFromClient, srcDiskImage)) {
        changeVolumeInfo(clonedDiskImage, diskImageFromClient);
      } else {
        DiskImage ancestorDiskImage = getDiskImageDao().getAncestor(srcDiskImage.getImageId());
        changeVolumeInfo(clonedDiskImage, ancestorDiskImage);
      }
    } else {
      DiskImage ancestorDiskImage = getDiskImageDao().getAncestor(srcDiskImage.getImageId());
      changeVolumeInfo(clonedDiskImage, ancestorDiskImage);
    }

    return clonedDiskImage;
  }
  @Test
  public void nullifiedSnapshotOnUpdateDiskToShareable() {
    UpdateVmDiskParameters parameters = createParameters();
    DiskImage disk = createShareableDisk(VolumeFormat.RAW);
    parameters.setDiskInfo(disk);
    StorageDomain storage = addNewStorageDomainToDisk(disk, StorageType.NFS);
    parameters.setDiskInfo(disk);

    DiskImage oldDisk = createDiskImage();
    oldDisk.setVmSnapshotId(Guid.newGuid());

    when(diskDao.get(diskImageGuid)).thenReturn(oldDisk);
    when(storageDomainStaticDao.get(storage.getId())).thenReturn(storage.getStorageStaticData());

    initializeCommand(parameters);
    mockVdsCommandSetVolumeDescription();
    mockInterfaceList();

    CanDoActionTestUtils.runAndAssertCanDoActionSuccess(command);
    command.executeVmCommand();
    assertTrue(oldDisk.getVmSnapshotId() == null);
  }
Exemple #4
0
  @Override
  public void buildDisk() {
    XmlNodeList list = selectNodes(_document, "//*/Section/Disk");
    for (XmlNode node : list) {
      final Guid guid = new Guid(node.attributes.get("ovf:diskId").getValue());

      DiskImage image =
          _images.stream().filter(d -> d.getImageId().equals(guid)).findFirst().orElse(null);
      DiskVmElement dve = image.getDiskVmElementForVm(vmBase.getId());

      if (node.attributes.get("ovf:vm_snapshot_id") != null) {
        image.setVmSnapshotId(new Guid(node.attributes.get("ovf:vm_snapshot_id").getValue()));
      }

      if (!StringUtils.isEmpty(node.attributes.get("ovf:size").getValue())) {
        image.setSize(
            convertGigabyteToBytes(Long.parseLong(node.attributes.get("ovf:size").getValue())));
      }
      if (!StringUtils.isEmpty(node.attributes.get("ovf:actual_size").getValue())) {
        image.setActualSizeInBytes(
            convertGigabyteToBytes(
                Long.parseLong(node.attributes.get("ovf:actual_size").getValue())));
      }
      if (node.attributes.get("ovf:volume-format") != null) {
        if (!StringUtils.isEmpty(node.attributes.get("ovf:volume-format").getValue())) {
          image.setVolumeFormat(
              VolumeFormat.valueOf(node.attributes.get("ovf:volume-format").getValue()));
        } else {
          image.setVolumeFormat(VolumeFormat.Unassigned);
        }
      } else {
        image.setVolumeFormat(VolumeFormat.Unassigned);
      }

      if (image.isQcowFormat()) {
        if (node.attributes.get("ovf:qcow-compat") != null
            && StringUtils.isNotEmpty(node.attributes.get("ovf:qcow-compat").getValue())) {
          image.setQcowCompat(
              QcowCompat.valueOf(node.attributes.get("ovf:qcow-compat").getValue()));
        } else {
          image.setQcowCompat(QcowCompat.QCOW2_V2);
        }
      }
      if (node.attributes.get("ovf:volume-type") != null) {
        if (!StringUtils.isEmpty(node.attributes.get("ovf:volume-type").getValue())) {
          image.setVolumeType(
              VolumeType.valueOf(node.attributes.get("ovf:volume-type").getValue()));
        } else {
          image.setVolumeType(VolumeType.Unassigned);
        }
      } else {
        image.setVolumeType(VolumeType.Unassigned);
      }
      if (node.attributes.get("ovf:disk-interface") != null) {
        if (!StringUtils.isEmpty(node.attributes.get("ovf:disk-interface").getValue())) {
          dve.setDiskInterface(
              DiskInterface.valueOf(node.attributes.get("ovf:disk-interface").getValue()));
        }
      } else {
        dve.setDiskInterface(DiskInterface.IDE);
      }
      if (node.attributes.get("ovf:boot") != null) {
        if (!StringUtils.isEmpty(node.attributes.get("ovf:boot").getValue())) {
          dve.setBoot(Boolean.parseBoolean(node.attributes.get("ovf:boot").getValue()));
        }
      }
      if (node.attributes.get("ovf:pass-discard") != null) {
        if (!StringUtils.isEmpty(node.attributes.get("ovf:pass-discard").getValue())) {
          dve.setPassDiscard(
              Boolean.parseBoolean(node.attributes.get("ovf:pass-discard").getValue()));
        }
      }
      if (node.attributes.get("ovf:wipe-after-delete") != null) {
        if (!StringUtils.isEmpty(node.attributes.get("ovf:wipe-after-delete").getValue())) {
          image.setWipeAfterDelete(
              Boolean.parseBoolean(node.attributes.get("ovf:wipe-after-delete").getValue()));
        }
      }
      if (node.attributes.get("ovf:disk-alias") != null) {
        if (!StringUtils.isEmpty(node.attributes.get("ovf:disk-alias").getValue())) {
          image.setDiskAlias(String.valueOf(node.attributes.get("ovf:disk-alias").getValue()));
        }
      }
      if (node.attributes.get("ovf:disk-description") != null) {
        if (!StringUtils.isEmpty(node.attributes.get("ovf:disk-description").getValue())) {
          image.setDiskDescription(
              String.valueOf(node.attributes.get("ovf:disk-description").getValue()));
        }
      }
    }
  }