Пример #1
0
  @Test
  public void allocateTarget_BasicTest() throws Exception {
    final String volId = "vol-0000";
    final ISCSIVolumeInfo iscsiVolumeInfo = new ISCSIVolumeInfo();
    iscsiVolumeInfo.setVolumeId(volId);

    final TGTService tgtService = context.mock(TGTService.class);
    final BlockStorageUtilSvc blockStorageUtilSvc = context.mock(BlockStorageUtilSvc.class);
    context.checking(
        new Expectations() {
          {
            oneOf(tgtService)
                .targetExists(
                    volId, 1, null, DirectStorageInfo.getStorageInfo().getTimeoutInMillis());
            will(returnValue(Boolean.FALSE));
          }
        });

    ISCSIMetaInfo metaInfo = new ISCSIMetaInfo(StorageProperties.NAME);
    metaInfo.setStoreNumber(new Integer(1));
    metaInfo.setTid(new Integer(1));
    metaInfo.setStorePrefix("foo:");
    metaInfo.setStoreUser("unittestuser0");

    try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) {
      metaInfo = Entities.persist(metaInfo);
      tran.commit();
    }

    ISCSIManager iscsiManager = new ISCSIManager(tgtService, blockStorageUtilSvc);
    iscsiManager.allocateTarget(iscsiVolumeInfo);

    List<ISCSIMetaInfo> remaining;
    try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) {
      remaining = Entities.query(new ISCSIMetaInfo());
      tran.commit();
    }

    assertTrue(
        "expected to have a result set querying the eucalyptus_storage persistence context",
        remaining != null);
    ISCSIMetaInfo retrieved = remaining.get(0);
    assertTrue(
        "expected store number to be 2 but was " + retrieved.getStoreNumber(),
        retrieved.getStoreNumber().intValue() == 2);
    assertTrue("expected tid to be 2", retrieved.getTid().intValue() == 2);
    String storeName = "foo:" + StorageProperties.NAME + ":store2";
    assertTrue(
        "expected iscsiVolumeInfo store name to be " + storeName,
        storeName.equals(iscsiVolumeInfo.getStoreName()));
    assertTrue(
        "expected iscsiVolumeInfo store user to be unittestuser0 but was "
            + iscsiVolumeInfo.getStoreUser(),
        "unittestuser0".equals(iscsiVolumeInfo.getStoreUser()));
    assertTrue(
        "expected iscsiVolumeInfo tid to be 1 and lun to be 1",
        iscsiVolumeInfo.getTid().intValue() == 1 && iscsiVolumeInfo.getLun().intValue() == 1);
  }
Пример #2
0
  @Test
  public void configure_YesDbUserAndYesTGTUserTest() throws Exception {

    final Long timeout = DirectStorageInfo.getStorageInfo().getTimeoutInMillis();
    final TGTService tgtService = context.mock(TGTService.class);
    final BlockStorageUtilSvc blockStorageUtilSvc = context.mock(BlockStorageUtilSvc.class);
    context.checking(
        new Expectations() {
          {
            oneOf(tgtService).userExists("eucalyptus", timeout);
            will(returnValue(Boolean.TRUE));
          }
        });

    try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) {
      Entities.persist(new CHAPUserInfo("eucalyptus", "foo"));
      tran.commit();
    }

    ISCSIManager iscsiManager = new ISCSIManager(tgtService, blockStorageUtilSvc);
    iscsiManager.configure();

    List<ISCSIMetaInfo> remaining;
    try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) {
      remaining = Entities.query(new ISCSIMetaInfo());
      tran.commit();
    }

    // make sure the meta info was created
    assertTrue(
        "expected to have a result set querying the eucalyptus_storage persistence context",
        remaining != null);
    ISCSIMetaInfo retrieved = remaining.get(0);
    assertTrue(
        "expected store prefix to be "
            + StorageProperties.STORE_PREFIX
            + " but it was "
            + retrieved.getStorePrefix(),
        StorageProperties.STORE_PREFIX.equals(retrieved.getStorePrefix()));
    assertTrue(
        "expected store number to be 0 but it was " + retrieved.getStoreNumber().intValue(),
        retrieved.getStoreNumber().intValue() == 0);
    assertTrue(
        "expected store user to be eucalyptus, but it was " + retrieved.getStoreUser(),
        "eucalyptus".equals(retrieved.getStoreUser()));
    assertTrue(
        "expected tid to be 1, but it was " + retrieved.getTid().intValue(),
        1 == retrieved.getTid().intValue());

    // make sure chap user was created
    CHAPUserInfo example = new CHAPUserInfo("eucalyptus");
    example.setScName(StorageProperties.NAME);
    try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) {
      example = Entities.uniqueResult(example);
      tran.commit();
    } catch (Exception ex) {
      fail("exception caught while looking for CHAPUserInfo record - " + ex.getMessage());
      ex.printStackTrace();
    }
    assertTrue("expected chap user info to be non-null", example != null);
    assertTrue(
        "expected eucalyptus chap user info to be created", "eucalyptus".equals(example.getUser()));
  }