Exemplo n.º 1
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    final BackupStorageInventory sftp = deployer.backupStorages.get("sftp");
    final ImageInventory img = new ImageInventory();
    img.setName("image");
    img.setPlatform(ImagePlatform.Linux.toString());
    img.setMediaType(ImageMediaType.RootVolumeTemplate.toString());
    img.setFormat("qcow2");
    img.setUrl("http://test.img");

    for (int i = 0; i < num; i++) {
      createVm(img, sftp.getUuid());
    }

    latch.await(5, TimeUnit.MINUTES);

    Assert.assertEquals(num, vms.size());

    fconfig.applyDhcpCmdList.clear();
    HostInventory host = deployer.hosts.get("host1");
    api.reconnectHost(host.getUuid());
    Assert.assertFalse(fconfig.applyDhcpCmdList.isEmpty());
    ApplyDhcpCmd cmd = fconfig.applyDhcpCmdList.get(0);
    Assert.assertEquals(num + 1, cmd.dhcp.size());

    List<VmInstanceVO> vms = dbf.listAll(VmInstanceVO.class);
    for (VmInstanceVO vm : vms) {
      checkNic(vm, cmd.dhcp);
    }
  }
Exemplo n.º 2
0
  @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 {
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    api.stopVmInstance(vm.getUuid());
    String rootVolumeUuid = vm.getRootVolumeUuid();
    VolumeVO vol = dbf.findByUuid(rootVolumeUuid, VolumeVO.class);

    BackupStorageInventory sftp = deployer.backupStorages.get("sftp");
    ImageInventory image =
        api.createTemplateFromRootVolume("testImage", rootVolumeUuid, (List) null);
    Assert.assertEquals(sftp.getUuid(), image.getBackupStorageRefs().get(0).getBackupStorageUuid());
    Assert.assertEquals(ImageStatus.Ready.toString(), image.getStatus());
    Assert.assertEquals(vol.getSize(), image.getSize());
    Assert.assertEquals(String.format("volume://%s", vol.getUuid()), image.getUrl());

    ImageVO ivo = dbf.findByUuid(image.getUuid(), ImageVO.class);
    Assert.assertNotNull(ivo);
  }
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    InstanceOfferingInventory ioinv = deployer.instanceOfferings.get("TestInstanceOffering");
    ImageInventory img = deployer.images.get("TestImage");
    L3NetworkInventory l3 = deployer.l3Networks.get("TestL3Network1");
    DiskOfferingInventory disk = deployer.diskOfferings.get("disk50G");

    IdentityCreator identityCreator = new IdentityCreator(api);
    AccountInventory test = identityCreator.useAccount("test");

    // some image set in xml,some below,the amount should one more than the quota to get expected
    // exceeding exception.
    api.updateQuota(test.getUuid(), ImageConstant.QUOTA_IMAGE_NUM, 4);

    BackupStorageInventory bsInv = deployer.backupStorages.get("TestImageStoreBackupStorage");

    // add image by http
    ImageInventory iinv = new ImageInventory();
    iinv.setUuid(Platform.getUuid());
    iinv.setName("Test Image1");
    iinv.setDescription("Test Image1");
    iinv.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
    iinv.setGuestOsType("Window7");
    iinv.setFormat("simulator");
    iinv.setUrl("http://192.168.200.1/mirror/diskimages/centos6-test.qcow2");
    iinv = api.addImage(iinv, identityCreator.getAccountSession(), bsInv.getUuid());

    // add image by local file
    iinv = new ImageInventory();
    iinv.setUuid(Platform.getUuid());
    iinv.setName("Test Image1");
    iinv.setDescription("Test Image1");
    iinv.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
    iinv.setGuestOsType("Window7");
    iinv.setFormat("simulator");
    iinv.setUrl("file://///home/miao/Desktop/zstack2/imageStore1.zip");
    // for getImageSize response
    iConfig.getImageSizeCmdSize.put(iinv.getUuid(), SizeUnit.GIGABYTE.toByte(2));
    // for download response
    iConfig.imageSizes.put(iinv.getUuid(), SizeUnit.GIGABYTE.toByte(1));
    iinv = api.addImage(iinv, identityCreator.getAccountSession(), bsInv.getUuid());

    // add image by local file
    iinv = new ImageInventory();
    iinv.setUuid(Platform.getUuid());
    iinv.setName("Test Image1");
    iinv.setDescription("Test Image1");
    iinv.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
    iinv.setGuestOsType("Window7");
    iinv.setFormat("simulator");
    iinv.setUrl("file://///home/miao/Desktop/zstack2/imageStore2.zip");
    iConfig.getImageSizeCmdSize.put(iinv.getUuid(), SizeUnit.GIGABYTE.toByte(2));
    iinv = api.addImage(iinv, identityCreator.getAccountSession(), bsInv.getUuid());

    // add image by http to exceed quota:image.num
    iinv = new ImageInventory();
    iinv.setUuid(Platform.getUuid());
    iinv.setName("Test Image2");
    iinv.setDescription("Test Image2");
    iinv.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
    iinv.setGuestOsType("Window7");
    iinv.setFormat("simulator");
    iinv.setUrl("http://192.168.200.1/mirror/diskimages/exceed.img");

    thrown.expect(ApiSenderException.class);
    thrown.expectMessage("The user exceeds a quota of a resource");
    thrown.expectMessage(ImageConstant.QUOTA_IMAGE_NUM);

    iConfig.getImageSizeCmdSize.put(iinv.getUuid(), SizeUnit.MEGABYTE.toByte(233));
    iinv = api.addImage(iinv, identityCreator.getAccountSession(), bsInv.getUuid());
    //
    List<Quota.QuotaUsage> usages = api.getQuotaUsage(test.getUuid(), null);
    //
    Quota.QuotaUsage imageNum =
        CollectionUtils.find(
            usages,
            new Function<Quota.QuotaUsage, Quota.QuotaUsage>() {
              @Override
              public Quota.QuotaUsage call(Quota.QuotaUsage arg) {
                return ImageConstant.QUOTA_IMAGE_NUM.equals(arg.getName()) ? arg : null;
              }
            });
    Assert.assertNotNull(imageNum);
    QuotaInventory qvm =
        api.getQuota(
            ImageConstant.QUOTA_IMAGE_NUM, test.getUuid(), identityCreator.getAccountSession());
    Assert.assertEquals(qvm.getValue(), imageNum.getTotal().longValue());
    Assert.assertEquals(2, imageNum.getUsed().longValue());
    //
    Quota.QuotaUsage imageSize =
        CollectionUtils.find(
            usages,
            new Function<Quota.QuotaUsage, Quota.QuotaUsage>() {
              @Override
              public Quota.QuotaUsage call(Quota.QuotaUsage arg) {
                return ImageConstant.QUOTA_IMAGE_SIZE.equals(arg.getName()) ? arg : null;
              }
            });
    Assert.assertNotNull(imageSize);
    qvm =
        api.getQuota(
            ImageConstant.QUOTA_IMAGE_SIZE, test.getUuid(), identityCreator.getAccountSession());
    Assert.assertEquals(qvm.getValue(), imageSize.getTotal().longValue());
    Assert.assertTrue(imageSize.getUsed().longValue() <= imageSize.getTotal().longValue());
  }