@Test
  public void testPoolStateIsNotUp() {
    try {
      createDb();

      StoragePoolVO pool = storagePoolDao.findById(storagePoolId);
      pool.setScope(ScopeType.ZONE);
      pool.setStatus(StoragePoolStatus.Maintenance);
      storagePoolDao.update(pool.getId(), pool);

      DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.XenServer);
      VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
      Mockito.when(
              storageMgr.storagePoolHasEnoughSpace(
                  Mockito.anyListOf(Volume.class), Mockito.any(StoragePool.class)))
          .thenReturn(true);
      DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
      int foundAcct = 0;
      for (StoragePoolAllocator allocator : allocators) {
        List<StoragePool> pools =
            allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
        if (!pools.isEmpty()) {
          Assert.assertEquals(pools.get(0).getId(), storage.getId());
          foundAcct++;
        }
      }

      if (foundAcct == 1) {
        Assert.fail();
      }
    } catch (Exception e) {
      cleanDb();
      Assert.fail();
    }
  }
  @Test
  public void testClusterAllocatorMultiplePools() {
    Long newStorageId = null;
    try {
      createDb();

      DataStoreProvider provider =
          providerMgr.getDataStoreProvider("ancient primary data store provider");
      storage = new StoragePoolVO();
      storage.setDataCenterId(dcId);
      storage.setPodId(podId);
      storage.setPoolType(StoragePoolType.NetworkFilesystem);
      storage.setClusterId(clusterId);
      storage.setStatus(StoragePoolStatus.Up);
      storage.setScope(ScopeType.CLUSTER);
      storage.setAvailableBytes(1000);
      storage.setCapacityBytes(20000);
      storage.setHostAddress(UUID.randomUUID().toString());
      storage.setPath(UUID.randomUUID().toString());
      storage.setStorageProviderName(provider.getName());
      StoragePoolVO newStorage = storagePoolDao.persist(storage);
      newStorageId = newStorage.getId();

      DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.XenServer);
      VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
      Mockito.when(
              storageMgr.storagePoolHasEnoughSpace(
                  Mockito.anyListOf(Volume.class), Mockito.any(StoragePool.class)))
          .thenReturn(true);
      DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
      int foundAcct = 0;
      for (StoragePoolAllocator allocator : allocators) {
        List<StoragePool> pools =
            allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
        if (!pools.isEmpty()) {
          Assert.assertEquals(pools.size(), 1);
          foundAcct++;
        }
      }

      if (foundAcct > 1 || foundAcct == 0) {
        Assert.fail();
      }
    } catch (Exception e) {
      cleanDb();

      if (newStorageId != null) {
        storagePoolDao.remove(newStorageId);
      }
      Assert.fail();
    }
  }
  @Test
  public void testClusterAllocatorWithTags() {
    try {
      createDb();
      StoragePoolDetailVO detailVO = new StoragePoolDetailVO(this.storagePoolId, "high", "true");
      poolDetailsDao.persist(detailVO);
      DiskOfferingVO diskOff = this.diskOfferingDao.findById(diskOffering.getId());
      List<String> tags = new ArrayList<String>();
      tags.add("high");
      diskOff.setTagsArray(tags);
      diskOfferingDao.update(diskOff.getId(), diskOff);

      DiskProfile profile = new DiskProfile(volume, diskOff, HypervisorType.XenServer);
      VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
      Mockito.when(
              storageMgr.storagePoolHasEnoughSpace(
                  Mockito.anyListOf(Volume.class), Mockito.any(StoragePool.class)))
          .thenReturn(true);
      DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
      int foundAcct = 0;
      for (StoragePoolAllocator allocator : allocators) {
        List<StoragePool> pools =
            allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
        if (!pools.isEmpty()) {
          Assert.assertEquals(pools.get(0).getId(), storage.getId());
          foundAcct++;
        }
      }

      if (foundAcct > 1 || foundAcct == 0) {
        Assert.fail();
      }
    } catch (Exception e) {
      cleanDb();
      Assert.fail();
    }
  }