private void canDoActionMakeDiskBootableOnOtherVm(boolean boot) {
    UpdateVmDiskParameters parameters = createParameters();
    Disk newDisk = parameters.getDiskInfo();
    newDisk.setBoot(true);

    Guid otherVmId = Guid.newGuid();
    VM otherVm = new VM();
    otherVm.setId(otherVmId);

    DiskImage otherDisk = new DiskImage();
    otherDisk.setId(Guid.newGuid());
    otherDisk.setActive(true);
    otherDisk.setBoot(boot);
    if (boot) {
      when(diskDao.getVmBootActiveDisk(otherVmId)).thenReturn(otherDisk);
    }
    when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage());

    initializeCommand(parameters, Arrays.asList(createVmStatusDown(), otherVm));

    mockInterfaceList();

    // The command should only succeed if there is no other bootable disk
    assertEquals(!boot, command.canDoAction());
  }
Пример #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;
 }
 /**
  * Add image and related entities to DB (Adds image, disk image dynamic and image storage domain
  * map)
  *
  * @param image the image to add
  * @param active if true the image will be active
  * @param imageStorageDomainMap entry of mapping between the storage domain and the image
  */
 public static void addImage(
     DiskImage image, boolean active, ImageStorageDomainMap imageStorageDomainMap) {
   image.setActive(active);
   DbFacade.getInstance().getImageDao().save(image.getImage());
   DiskImageDynamic diskDynamic = new DiskImageDynamic();
   diskDynamic.setId(image.getImageId());
   diskDynamic.setActualSize(image.getActualSizeInBytes());
   DbFacade.getInstance().getDiskImageDynamicDao().save(diskDynamic);
   if (imageStorageDomainMap != null) {
     DbFacade.getInstance().getImageStorageDomainMapDao().save(imageStorageDomainMap);
   }
 }
Пример #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;
 }
  private DiskImage mockDiskImage(DiskInterface iface) {
    disk.setImageId(diskImageGuid);
    ArrayList<Guid> storageIdList = new ArrayList<>();
    storageIdList.add(storageDomainId);
    disk.setStorageIds(storageIdList);
    disk.setStoragePoolId(storagePoolId);
    disk.setActive(true);
    disk.setId(Guid.newGuid());

    when(diskDao.get(diskImageGuid)).thenReturn(disk);
    DiskVmElement dve = new DiskVmElement(disk.getId(), vmId);
    dve.setDiskInterface(iface);
    when(diskVmElementDao.get(new VmDeviceId(disk.getId(), vmId))).thenReturn(dve);
    return disk;
  }
  @Test
  public void getOtherVmDisks() {
    UpdateVmDiskParameters parameters = createParameters();

    DiskImage otherDisk = new DiskImage();
    otherDisk.setId(Guid.newGuid());
    otherDisk.setActive(true);
    when(diskDao.getAllForVm(vmId))
        .thenReturn(new LinkedList<>(Arrays.asList(parameters.getDiskInfo(), otherDisk)));
    when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage());
    initializeCommand(parameters);

    VM vm = createVmStatusDown();
    mockCtorRelatedDaoCalls(Collections.singletonList(vm));
    List<Disk> otherDisks = command.getOtherVmDisks(vm.getId());
    assertEquals("Wrong number of other disks", 1, otherDisks.size());
    assertFalse("Wrong other disk", otherDisks.contains(parameters.getDiskInfo()));
  }