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

Change iSCSI storage connection validation to properly avoid duplications #551

Merged
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 @@ -207,6 +207,14 @@ public StorageServerConnections findConnectionWithSameDetails(StorageServerConne
return null;
}

public List<StorageServerConnections> findConnectionsByAddressPortAndIqn(StorageServerConnections connection) {
return storageServerConnectionDao.getStorageConnectionsByConnectionPortAndIqn(
connection.getConnection(),
connection.getPort(),
connection.getIqn()
);
}

private void fillConnectionDetailsIfNeeded(StorageServerConnections connection) {
// in case that the connection id is null (in case it wasn't loaded from the db before) - we can attempt to load
// it from the db by its details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ protected String isConnWithSameDetailsExists(StorageServerConnections connection
String connectionField = connection.getConnection();
connections = storageServerConnectionDao.getAllForStorage(connectionField);
} else {
StorageServerConnections sameConnection = iscsiStorageHelper.findConnectionWithSameDetails(connection);
connections =
sameConnection != null ? Collections.singletonList(sameConnection)
: Collections.emptyList();
connections = iscsiStorageHelper.findConnectionsByAddressPortAndIqn(connection);
}

return (connections != null && connections.size() > 0 &&
ahadas marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void isConnWithSameDetailsExist() {
StorageServerConnections existingConn = createISCSIConnection("1.2.3.4", StorageType.ISCSI, "iqn.2013-04.myhat.com:aaa-target1", "3650", "user1", "mypassword123");
existingConn.setId(Guid.newGuid().toString());

when(iscsiStorageHelper.findConnectionWithSameDetails(newISCSIConnection)).thenReturn(existingConn);
when(iscsiStorageHelper.findConnectionsByAddressPortAndIqn(newISCSIConnection)).thenReturn(Collections.singletonList(existingConn));
String isExists = command.isConnWithSameDetailsExists(newISCSIConnection, null);
assertFalse(isExists.isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,15 @@ public void isConnWithSameDetailsExistBlockDomains() {
StorageServerConnections newISCSIConnection = createISCSIConnection("1.2.3.4", StorageType.ISCSI, "iqn.2013-04.myhat.com:aaa-target1", "3260", "user1", "mypassword123");

StorageServerConnections connection1 = createISCSIConnection("1.2.3.4", StorageType.ISCSI, "iqn.2013-04.myhat.com:aaa-target1", "3260", "user1", "mypassword123");
when(iscsiStorageHelper.findConnectionWithSameDetails(newISCSIConnection)).thenReturn(connection1);
when(iscsiStorageHelper.findConnectionsByAddressPortAndIqn(newISCSIConnection)).thenReturn(Collections.singletonList(connection1));
boolean isExists = !command.isConnWithSameDetailsExists(newISCSIConnection, null).isEmpty();
assertTrue(isExists);
}

@Test
public void isConnWithSameDetailsExistCheckSameConn() {
StorageServerConnections newISCSIConnection = createISCSIConnection("1.2.3.4", StorageType.ISCSI, "iqn.2013-04.myhat.com:aaa-target1", "3260", "user1", "mypassword123");
when(iscsiStorageHelper.findConnectionWithSameDetails(newISCSIConnection)).thenReturn(newISCSIConnection);
when(iscsiStorageHelper.findConnectionsByAddressPortAndIqn(newISCSIConnection)).thenReturn(Collections.singletonList(newISCSIConnection));
boolean isExists = !command.isConnWithSameDetailsExists(newISCSIConnection, null).isEmpty();
assertTrue(isExists);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ List<StorageServerConnections> getStorageConnectionsByStorageTypeAndStatus(Guid
List<StorageServerConnections> getAllForConnection(
StorageServerConnections connection);

/**
* Retrieves all connections for the specified address, port and iqn
*
* @param connection the address of the connection
* @param port the port of the connection
* @param iqn the IQN (iSCSI Qualified Name) of the connection
* @return the list of connections
*/
List<StorageServerConnections> getStorageConnectionsByConnectionPortAndIqn(
String connection, String port, String iqn);

/**
* Retrieves all connections used by the specified storage domain
* @return the list of connections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ public List<StorageServerConnections> getAllForConnection(
.addValue("username", connection.getUserName()));
}

@Override
public List<StorageServerConnections> getStorageConnectionsByConnectionPortAndIqn(
ahadas marked this conversation as resolved.
Show resolved Hide resolved
String connection, String port, String iqn) {
return getCallsHandler().executeReadList("GetStorageConnectionsByConnectionPortAndIqn",
mapper,
getCustomMapSqlParameterSource()
.addValue("iqn", iqn)
.addValue("connection", connection)
.addValue("port", port));
}


@Override
public List<StorageServerConnections> getAllForDomain(Guid domainId) {
return getCallsHandler().executeReadList("GetStorageServerConnectionsForDomain", mapper,
Expand Down
18 changes: 18 additions & 0 deletions packaging/dbscripts/storages_san_sp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,24 @@ BEGIN
END;$PROCEDURE$
LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION GetStorageConnectionsByConnectionPortAndIqn (
v_iqn VARCHAR(128),
v_connection VARCHAR(250),
v_port VARCHAR(50)
)
RETURNS SETOF storage_server_connections STABLE AS $PROCEDURE$
BEGIN
RETURN QUERY

SELECT *
FROM storage_server_connections
WHERE iqn = v_iqn
AND connection = v_connection
AND port = v_port;
END;$PROCEDURE$
LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION Getstorage_server_connectionsByStorageType (v_storage_type INT)
RETURNS SETOF storage_server_connections STABLE AS $PROCEDURE$
BEGIN
Expand Down