Exemplo n.º 1
0
 @Test
 public void testValidateOvfDiskNotIllegal() {
   ((DiskImage) disk).setImageStatus(ImageStatus.OK);
   disk.setContentType(DiskContentType.OVF_STORE);
   ValidateTestUtils.runAndAssertValidateFailure(
       cmd, EngineMessage.ACTION_TYPE_FAILED_OVF_DISK_NOT_IN_APPLICABLE_STATUS);
 }
Exemplo n.º 2
0
  private void buildImageReference() {
    XmlNodeList list = selectNodes(_document, "//*/File", _xmlNS);
    for (XmlNode node : list) {
      // If the disk storage type is Cinder then override the disk image with Cinder object,
      // otherwise use the disk image.
      DiskImage disk = new DiskImage();

      // If the OVF is old and does not contain any storage type reference then we assume we can
      // only have disk image.
      if (node.attributes.get("ovf:disk_storage_type") != null) {
        String diskStorageType = node.attributes.get("ovf:disk_storage_type").getValue();
        if (diskStorageType != null && diskStorageType.equals(DiskStorageType.CINDER.name())) {
          disk = new CinderDisk();
          if (node.attributes.get("ovf:cinder_volume_type") != null) {
            String cinderVolumeType = node.attributes.get("ovf:cinder_volume_type").getValue();
            disk.setCinderVolumeType(cinderVolumeType);
          }
        }
      }
      disk.setImageId(new Guid(node.attributes.get("ovf:id").getValue()));
      disk.setId(
          OvfParser.getImageGroupIdFromImageFile(node.attributes.get("ovf:href").getValue()));
      // Default values:
      disk.setActive(true);
      disk.setImageStatus(ImageStatus.OK);
      disk.setDescription(node.attributes.get("ovf:description").getValue());

      disk.setDiskVmElements(
          Collections.singletonList(new DiskVmElement(disk.getId(), vmBase.getId())));

      _images.add(disk);
    }
  }
 private DiskImage createDiskSnapshot(Guid diskId) {
   DiskImage di = new DiskImage();
   di.setActive(false);
   di.setId(diskId);
   di.setImageId(Guid.newGuid());
   di.setParentId(Guid.newGuid());
   di.setImageStatus(ImageStatus.OK);
   return di;
 }
 private DiskImage createDiskImage(boolean active) {
   DiskImage di = new DiskImage();
   di.setId(Guid.newGuid());
   di.setImageId(Guid.newGuid());
   di.setParentId(Guid.newGuid());
   di.setImageStatus(ImageStatus.OK);
   di.setActive(active);
   return di;
 }
Exemplo n.º 5
0
  @Before
  public void setUp() {
    vmId = Guid.newGuid();
    diskId = Guid.newGuid();
    poolId = Guid.newGuid();
    storageDomainId = Guid.newGuid();
    groupId = Guid.newGuid();
    vdsId = Guid.newGuid();

    disk = new DiskImage();
    disk.setId(diskId);
    disk.setVmEntityType(VmEntityType.VM);
    disk.setImageStatus(ImageStatus.OK);
    disk.setStorageIds(new ArrayList<>(Arrays.asList(storageDomainId)));

    vm = new VM();
    vm.setId(vmId);
    vm.setStatus(VMStatus.Down);
    vm.setStoragePoolId(poolId);
    vm.setClusterId(groupId);

    VmDeviceId vmDeviceId = new VmDeviceId(diskId, vmId);
    vmDevice = new VmDevice();
    vmDevice.setId(vmDeviceId);

    cluster = new Cluster();
    cluster.setId(groupId);

    vds = new VDS();
    vds.setId(vdsId);

    storagePool = new StoragePool();
    storagePool.setStatus(StoragePoolStatus.Up);

    storageDomain = new StorageDomain();
    storageDomain.setStorageType(StorageType.ISCSI);

    when(vmDao.getVmsListForDisk(diskId, Boolean.FALSE)).thenReturn(Collections.singletonList(vm));
    when(vmDeviceDao.get(vmDeviceId)).thenReturn(vmDevice);
    when(vdsDao.getAllForClusterWithStatus(groupId, VDSStatus.Up))
        .thenReturn(Collections.singletonList(vds));
    when(spDao.get(poolId)).thenReturn(storagePool);
    when(clusterDao.get(groupId)).thenReturn(cluster);
    when(storageDomainStaticDao.get(storageDomainId))
        .thenReturn(storageDomain.getStorageStaticData());

    cmd = spy(new GetDiskAlignmentCommand<>(new GetDiskAlignmentParameters(diskId), null));

    doReturn(disk).when(cmd).getDisk();
    doReturn(vdsDao).when(cmd).getVdsDao();
    doReturn(vmDao).when(cmd).getVmDao();
    doReturn(spDao).when(cmd).getStoragePoolDao();
    doReturn(clusterDao).when(cmd).getClusterDao();
    doReturn(storageDomainStaticDao).when(cmd).getStorageDomainStaticDao();
  }
Exemplo n.º 6
0
 protected List<DiskImage> createDiskSnapshot(Guid diskId, int numOfImages) {
   List<DiskImage> disksList = new ArrayList<>();
   for (int i = 0; i < numOfImages; ++i) {
     DiskImage diskImage = new DiskImage();
     diskImage.setActive(false);
     diskImage.setId(diskId);
     diskImage.setImageId(Guid.newGuid());
     diskImage.setParentId(Guid.newGuid());
     diskImage.setImageStatus(ImageStatus.OK);
     disksList.add(diskImage);
   }
   return disksList;
 }
  public static void updateAllDiskImagesSnapshotsStatusInTransactionWithCompensation(
      final Collection<Guid> diskIds,
      final ImageStatus status,
      ImageStatus statusForCompensation,
      final CompensationContext compensationContext) {
    if (compensationContext != null) {
      for (Guid diskId : diskIds) {
        List<DiskImage> diskSnapshots =
            DbFacade.getInstance().getDiskImageDao().getAllSnapshotsForImageGroup(diskId);
        for (DiskImage diskSnapshot : diskSnapshots) {
          diskSnapshot.setImageStatus(statusForCompensation);
          compensationContext.snapshotEntityStatus(diskSnapshot.getImage());
        }
      }

      TransactionSupport.executeInScope(
          TransactionScopeOption.Required,
          () -> {
            for (Guid diskId : diskIds) {
              DbFacade.getInstance()
                  .getImageDao()
                  .updateStatusOfImagesByImageGroupId(diskId, status);
            }
            compensationContext.stateChanged();
            return null;
          });
    } else {

      TransactionSupport.executeInScope(
          TransactionScopeOption.Required,
          () -> {
            for (Guid diskId : diskIds) {
              updateAllDiskImageSnapshotsStatus(diskId, status);
            }
            return null;
          });
    }
  }
  /**
   * After merging the snapshots, update the image and snapshot records in the database to reflect
   * the changes. This handles either forward or backwards merge (detected). It will either then
   * remove the images, or mark them illegal (to handle the case where image deletion failed).
   *
   * @param removeImages Remove the images from the database, or if false, only mark them illegal
   */
  private void syncDbRecords(boolean removeImages) {
    // If deletion failed after a backwards merge, the snapshots' images need to be swapped
    // as they would upon success.  Instead of removing them, mark them illegal.
    DiskImage baseImage = getDiskImage();
    DiskImage topImage = getDestinationDiskImage();

    // The vdsm merge verb may decide to perform a forward or backward merge.
    if (topImage == null) {
      log.debug("No merge destination image, not updating image/snapshot association");
    } else if (getParameters().getMergeStatusReturnValue().getBlockJobType()
        == VmBlockJobType.PULL) {
      // For forward merge, the volume format and type may change.
      topImage.setvolumeFormat(baseImage.getVolumeFormat());
      topImage.setVolumeType(baseImage.getVolumeType());
      topImage.setParentId(baseImage.getParentId());
      topImage.setImageStatus(ImageStatus.OK);

      getBaseDiskDao().update(topImage);
      getImageDao().update(topImage.getImage());
      updateDiskImageDynamic(topImage);

      updateVmConfigurationForImageRemoval(
          baseImage.getImage().getSnapshotId(), baseImage.getImageId());
    } else {
      // For backwards merge, the prior base image now has the data associated with the newer
      // snapshot we want to keep.  Re-associate this older image with the newer snapshot.
      // The base snapshot is deleted if everything went well.  In case it's not deleted, we
      // hijack it to preserve a link to the broken image.  This makes the image discoverable
      // so that we can retry the deletion later, yet doesn't corrupt the VM image chain.
      List<DiskImage> children =
          DbFacade.getInstance().getDiskImageDao().getAllSnapshotsForParent(topImage.getImageId());
      if (!children.isEmpty()) {
        DiskImage childImage = children.get(0);
        childImage.setParentId(baseImage.getImageId());
        getImageDao().update(childImage.getImage());
      }

      Image oldTopImage = topImage.getImage();
      topImage.setImage(baseImage.getImage());
      baseImage.setImage(oldTopImage);

      Guid oldTopSnapshotId = topImage.getImage().getSnapshotId();
      topImage.getImage().setSnapshotId(baseImage.getImage().getSnapshotId());
      baseImage.getImage().setSnapshotId(oldTopSnapshotId);

      boolean oldTopIsActive = topImage.getImage().isActive();
      topImage.getImage().setActive(baseImage.getImage().isActive());
      VolumeClassification baseImageVolumeClassification =
          VolumeClassification.getVolumeClassificationByActiveFlag(baseImage.getImage().isActive());
      topImage.getImage().setVolumeClassification(baseImageVolumeClassification);
      baseImage.getImage().setActive(oldTopIsActive);
      VolumeClassification oldTopVolumeClassification =
          VolumeClassification.getVolumeClassificationByActiveFlag(oldTopIsActive);
      topImage.getImage().setVolumeClassification(oldTopVolumeClassification);

      topImage.setSize(baseImage.getSize());
      topImage.setImageStatus(ImageStatus.OK);
      getBaseDiskDao().update(topImage);
      getImageDao().update(topImage.getImage());
      updateDiskImageDynamic(topImage);

      getBaseDiskDao().update(baseImage);
      getImageDao().update(baseImage.getImage());

      updateVmConfigurationForImageChange(
          topImage.getImage().getSnapshotId(), baseImage.getImageId(), topImage);
      updateVmConfigurationForImageRemoval(
          baseImage.getImage().getSnapshotId(), topImage.getImageId());
    }

    Set<Guid> imagesToUpdate = getParameters().getMergeStatusReturnValue().getImagesToRemove();
    if (imagesToUpdate == null) {
      log.error("Failed to update orphaned images in db: image list could not be retrieved");
      return;
    }
    for (Guid imageId : imagesToUpdate) {
      if (removeImages) {
        getImageDao().remove(imageId);
      } else {
        // The (illegal && no-parent && no-children) status indicates an orphaned image.
        Image image = getImageDao().get(imageId);
        image.setStatus(ImageStatus.ILLEGAL);
        image.setParentId(Guid.Empty);
        getImageDao().update(image);
      }
    }
  }
Exemplo n.º 9
0
 @Test
 public void testValidateImageIsLocked() {
   disk.setImageStatus(ImageStatus.LOCKED);
   ValidateTestUtils.runAndAssertValidateFailure(
       cmd, EngineMessage.ACTION_TYPE_FAILED_DISKS_LOCKED);
 }