@Test
  public void test() throws ApiSenderException {
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    api.stopVmInstance(vm.getUuid());
    PrimaryStorageInventory local = deployer.primaryStorages.get("local");

    VolumeSnapshotInventory sp = api.createSnapshot(vm.getRootVolumeUuid());
    Assert.assertFalse(kconfig.snapshotCmds.isEmpty());
    LocalStorageResourceRefVO ref = dbf.findByUuid(sp.getUuid(), LocalStorageResourceRefVO.class);
    Assert.assertNotNull(ref);
    Assert.assertEquals(vm.getHostUuid(), ref.getHostUuid());

    sp = api.createSnapshot(vm.getRootVolumeUuid());
    ref = dbf.findByUuid(sp.getUuid(), LocalStorageResourceRefVO.class);
    Assert.assertNotNull(ref);
    Assert.assertEquals(vm.getHostUuid(), ref.getHostUuid());

    sp = api.createSnapshot(vm.getRootVolumeUuid());
    ref = dbf.findByUuid(sp.getUuid(), LocalStorageResourceRefVO.class);
    Assert.assertNotNull(ref);
    Assert.assertEquals(vm.getHostUuid(), ref.getHostUuid());

    PrimaryStorageVO localvo = dbf.findByUuid(local.getUuid(), PrimaryStorageVO.class);
    long avail = localvo.getCapacity().getAvailableCapacity();

    ImageInventory img = api.createTemplateFromSnapshot(sp.getUuid());
    Assert.assertTrue(img.getSize() != 0);

    localvo = dbf.findByUuid(local.getUuid(), PrimaryStorageVO.class);
    Assert.assertEquals(avail, localvo.getCapacity().getAvailableCapacity());
  }
 private void fullSnapshot(VolumeSnapshotInventory inv, int distance) {
   Assert.assertEquals(VolumeSnapshotState.Enabled.toString(), inv.getState());
   Assert.assertEquals(VolumeSnapshotStatus.Ready.toString(), inv.getStatus());
   VolumeVO vol = dbf.findByUuid(inv.getVolumeUuid(), VolumeVO.class);
   VolumeSnapshotVO svo = dbf.findByUuid(inv.getUuid(), VolumeSnapshotVO.class);
   Assert.assertNotNull(svo);
   Assert.assertTrue(svo.isFullSnapshot());
   Assert.assertTrue(svo.isLatest());
   Assert.assertNull(svo.getParentUuid());
   Assert.assertEquals(distance, svo.getDistance());
   Assert.assertEquals(vol.getPrimaryStorageUuid(), svo.getPrimaryStorageUuid());
   Assert.assertNotNull(svo.getPrimaryStorageInstallPath());
   VolumeSnapshotTreeVO cvo = dbf.findByUuid(svo.getTreeUuid(), VolumeSnapshotTreeVO.class);
   Assert.assertNotNull(cvo);
   Assert.assertTrue(cvo.isCurrent());
 }
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    VolumeInventory root =
        CollectionUtils.find(
            vm.getAllVolumes(),
            new Function<VolumeInventory, VolumeInventory>() {
              @Override
              public VolumeInventory call(VolumeInventory arg) {
                return VolumeType.Root.toString().equals(arg.getType()) ? arg : null;
              }
            });

    assert root != null;
    VolumeSnapshotInventory sp = api.createSnapshot(root.getUuid());
    IscsiBtrfsSnapshotValidator validator = new IscsiBtrfsSnapshotValidator();
    validator.validate(sp);

    VolumeInventory volume = api.createDataVolumeFromSnapshot(sp.getUuid());
    Assert.assertEquals(VolumeConstant.VOLUME_FORMAT_RAW, volume.getFormat());
  }
  @Test
  public void test() throws ApiSenderException {
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    VolumeInventory dataVol =
        CollectionUtils.find(
            vm.getAllVolumes(),
            new Function<VolumeInventory, VolumeInventory>() {
              @Override
              public VolumeInventory call(VolumeInventory arg) {
                if (arg.getType().equals(VolumeType.Data.toString())) {
                  return arg;
                }
                return null;
              }
            });

    String volUuid = dataVol.getUuid();
    VolumeSnapshotInventory inv1 = api.createSnapshot(volUuid);
    fullSnapshot(inv1, 0);

    VolumeSnapshotInventory inv = api.createSnapshot(volUuid);
    deltaSnapshot(inv, 1);

    inv = api.createSnapshot(volUuid);
    deltaSnapshot(inv, 2);

    inv = api.createSnapshot(volUuid);
    deltaSnapshot(inv, 3);

    BackupStorageInventory sftp = deployer.backupStorages.get("sftp");
    api.backupSnapshot(inv.getUuid());

    api.deleteSnapshotFromBackupStorage(inv1.getUuid(), sftp.getUuid());

    BackupStorageVO sftpvo = dbf.findByUuid(sftp.getUuid(), BackupStorageVO.class);
    Assert.assertEquals(sftp.getAvailableCapacity(), sftpvo.getAvailableCapacity());
  }
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    VolumeInventory root =
        CollectionUtils.find(
            vm.getAllVolumes(),
            new Function<VolumeInventory, VolumeInventory>() {
              @Override
              public VolumeInventory call(VolumeInventory arg) {
                return VolumeType.Root.toString().equals(arg.getType()) ? arg : null;
              }
            });

    assert root != null;
    VolumeSnapshotInventory sp = api.createSnapshot(root.getUuid());
    IscsiBtrfsSnapshotValidator validator = new IscsiBtrfsSnapshotValidator();
    validator.validate(sp);
    Assert.assertEquals(1, iconfig.createSubVolumeCmds.size());
    api.destroyVmInstance(vm.getUuid());
    api.deleteSnapshot(sp.getUuid());

    VolumeSnapshotVO spvo = dbf.findByUuid(sp.getUuid(), VolumeSnapshotVO.class);
    Assert.assertNull(spvo);
  }