@Test
 public void testUpdateVmDeviceUsingScsiReservationProperty() {
   DiskVmElement dve = dao.get(getExistingEntityId());
   boolean usingScsiReservation = !dve.isUsingScsiReservation();
   dve.setUsingScsiReservation(usingScsiReservation);
   dao.update(dve);
   DiskVmElement dveFromDb = dao.get(getExistingEntityId());
   assertEquals(dveFromDb.isUsingScsiReservation(), usingScsiReservation);
 }
  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;
  }
Example #3
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()));
        }
      }
    }
  }
 @Test
 public void testVmElementDiskUnpluggedStatus() {
   DiskVmElement dveUnplugged =
       dao.get(new VmDeviceId(UNPLUGGED_DISK_ID, FixturesTool.VM_RHEL5_POOL_57));
   assertFalse(dveUnplugged.isPlugged());
 }
 @Test
 public void testVmElementDiskLogicalName() {
   DiskVmElement dveWithLogicalName =
       dao.get(new VmDeviceId(PLUGGED_DISK_ID, FixturesTool.VM_RHEL5_POOL_57));
   assertEquals("logical_name", dveWithLogicalName.getLogicalName());
 }
 @Test
 public void testGetFilteredWithPermissions() {
   DiskVmElement result = dao.get(getExistingEntityId(), PRIVILEGED_USER_ID, true);
   assertNotNull(result);
   assertEquals(getExistingEntityId().toString(), result.getId().toString());
 }