Esempio n. 1
0
  private void checkNic(VmInstanceVO vm, List<DhcpInfo> info) {
    VmNicVO nic = vm.getVmNics().iterator().next();
    DhcpInfo target = null;
    for (DhcpInfo i : info) {
      if (i.mac.equals(nic.getMac())) {
        target = i;
        break;
      }
    }

    Assert.assertNotNull(target);
    Assert.assertEquals(nic.getIp(), target.ip);
    Assert.assertEquals(nic.getNetmask(), target.netmask);
    Assert.assertEquals(nic.getGateway(), target.gateway);
    Assert.assertEquals(true, target.isDefaultL3Network);
    Assert.assertEquals(
        VmSystemTags.HOSTNAME.getTokenByResourceUuid(vm.getUuid(), VmSystemTags.HOSTNAME_TOKEN),
        target.hostname);
    L3NetworkVO l3 = dbf.findByUuid(nic.getL3NetworkUuid(), L3NetworkVO.class);
    Assert.assertEquals(l3.getDnsDomain(), target.dnsDomain);
    Assert.assertNotNull(target.dns);
    List<String> dns =
        CollectionUtils.transformToList(
            l3.getDns(),
            new Function<String, L3NetworkDnsVO>() {
              @Override
              public String call(L3NetworkDnsVO arg) {
                return arg.getDns();
              }
            });
    Assert.assertTrue(dns.containsAll(target.dns));
    Assert.assertTrue(target.dns.containsAll(dns));
  }
Esempio n. 2
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    final L3NetworkInventory l3 = deployer.l3Networks.get("TestL3Network4");
    VmInstanceInventory vm = deployer.vms.get("TestVm");

    APIGetIpAddressCapacityReply ipcap = api.getIpAddressCapacityByAll();
    long avail1 = ipcap.getAvailableCapacity();

    int num = 50;
    final CountDownLatch latch = new CountDownLatch(num);
    final String vmUuid = vm.getUuid();

    class Ret {
      int count;
    }

    final Ret ret = new Ret();
    for (int i = 0; i < num; i++) {
      new Runnable() {
        @Override
        @AsyncThread
        public void run() {
          try {
            VmInstanceInventory v = api.attachNic(vmUuid, l3.getUuid());
            ret.count += 1;
          } catch (Exception e) {
            logger.warn(e.getMessage(), e);
          } finally {
            latch.countDown();
          }
        }
      }.run();
    }

    latch.await(120, TimeUnit.SECONDS);

    VmInstanceVO vmvo = dbf.findByUuid(vmUuid, VmInstanceVO.class);
    final CountDownLatch latch1 = new CountDownLatch(vmvo.getVmNics().size());
    for (final VmNicVO nic : vmvo.getVmNics()) {
      new Runnable() {
        @Override
        @AsyncThread
        public void run() {
          try {
            api.detachNic(nic.getUuid());
          } catch (Exception e) {
            logger.warn(e.getMessage(), e);
          } finally {
            latch1.countDown();
          }
        }
      }.run();
    }

    latch1.await(120, TimeUnit.SECONDS);

    TimeUnit.SECONDS.sleep(5);
    ipcap = api.getIpAddressCapacityByAll();
    long avail2 = ipcap.getAvailableCapacity();

    Assert.assertEquals(avail1, avail2 - 3);
  }