Skip to content
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 @@ -149,9 +149,9 @@ public static StorageStrategy getStrategyByStoragePoolDetails(Map<String, String
}

public static String getIgroupName(String svmName, String hostUuid) {
//Igroup name format: cs_svmName_hostUuid
//Igroup name format: cs_hostUuid_svmName

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For normal CloudStack UUIDs (hex + hyphens), sanitization is a no-op, so 550e8400-e29b-41d4-a716-446655440000 stays as-is. It only matters if the input has characters outside [a-zA-Z0-9_-].

String sanitizedHostUuid = hostUuid.replaceAll("[^a-zA-Z0-9_-]", "_");
String igroupName = OntapStorageConstants.CS + OntapStorageConstants.UNDERSCORE + svmName + OntapStorageConstants.UNDERSCORE + sanitizedHostUuid;
String igroupName = OntapStorageConstants.CS + OntapStorageConstants.UNDERSCORE + sanitizedHostUuid + OntapStorageConstants.UNDERSCORE + svmName;
// ONTAP igroup names are limited to 96 characters; truncate if longer.
Comment on lines 151 to 155

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will try to push this change in 4.23 so that we will not see this issue during upgrade

if (igroupName.length() > OntapStorageConstants.IGROUP_NAME_MAX_LENGTH) {
igroupName = igroupName.substring(0, OntapStorageConstants.IGROUP_NAME_MAX_LENGTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class OntapStorageUtilsTest {
public void getIgroupName_returnsExpectedFormat_whenWithinLimit() {
String result = OntapStorageUtils.getIgroupName("svm1", "host-uuid-123");

assertEquals("cs_svm1_host-uuid-123", result);
assertEquals("cs_host-uuid-123_svm1", result);
assertTrue(result.length() <= OntapStorageConstants.IGROUP_NAME_MAX_LENGTH);
}

Expand All @@ -38,20 +38,20 @@ public void getIgroupName_sanitizesInvalidCharacters() {
// Characters outside [a-zA-Z0-9_-] in the host uuid must be replaced with '_'.
String result = OntapStorageUtils.getIgroupName("svm1", "host.uuid:123/abc");

assertEquals("cs_svm1_host_uuid_123_abc", result);
assertEquals("cs_host_uuid_123_abc_svm1", result);
}

@Test
public void getIgroupName_doesNotTruncate_whenExactlyAtMaxLength() {
// Format: cs(2) + _(1) + svmName + _(1) + hostUuid
// Format: cs(2) + _(1) + hostUuid + _(1) + svmName
// For an overall length of 96 with a 4-char uuid, svmName must be 88 chars.
String svmName = "a".repeat(88);
String hostUuid = "uuid";

String result = OntapStorageUtils.getIgroupName(svmName, hostUuid);

assertEquals(OntapStorageConstants.IGROUP_NAME_MAX_LENGTH, result.length());
assertEquals("cs_" + svmName + "_" + hostUuid, result);
assertEquals("cs_" + hostUuid + "_" + svmName, result);
}

@Test
Expand All @@ -63,15 +63,15 @@ public void getIgroupName_truncates_whenExceedingMaxLength() {

assertEquals(OntapStorageConstants.IGROUP_NAME_MAX_LENGTH, result.length());
// The truncated value must still be a prefix of the full, untruncated name.
String fullName = "cs_" + svmName + "_" + hostUuid;
String fullName = "cs_" + hostUuid + "_" + svmName;
assertEquals(fullName.substring(0, OntapStorageConstants.IGROUP_NAME_MAX_LENGTH), result);
assertTrue(result.startsWith("cs_"));
}

@Test
public void getIgroupName_truncates_whenOneCharOverMaxLength() {
// Build a name that is exactly one character over the limit (97 chars):
// svmName of 89 chars + 4-char uuid -> 2 + 1 + 89 + 1 + 4 = 97.
// svmName of 89 chars + 4-char uuid -> 2 + 1 + 4 + 1 + 89 = 97.
String svmName = "a".repeat(89);
String hostUuid = "uuid";

Expand Down
Loading