Skip to content

Commit 104b769

Browse files
suryag1201Gupta, Surya
andauthored
[CSTACKEX-216] Review Comments for Igroup Name Length (#79)
### Description Issue: "getIgroupName() truncates the full "cs__" string as a whole. If svmName is long, this can truncate away most or all of the hostUuid portion, increasing the chance of igroup name collisions across different hosts (and also throws a NullPointerException if hostUuid is null). Consider validating inputs and truncating svmName first so the host UUID remains intact (or, if hostUuid itself is too long, truncate only the UUID)." Fix: In typical deployments, truncation likely never triggers bcz total length will remain less than 96. But to avoid any issues for future where svm limits get exceeded, will change the igroup format to cs_hostUuid_svmName Note: This is a breaking change for existing deployments. Igroups already on ONTAP use the old format (cs_svm1_hostname). After this change, CloudStack will look for cs_<uuid>_svm1 and may not find existing igroup <!--- ******************************************************************************* --> <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. --> <!--- PLEASE PUT AN 'X' in only **ONE** box --> <!--- ******************************************************************************* --> ### Types of changes - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Enhancement (improves an existing feature and functionality) - [ ] Cleanup (Code refactoring and cleanup, that may add test cases) - [ ] Build/CI - [ ] Test (unit or integration test code) ### Feature/Enhancement Scale or Bug Severity #### Feature/Enhancement Scale - [ ] Major - [ ] Minor #### Bug Severity - [ ] BLOCKER - [ ] Critical - [ ] Major - [ ] Minor - [ ] Trivial ### Screenshots (if appropriate): <img width="1383" height="321" alt="image" src="https://github.com/user-attachments/assets/d051a3d3-7069-4936-a21c-d53b1ba368f6" /> <img width="1505" height="766" alt="image" src="https://github.com/user-attachments/assets/128256ef-d000-41a3-9359-78f48d45eced" /> ### How Has This Been Tested? 1- Created 1st VM on ISCSI Storage pool - Igroup got create with new name format attached a screen shot and lun got mapped 2- Create 2nd VM on same storage pool - Igroup got reused and lun got mapped 3- Storage Pool to enter maintenance mode - All Luns got unmapped and igroup also got deleted 4- Storage Pool to cancel maintenance mode - New Igroup got created with same name format and All Luns got mapped again. 5-Create a new CloudStack volume and attched to the instance - used the existing igroup and mapped the lun 6- Delete All VMs - Igroup got deleted #### How did you try to break this feature and the system with this change? <!-- see how your change affects other areas of the code, etc. --> <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document --> Co-authored-by: Gupta, Surya <Surya.Gupta@netapp.com>
1 parent a59b49e commit 104b769

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ public static StorageStrategy getStrategyByStoragePoolDetails(Map<String, String
149149
}
150150

151151
public static String getIgroupName(String svmName, String hostUuid) {
152-
//Igroup name format: cs_svmName_hostUuid
152+
//Igroup name format: cs_hostUuid_svmName
153153
String sanitizedHostUuid = hostUuid.replaceAll("[^a-zA-Z0-9_-]", "_");
154-
String igroupName = OntapStorageConstants.CS + OntapStorageConstants.UNDERSCORE + svmName + OntapStorageConstants.UNDERSCORE + sanitizedHostUuid;
154+
String igroupName = OntapStorageConstants.CS + OntapStorageConstants.UNDERSCORE + sanitizedHostUuid + OntapStorageConstants.UNDERSCORE + svmName;
155155
// ONTAP igroup names are limited to 96 characters; truncate if longer.
156156
if (igroupName.length() > OntapStorageConstants.IGROUP_NAME_MAX_LENGTH) {
157157
igroupName = igroupName.substring(0, OntapStorageConstants.IGROUP_NAME_MAX_LENGTH);

plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/utils/OntapStorageUtilsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class OntapStorageUtilsTest {
2929
public void getIgroupName_returnsExpectedFormat_whenWithinLimit() {
3030
String result = OntapStorageUtils.getIgroupName("svm1", "host-uuid-123");
3131

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

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

41-
assertEquals("cs_svm1_host_uuid_123_abc", result);
41+
assertEquals("cs_host_uuid_123_abc_svm1", result);
4242
}
4343

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

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

5353
assertEquals(OntapStorageConstants.IGROUP_NAME_MAX_LENGTH, result.length());
54-
assertEquals("cs_" + svmName + "_" + hostUuid, result);
54+
assertEquals("cs_" + hostUuid + "_" + svmName, result);
5555
}
5656

5757
@Test
@@ -63,15 +63,15 @@ public void getIgroupName_truncates_whenExceedingMaxLength() {
6363

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

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

0 commit comments

Comments
 (0)