Skip to content

Commit

Permalink
core,restapi: report iscsi server address and port for direct LUNs
Browse files Browse the repository at this point in the history
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
  • Loading branch information
bennyz committed Jul 27, 2022
1 parent ba21266 commit 6251e3f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import org.ovirt.engine.core.bll.QueriesCommandBase;
import org.ovirt.engine.core.bll.context.EngineContext;
import org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler;
import org.ovirt.engine.core.common.businessentities.StorageServerConnections;
import org.ovirt.engine.core.common.businessentities.storage.Disk;
import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
import org.ovirt.engine.core.common.businessentities.storage.DiskStorageType;
import org.ovirt.engine.core.common.businessentities.storage.LunDisk;
import org.ovirt.engine.core.common.queries.IdQueryParameters;
import org.ovirt.engine.core.dao.DiskDao;
import org.ovirt.engine.core.dao.StorageServerConnectionDao;

public class GetDiskAndSnapshotsByDiskIdQuery<P extends IdQueryParameters> extends QueriesCommandBase<P> {
@Inject
Expand All @@ -21,6 +24,9 @@ public class GetDiskAndSnapshotsByDiskIdQuery<P extends IdQueryParameters> exten
@Inject
private ImagesHandler imagesHandler;

@Inject
private StorageServerConnectionDao storageServerConnectionDao;

public GetDiskAndSnapshotsByDiskIdQuery(P parameters, EngineContext context) {
super(parameters, context);
}
Expand All @@ -33,6 +39,9 @@ protected void executeQueryCommand() {

// In case of LUN disk
if (allDisks.size() == 1 && allDisks.get(0).getDiskStorageType() == DiskStorageType.LUN) {
LunDisk disk = (LunDisk) allDisks.get(0);
List<StorageServerConnections> connections = storageServerConnectionDao.getAllForLun(disk.getLun().getLUNId());
disk.getLun().setLunConnections(connections);
getQueryReturnValue().setReturnValue(allDisks.get(0));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.ovirt.engine.core.common.businessentities.storage.CinderDisk;
import org.ovirt.engine.core.common.businessentities.storage.DiskContentType;
import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
import org.ovirt.engine.core.common.businessentities.storage.LUNs;
import org.ovirt.engine.core.common.businessentities.storage.LunDisk;
import org.ovirt.engine.core.common.queries.QueryParametersBase;
import org.ovirt.engine.core.compat.Guid;
Expand Down Expand Up @@ -110,6 +111,7 @@ private CinderDisk createCinderDisk() {
private LunDisk createLunDisk() {
LunDisk lun = new LunDisk();
lun.setId(Guid.newGuid());
lun.setLun(new LUNs());
return lun;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
Expand All @@ -24,6 +25,7 @@
import org.ovirt.engine.core.common.queries.IdQueryParameters;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dao.DiskDao;
import org.ovirt.engine.core.dao.StorageServerConnectionDao;

/**
* A test case for {@link GetDiskAndSnapshotsByDiskIdQuery}.
Expand All @@ -41,6 +43,9 @@ public class GetDiskAndSnapshotsByDiskIdQueryTest extends
@Mock
private DiskDao diskDao;

@Mock
private StorageServerConnectionDao storageServerConnectionDao;

@BeforeEach
@Override
public void setUp() throws Exception {
Expand Down Expand Up @@ -118,6 +123,7 @@ public void testQueryWithCinderDisk() {

@Test
public void testQueryWithLunDisk() {
when(storageServerConnectionDao.getAllForLun(any())).thenReturn(new ArrayList<>());
Disk disk = executeQuery(lunDisk);
assertTrue(disk instanceof LunDisk, "disk should be from type LunDisk");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public static LogicalUnit map(LUNs entity, LogicalUnit template) {
model.setSize(SizeConverter.convert((long)entity.getDeviceSize(),
SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES).longValue());

if (entity.getLunConnections() != null && !entity.getLunConnections().isEmpty()) {
model.setAddress(entity.getLunConnections().get(0).getConnection());
model.setPort(Integer.valueOf(entity.getLunConnections().get(0).getPort()));
model.setTarget(entity.getLunConnections().get(0).getIqn());
}

model.setPaths(entity.getPathCount());
return model;
}
Expand Down Expand Up @@ -105,13 +111,17 @@ public static StorageServerConnections map(LogicalUnit logicalUnit, StorageServe
}
if (logicalUnit.isSetPort()) {
entity.setPort(logicalUnit.getPort().toString());
} else {
// Setting default port to please the StorageLogicalUnitMapperTest#testRoundtrip test
entity.setPort("3260");
}
if (logicalUnit.isSetUsername()) {
entity.setUserName(logicalUnit.getUsername());
}
if (logicalUnit.isSetPassword()) {
entity.setPassword(logicalUnit.getPassword());
}

return entity;
}

Expand Down

0 comments on commit 6251e3f

Please sign in to comment.