Ejemplo n.º 1
0
  @Test
  public void cleanup_BasicTest() throws Exception {
    final String volId = "vol-0000";
    final ISCSIVolumeInfo iscsiVolumeInfo = new ISCSIVolumeInfo();
    iscsiVolumeInfo.setVolumeId(volId);
    iscsiVolumeInfo.setTid(new Integer(1));
    iscsiVolumeInfo.setVgName("foo");
    iscsiVolumeInfo.setLvName("foo");
    iscsiVolumeInfo.setLun(new Integer(1));

    final TGTService tgtService = context.mock(TGTService.class);
    final BlockStorageUtilSvc blockStorageUtilSvc = context.mock(BlockStorageUtilSvc.class);
    final Long timeout = DirectStorageInfo.getStorageInfo().getTimeoutInMillis();
    context.checking(
        new Expectations() {
          {
            oneOf(tgtService).targetExists(volId, 1, iscsiVolumeInfo.getAbsoluteLVPath(), timeout);
            will(returnValue(Boolean.TRUE));
            oneOf(tgtService).targetExists(volId, 1, iscsiVolumeInfo.getAbsoluteLVPath(), timeout);
            will(returnValue(Boolean.TRUE));
            oneOf(tgtService).unbindTarget(volId, 1, timeout);
            oneOf(tgtService).deleteLun(volId, 1, 1, timeout);
            oneOf(tgtService).deleteTarget(volId, 1, timeout, false);
            oneOf(tgtService).targetExists(volId, 1, null, timeout);
            will(returnValue(Boolean.FALSE));
            oneOf(tgtService).targetExists(volId, 1, iscsiVolumeInfo.getAbsoluteLVPath(), timeout);
            will(returnValue(Boolean.FALSE));
          }
        });

    try (TransactionResource tran = Entities.transactionFor(ISCSIVolumeInfo.class)) {
      Entities.persist(iscsiVolumeInfo);
      tran.commit();
    }

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

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

    assertTrue(
        "expected to have a result set querying the eucalyptus_storage persistence context",
        remaining != null);
    ISCSIVolumeInfo retrieved = remaining.get(0);
    assertTrue(
        "expected store name to be null but was " + retrieved.getStoreName(),
        retrieved.getStoreName() == null);
    assertTrue("expected tid to be -1", retrieved.getTid().intValue() == -1);
    assertTrue(
        "expected iscsiVolumeInfo lun to be -1 but was " + retrieved.getLun().intValue(),
        retrieved.getLun().intValue() == -1);
  }
Ejemplo n.º 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()));
  }