@Test public void cleanup_NotExportedTest() 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.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); }
public void cleanup(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo volInfo = (ISCSIVolumeInfo) volumeInfo; try (TransactionResource tran = Entities.transactionFor(ISCSIVolumeInfo.class)) { ISCSIVolumeInfo volEntity = Entities.merge(volInfo); if (isExported(volEntity)) { unexportTarget(volEntity.getVolumeId(), volEntity.getTid(), volEntity.getLun(), volEntity.getAbsoluteLVPath()); if (!isExported(volEntity)) { volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } else { throw new EucalyptusCloudException("Unable to remove tid: " + volEntity.getTid()); } } else { LOG.debug("Target tid " + volEntity.getTid() + " is not exported for lun " + volEntity.getLun() + " for volume " + volEntity.getVolumeId()); volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } tran.commit(); } catch (Exception e) { LOG.error("Something went wrong, exiting iscsi cleanup for volume " + volumeInfo.getVolumeId()); } } else { LOG.error("Unknown volume type for volume " + volumeInfo.getVolumeId() + " - cannot cleanpup"); throw new EucalyptusCloudException("Unknown type for volumeInfo in ISCSI cleanup. Did not find ISCSIVolumeInfo as expected"); } }
ISCSIManager implements StorageExportManager { public void cleanup(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo volInfo = (ISCSIVolumeInfo) volumeInfo; try (TransactionResource tran = Entities.transactionFor(ISCSIVolumeInfo.class)) { ISCSIVolumeInfo volEntity = Entities.merge(volInfo); if (isExported(volEntity)) { unexportTarget(volEntity.getVolumeId(), volEntity.getTid(), volEntity.getLun(), volEntity.getAbsoluteLVPath()); if (!isExported(volEntity)) { volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } else { throw new EucalyptusCloudException("Unable to remove tid: " + volEntity.getTid()); } } else { LOG.debug("Target tid " + volEntity.getTid() + " is not exported for lun " + volEntity.getLun() + " for volume " + volEntity.getVolumeId()); volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } tran.commit(); } catch (Exception e) { LOG.error("Something went wrong, exiting iscsi cleanup for volume " + volumeInfo.getVolumeId()); } } else { LOG.error("Unknown volume type for volume " + volumeInfo.getVolumeId() + " - cannot cleanpup"); throw new EucalyptusCloudException("Unknown type for volumeInfo in ISCSI cleanup. Did not find ISCSIVolumeInfo as expected"); } } }
ISCSIManager implements StorageExportManager { public void cleanup(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo volInfo = (ISCSIVolumeInfo) volumeInfo; try (TransactionResource tran = Entities.transactionFor(ISCSIVolumeInfo.class)) { ISCSIVolumeInfo volEntity = Entities.merge(volInfo); if (isExported(volEntity)) { unexportTarget(volEntity.getVolumeId(), volEntity.getTid(), volEntity.getLun(), volEntity.getAbsoluteLVPath()); if (!isExported(volEntity)) { volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } else { throw new EucalyptusCloudException("Unable to remove tid: " + volEntity.getTid()); } } else { LOG.debug("Target tid " + volEntity.getTid() + " is not exported for lun " + volEntity.getLun() + " for volume " + volEntity.getVolumeId()); volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } tran.commit(); } catch (Exception e) { LOG.error("Something went wrong, exiting iscsi cleanup for volume " + volumeInfo.getVolumeId()); } } else { LOG.error("Unknown volume type for volume " + volumeInfo.getVolumeId() + " - cannot cleanpup"); throw new EucalyptusCloudException("Unknown type for volumeInfo in ISCSI cleanup. Did not find ISCSIVolumeInfo as expected"); } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); }
ISCSIManager implements StorageExportManager { public void cleanup(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo volInfo = (ISCSIVolumeInfo) volumeInfo; try (TransactionResource tran = Entities.transactionFor(ISCSIVolumeInfo.class)) { ISCSIVolumeInfo volEntity = Entities.merge(volInfo); if (isExported(volEntity)) { unexportTarget(volEntity.getVolumeId(), volEntity.getTid(), volEntity.getLun(), volEntity.getAbsoluteLVPath()); if (!isExported(volEntity)) { volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } else { throw new EucalyptusCloudException("Unable to remove tid: " + volEntity.getTid()); } } else { LOG.debug("Target tid " + volEntity.getTid() + " is not exported for lun " + volEntity.getLun() + " for volume " + volEntity.getVolumeId()); volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } tran.commit(); } catch (Exception e) { LOG.error("Something went wrong, exiting iscsi cleanup for volume " + volumeInfo.getVolumeId()); } } else { LOG.error("Unknown volume type for volume " + volumeInfo.getVolumeId() + " - cannot cleanpup"); throw new EucalyptusCloudException("Unknown type for volumeInfo in ISCSI cleanup. Did not find ISCSIVolumeInfo as expected"); } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); @Override void checkPreconditions(); @Override void check(); void addUser(String username, String password); void deleteUser(String username); void exportTarget(String volumeId, int tid, String name, int lun, String path, String user); void unexportTarget(String volumeId, int tid, int lun, String path); @Override void configure(); @Override synchronized void allocateTarget(LVMVolumeInfo volumeInfo); String getEncryptedPassword(); void cleanup(LVMVolumeInfo volumeInfo); @Override void stop(); @Override boolean isExported(LVMVolumeInfo volumeInfo); }
ISCSIManager implements StorageExportManager { public void cleanup(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo volInfo = (ISCSIVolumeInfo) volumeInfo; try (TransactionResource tran = Entities.transactionFor(ISCSIVolumeInfo.class)) { ISCSIVolumeInfo volEntity = Entities.merge(volInfo); if (isExported(volEntity)) { unexportTarget(volEntity.getVolumeId(), volEntity.getTid(), volEntity.getLun(), volEntity.getAbsoluteLVPath()); if (!isExported(volEntity)) { volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } else { throw new EucalyptusCloudException("Unable to remove tid: " + volEntity.getTid()); } } else { LOG.debug("Target tid " + volEntity.getTid() + " is not exported for lun " + volEntity.getLun() + " for volume " + volEntity.getVolumeId()); volEntity.setTid(-1); volEntity.setLun(-1); volEntity.setStoreName(null); volEntity.setStoreUser(null); } tran.commit(); } catch (Exception e) { LOG.error("Something went wrong, exiting iscsi cleanup for volume " + volumeInfo.getVolumeId()); } } else { LOG.error("Unknown volume type for volume " + volumeInfo.getVolumeId() + " - cannot cleanpup"); throw new EucalyptusCloudException("Unknown type for volumeInfo in ISCSI cleanup. Did not find ISCSIVolumeInfo as expected"); } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); @Override void checkPreconditions(); @Override void check(); void addUser(String username, String password); void deleteUser(String username); void exportTarget(String volumeId, int tid, String name, int lun, String path, String user); void unexportTarget(String volumeId, int tid, int lun, String path); @Override void configure(); @Override synchronized void allocateTarget(LVMVolumeInfo volumeInfo); String getEncryptedPassword(); void cleanup(LVMVolumeInfo volumeInfo); @Override void stop(); @Override boolean isExported(LVMVolumeInfo volumeInfo);  }