Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core,restapi: report iscsi server address and port for direct LUNs #559

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 +39,10 @@ protected void executeQueryCommand() {

// In case of LUN disk
if (allDisks.size() == 1 && allDisks.get(0).getDiskStorageType() == DiskStorageType.LUN) {
getQueryReturnValue().setReturnValue(allDisks.get(0));
LunDisk disk = (LunDisk) allDisks.get(0);
List<StorageServerConnections> connections = storageServerConnectionDao.getAllForLun(disk.getLun().getLUNId());
disk.getLun().setLunConnections(connections);
getQueryReturnValue().setReturnValue(disk);
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 @@ -13,6 +13,7 @@ public class StorageServerConnections implements BusinessEntity<String> {
private static final long serialVersionUID = 5444293590307760809L;

public static final String DEFAULT_TPGT = "1";
public static final String DEFAULT_ISCSI_PORT = "3260";

public StorageServerConnections() {
storageType = StorageType.UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ovirt.engine.api.restapi.resource;

import static org.ovirt.engine.core.common.businessentities.StorageServerConnections.DEFAULT_ISCSI_PORT;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -89,8 +91,6 @@ public class BackendHostResource extends AbstractBackendActionableResource<Host,
public static final String FORCE = "force";
public static final String STOP_GLUSTER_SERVICE = "stop_gluster_service";

private static final String DEFAULT_ISCSI_PORT = "3260";

private BackendHostsResource parent;

public BackendHostResource(String id, BackendHostsResource parent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.ovirt.engine.api.restapi.types;

import static org.ovirt.engine.core.common.businessentities.StorageServerConnections.DEFAULT_ISCSI_PORT;


import java.util.ArrayList;

import org.ovirt.engine.api.model.HostStorage;
Expand Down Expand Up @@ -48,6 +51,13 @@ 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()) {
StorageServerConnections lunConnection = entity.getLunConnections().get(0);
model.setAddress(lunConnection.getConnection());
model.setPort(Integer.valueOf(lunConnection.getPort()));
model.setTarget(lunConnection.getIqn());
}

model.setPaths(entity.getPathCount());
return model;
}
Expand Down Expand Up @@ -105,13 +115,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(DEFAULT_ISCSI_PORT);
}
if (logicalUnit.isSetUsername()) {
entity.setUserName(logicalUnit.getUsername());
}
if (logicalUnit.isSetPassword()) {
entity.setPassword(logicalUnit.getPassword());
}

return entity;
}

Expand Down