예제 #1
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    ImageInventory img = deployer.images.get("TestImage");
    VmInstanceInventory vm = deployer.vms.get("TestVm");

    api.deleteImage(img.getUuid());

    api.stopVmInstance(vm.getUuid());
    api.startVmInstance(vm.getUuid());
    api.rebootVmInstance(vm.getUuid());
    api.destroyVmInstance(vm.getUuid());
  }
예제 #2
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    CoreGlobalProperty.VM_TRACER_ON = false;
    IdentityGlobalConfig.SESSION_TIMEOUT.updateValue(TimeUnit.HOURS.toSeconds(1000));
    api.prepare();
    InstanceOfferingInventory ioinv = api.listInstanceOffering(null).get(0);
    ImageInventory iminv = api.listImage(null).get(0);
    List<DiskOfferingInventory> dinvs = api.listDiskOffering(null);
    List<L3NetworkInventory> nwinvs = api.listL3Network(null);
    List<String> nws = new ArrayList<String>(nwinvs.size());
    for (L3NetworkInventory nwinv : nwinvs) {
      nws.add(nwinv.getUuid());
    }

    for (int i = 0; i < vmNum; i++) {
      VmInstanceInventory vm = new VmInstanceInventory();
      vm.setDescription("TestVm");
      vm.setName("TestVm");
      vm.setType(VmInstanceConstant.USER_VM_TYPE);
      vm.setInstanceOfferingUuid(ioinv.getUuid());
      vm.setImageUuid(iminv.getUuid());
      createVm(vm, dinvs.get(0).getUuid(), nws, new ArrayList<String>());
    }
    latch.await(600, TimeUnit.MINUTES);
    long totalTime = 0;
    long minTime = 0;
    long maxTime = 0;
    for (Long t : timeCost) {
      minTime = Math.min(minTime, t);
      maxTime = Math.max(maxTime, t);
      totalTime += t;
    }
    System.out.println(
        String.format(
            "total time: %s, min time: %s, max time: %s, avg  time: %s",
            TimeUnit.MILLISECONDS.toSeconds(totalTime),
            TimeUnit.MILLISECONDS.toSeconds(minTime),
            TimeUnit.MILLISECONDS.toSeconds(maxTime),
            TimeUnit.MILLISECONDS.toSeconds(totalTime / timeCost.size())));

    /*
    SimpleQuery<VmInstanceVO> q = dbf.createQuery(VmInstanceVO.class);
    q.add(VmInstanceVO_.state, Op.EQ, VmInstanceState.Running);
    long count = q.count();
    Assert.assertEquals(vmNum, count);
    */
    TimeUnit.HOURS.sleep(1000);
  }
  @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);
  }
예제 #4
0
 @Test
 public void test() throws ApiSenderException {
   ImageInventory iminv = deployer.images.get("TestImage");
   InstanceOfferingInventory ioinv = deployer.instanceOfferings.get("TestInstanceOffering");
   L3NetworkInventory l3inv = deployer.l3Networks.get("TestL3Network2");
   APICreateVmInstanceMsg msg = new APICreateVmInstanceMsg();
   msg.setImageUuid(iminv.getUuid());
   msg.setInstanceOfferingUuid(ioinv.getUuid());
   List<String> l3uuids = new ArrayList<String>();
   l3uuids.add(l3inv.getUuid());
   msg.setL3NetworkUuids(l3uuids);
   msg.setName("TestVm");
   msg.setSession(session);
   msg.setServiceId(ApiMediatorConstant.SERVICE_ID);
   msg.setType(VmInstanceConstant.USER_VM_TYPE);
   ApiSender sender = api.getApiSender();
   sender.send(msg, APICreateVmInstanceEvent.class);
 }
  @Test
  public void test() throws ApiSenderException {
    L3NetworkInventory l3 = deployer.l3Networks.get("l3Network1");
    InstanceOfferingInventory instanceOffering =
        deployer.instanceOfferings.get("instanceOffering512M512HZ");
    ImageInventory imageInventory = deployer.images.get("image1");
    ZoneInventory zone1 = deployer.zones.get("zone1");

    VmCreator creator = new VmCreator();
    creator.addL3Network(l3.getUuid());
    creator.imageUuid = imageInventory.getUuid();
    creator.instanceOfferingUuid = instanceOffering.getUuid();
    creator.zoneUuid = zone1.getUuid();
    VmInstanceInventory vm = creator.create();
    HostCapacityVO cvo = dbf.findByUuid(vm.getHostUuid(), HostCapacityVO.class);
    Assert.assertEquals(instanceOffering.getCpuNum(), cvo.getUsedCpu());
    Assert.assertEquals(instanceOffering.getMemorySize(), cvo.getUsedMemory());
    Assert.assertEquals(zone1.getUuid(), vm.getZoneUuid());
  }
예제 #6
0
 @AsyncThread
 private void createVm(ImageInventory img, String bsUuid) throws ApiSenderException {
   img = api.addImage(img, bsUuid);
   InstanceOfferingInventory ioinv = deployer.instanceOfferings.get("small");
   L3NetworkInventory l3 = deployer.l3Networks.get("TestL3Network1");
   VmCreator creator = new VmCreator(api);
   creator.imageUuid = img.getUuid();
   creator.session = api.getAdminSession();
   creator.instanceOfferingUuid = ioinv.getUuid();
   creator.name = "vm";
   creator.addL3Network(l3.getUuid());
   try {
     synchronized (vms) {
       vms.add(creator.create());
     }
   } finally {
     latch.countDown();
   }
 }
예제 #7
0
  @Test
  public void test() throws ApiSenderException {
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    ImageInventory iso = deployer.images.get("TestIso");
    PrimaryStorageInventory ps = deployer.primaryStorages.get("ceph-pri");

    restf.installBeforeAsyncJsonPostInterceptor(
        new BeforeAsyncJsonPostInterceptor() {
          @Override
          public void beforeAsyncJsonPost(String url, Object body, TimeUnit unit, long timeout) {
            if (body instanceof AttachIsoCmd) {
              AttachIsoCmd cmd = (AttachIsoCmd) body;
              isoto = (KvmCephIsoTO) cmd.iso;
            }
          }

          @Override
          public void beforeAsyncJsonPost(String url, String body, TimeUnit unit, long timeout) {}
        });

    api.attachIso(vm.getUuid(), iso.getUuid(), null);
    Assert.assertNotNull(isoto);
    Assert.assertFalse(isoto.getMonInfo().isEmpty());

    CephPrimaryStorageVO ceph = dbf.findByUuid(ps.getUuid(), CephPrimaryStorageVO.class);
    Assert.assertEquals(ceph.getMons().size(), isoto.getMonInfo().size());

    for (final CephPrimaryStorageMonVO mon : ceph.getMons()) {
      MonInfo info =
          CollectionUtils.find(
              isoto.getMonInfo(),
              new Function<MonInfo, MonInfo>() {
                @Override
                public MonInfo call(MonInfo arg) {
                  return arg.getHostname().equals(mon.getHostname()) ? arg : null;
                }
              });

      Assert.assertNotNull(info);
    }
  }
  @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());
  }