示例#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);
    }
  }
  private void handle(APIGetNetworkServiceTypesMsg msg) {
    Map<String, List<String>> ret = new HashMap<String, List<String>>();

    List<NetworkServiceTypeVO> types = dbf.listAll(NetworkServiceTypeVO.class);
    for (NetworkServiceTypeVO vo : types) {
      List<String> providers = ret.get(vo.getType());
      if (providers == null) {
        providers = new ArrayList<String>();
        ret.put(vo.getType(), providers);
      }
      providers.add(vo.getNetworkServiceProviderUuid());
    }

    APIGetNetworkServiceTypesReply reply = new APIGetNetworkServiceTypesReply();
    reply.setServiceAndProviderTypes(ret);

    bus.reply(msg, reply);
  }
示例#3
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    HostInventory host2 = deployer.hosts.get("host2");
    HostInventory host1 = deployer.hosts.get("host1");
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    PrimaryStorageInventory local = deployer.primaryStorages.get("local");

    List<VolumeVO> vols = dbf.listAll(VolumeVO.class);
    List<VolumeVO> volumesOnLocal = new ArrayList<VolumeVO>();

    ImageCacheVO cacheVO = dbf.listAll(ImageCacheVO.class).get(0);
    long imageSize = cacheVO.getSize();
    long usedVolumeSize = 0;
    for (VolumeVO vol : vols) {
      if (vol.getPrimaryStorageUuid().equals(local.getUuid())) {
        volumesOnLocal.add(vol);
        usedVolumeSize += ratioMgr.calculateByRatio(vol.getPrimaryStorageUuid(), vol.getSize());
      }
    }

    config.createEmptyVolumeCmds.clear();
    config.deleteBitsCmds.clear();
    vm = api.migrateVmInstance(vm.getUuid(), host2.getUuid());
    TimeUnit.SECONDS.sleep(5);
    LocalStorageHostRefVO ref1 = dbf.findByUuid(host1.getUuid(), LocalStorageHostRefVO.class);
    Assert.assertEquals(ref1.getTotalCapacity() - imageSize, ref1.getAvailableCapacity());
    LocalStorageHostRefVO ref2 = dbf.findByUuid(host2.getUuid(), LocalStorageHostRefVO.class);
    Assert.assertEquals(
        ref2.getTotalCapacity() - imageSize - usedVolumeSize, ref2.getAvailableCapacity());

    Assert.assertEquals(volumesOnLocal.size(), config.createEmptyVolumeCmds.size());
    for (final VolumeVO vol : volumesOnLocal) {
      // volumes are created on dst host
      CreateEmptyVolumeCmd cmd =
          CollectionUtils.find(
              config.createEmptyVolumeCmds,
              new Function<CreateEmptyVolumeCmd, CreateEmptyVolumeCmd>() {
                @Override
                public CreateEmptyVolumeCmd call(CreateEmptyVolumeCmd arg) {
                  return arg.getVolumeUuid().equals(vol.getUuid()) ? arg : null;
                }
              });
      Assert.assertNotNull(cmd);
      Assert.assertEquals(vol.getInstallPath(), cmd.getInstallUrl());

      LocalStorageResourceRefVO r = dbf.findByUuid(vol.getUuid(), LocalStorageResourceRefVO.class);
      Assert.assertEquals(host2.getUuid(), r.getHostUuid());

      // volumes are deleted on src host
      DeleteBitsCmd dcmd =
          CollectionUtils.find(
              config.deleteBitsCmds,
              new Function<DeleteBitsCmd, DeleteBitsCmd>() {
                @Override
                public DeleteBitsCmd call(DeleteBitsCmd arg) {
                  return arg.getPath().equals(vol.getInstallPath()) ? arg : null;
                }
              });
      Assert.assertNotNull(
          String.format(
              "no delete command for volume[uuid:%s, path:%s]",
              vol.getUuid(), vol.getInstallPath()),
          dcmd);
    }

    Assert.assertFalse(kconfig.migrateVmCmds.isEmpty());
    MigrateVmCmd mcmd = kconfig.migrateVmCmds.get(0);
    Assert.assertEquals(host2.getManagementIp(), mcmd.getDestHostIp());
    Assert.assertEquals(vm.getUuid(), mcmd.getVmUuid());
    Assert.assertEquals(
        StorageMigrationPolicy.IncCopy.toString(), mcmd.getStorageMigrationPolicy());
  }