From e477353b1c52af578c03a350e7fee7b5a212dcd5 Mon Sep 17 00:00:00 2001 From: sandeeplocharla Date: Mon, 9 Nov 2026 16:50:34 +0530 Subject: [PATCH 1/3] CSTACKEX-367: Remove LUN-map logical unit number dead code Since the managed iSCSI path became // (PR #114), nothing consumes the LUN-map logical unit number. Stop fetching and returning it: - enableLogicalAccess/ensureLunMapped now return void; the follow-up lun-maps GET that only read the number is removed - getLogicalAccess returns boolean (mapping exists) - drop OntapStorageConstants.LOGICAL_UNIT_NUMBER and LUN-number logging in OntapPrimaryDatastoreDriver - update unit tests, asserting a new mapping needs one lookup and one create # Conflicts: # plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java # plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java # plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java --- .../driver/OntapPrimaryDatastoreDriver.java | 13 +- .../storage/service/SANStrategy.java | 6 +- .../storage/service/StorageStrategy.java | 7 +- .../storage/service/UnifiedNASStrategy.java | 7 +- .../storage/service/UnifiedSANStrategy.java | 48 +++---- .../storage/utils/OntapStorageConstants.java | 1 - .../OntapPrimaryDatastoreDriverTest.java | 12 +- .../storage/service/StorageStrategyTest.java | 7 +- .../service/UnifiedSANStrategyTest.java | 119 ++++++------------ 9 files changed, 78 insertions(+), 142 deletions(-) diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java index 1375d5d17c2d..627fbd808426 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java @@ -1555,10 +1555,10 @@ private void grantAccessIscsi(Host host, VolumeVO volumeVO, Map ensureAccessGroupForHost(sanStrategy, host, storagePool, svmName, accessGroupName); // Create or retrieve existing LUN mapping. - String lunNumber = sanStrategy.ensureLunMapped(svmName, cloudStackVolumeName, accessGroupName); + sanStrategy.ensureLunMapped(svmName, cloudStackVolumeName, accessGroupName); String lunWwid = resolveVolumeLunWwid(sanStrategy, svmName, cloudStackVolumeName, volumeVO.getId()); - logger.debug("grantAccessIscsi: LUN [{}] mapped to igroup [{}] as logical unit number [{}], WWID [{}]", - cloudStackVolumeName, accessGroupName, lunNumber, lunWwid); + logger.debug("grantAccessIscsi: LUN [{}] mapped to igroup [{}], WWID [{}]", + cloudStackVolumeName, accessGroupName, lunWwid); // Update volume path if changed (e.g. the WWID was not yet known for a pre-existing volume) String iscsiPath = buildIscsiPath(storagePool, lunWwid); @@ -1573,7 +1573,7 @@ private void grantAccessIscsi(Host host, VolumeVO volumeVO, Map * *

Called by the framework from {@code copyTemplateToManagedTemplateVolume} just before it * issues the {@code CopyCommand}. That method reads {@code managedStoreTarget} from the pool - * details before this call, when the LUN number does not exist yet, so the stale + * details before this call, when the LUN WWID is not yet known, so the stale * value is corrected here. The datastore details are re-read when the command is built, so the * update lands in time.

*/ @@ -1595,13 +1595,12 @@ private void grantAccessTemplate(TemplateInfo templateInfo, Host host, DataStore boolean lunMapped = false; try { - String lunNumber = sanStrategy.ensureLunMapped(svmName, lunName, accessGroupName); + sanStrategy.ensureLunMapped(svmName, lunName, accessGroupName); lunMapped = true; // The template cache LUN has no volume_details row to cache the WWID in, and this runs // once per template per pool, so it is fetched from the array each time. String lunWwid = fetchLunWwid(sanStrategy, svmName, lunName); - logger.debug("grantAccessTemplate: template cache LUN [{}] mapped as logical unit number [{}], WWID [{}]", - lunName, lunNumber, lunWwid); + logger.debug("grantAccessTemplate: template cache LUN [{}] mapped, WWID [{}]", lunName, lunWwid); String iscsiPath = buildIscsiPath(storagePool, lunWwid); templatePoolRef.setInstallPath(iscsiPath); diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/SANStrategy.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/SANStrategy.java index 4b1bca00f95c..7713708e450f 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/SANStrategy.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/SANStrategy.java @@ -33,15 +33,13 @@ public SANStrategy(OntapStorage ontapStorage) { /** * Ensures the LUN is mapped to the specified access group (igroup). - * If a mapping already exists, returns the existing LUN number. - * If not, creates a new mapping and returns the assigned LUN number. + * If a mapping already exists, nothing is done; otherwise a new mapping is created. * * @param svmName the SVM name * @param lunName the LUN name * @param accessGroupName the igroup name - * @return the logical unit number as a String */ - public abstract String ensureLunMapped(String svmName, String lunName, String accessGroupName); + public abstract void ensureLunMapped(String svmName, String lunName, String accessGroupName); /** * Validates that the host initiator is present in the access group (igroup). diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/StorageStrategy.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/StorageStrategy.java index 64a6f1af4e0a..dfbfdcaef1e2 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/StorageStrategy.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/StorageStrategy.java @@ -1056,9 +1056,8 @@ public abstract JobResponse revertSnapshotForCloudStackVolume(String snapshotNam * //TODO for NFS 3.0 and NFS 4.1 protocols (e.g., export rule management) * //TODO for Nvme/TCP and Nvme/FC protocols * @param values map including SVM name, LUN name, and igroup name (for SAN) or equivalent for NAS - * @return String containing logical unit number for the new/existing mapping (SAN) or relevant info for NAS */ - abstract public String enableLogicalAccess(Map values); + abstract public void enableLogicalAccess(Map values); /** * Method encapsulates the behavior based on the opted protocol in subclasses @@ -1071,9 +1070,9 @@ public abstract JobResponse revertSnapshotForCloudStackVolume(String snapshotNam * Method encapsulates the behavior based on the opted protocol in subclasses * lunMap lookup for iSCSI/FC protocols (GET-only, no side-effects) * @param values map with SVM name, LUN name, and igroup name (for SAN) or equivalent for NAS - * @return String containing logical unit number if mapping exists; otherwise null + * @return true if the mapping exists; otherwise false */ - abstract public String getLogicalAccess(Map values); + abstract public boolean getLogicalAccess(Map values); // ── FlexVolume Snapshot accessors ──────────────────────────────────────── diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java index 18bc3116259d..9f6720d6dede 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java @@ -507,8 +507,7 @@ public AccessGroup getAccessGroup(Map values) { } @Override - public String enableLogicalAccess(Map values) { - return null; + public void enableLogicalAccess(Map values) { } @Override @@ -516,8 +515,8 @@ public void disableLogicalAccess(Map values) { } @Override - public String getLogicalAccess(Map values) { - return null; + public boolean getLogicalAccess(Map values) { + return false; } private ExportPolicy createExportPolicy(String svmName, ExportPolicy policy) { diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java index 21e58a00a8bc..bc056e431dd2 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.storage.service; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -856,9 +855,8 @@ public AccessGroup getAccessGroup(Map values) { } @Override - public String enableLogicalAccess(Map values) { + public void enableLogicalAccess(Map values) { logger.trace("enableLogicalAccess : Creating LunMap with values {} ", values); - String lunNumber = null; if (values == null) { logger.error("enableLogicalAccess: LunMap creation failed. Invalid request values: null"); throw new CloudRuntimeException("Failed to create LunMap, invalid request"); @@ -898,13 +896,11 @@ public String enableLogicalAccess(Map values) { throw feignEx; } } - logger.trace("enableLogicalAccess: LunMap created for Lun: {} and igroup: {}", lunName, igroupName); - lunNumber = ""; + logger.trace("enableLogicalAccess: LunMap ensured for Lun: {} and igroup: {}", lunName, igroupName); } catch (Exception e) { logger.error("Exception occurred while creating LunMap", e); throw new CloudRuntimeException("Failed to create LunMap: " + e.getMessage()); } - return lunNumber; } public void disableLogicalAccess(Map values) { @@ -936,10 +932,9 @@ public void disableLogicalAccess(Map values) { } } - // GET-only helper: fetch LUN-map and return logical unit number if it exists; otherwise return null + // GET-only helper: returns true if the LUN-map exists; otherwise false @Override - public String getLogicalAccess(Map values) { - String lunNumber = null; + public boolean getLogicalAccess(Map values) { logger.trace("getLogicalAccess : Fetching LunMap with values {} ", values); if (values == null) { logger.error("getLogicalAccess: Invalid request values: null"); @@ -958,46 +953,31 @@ public String getLogicalAccess(Map values) { Map.of( OntapStorageConstants.SVM_DOT_NAME, svmName, OntapStorageConstants.LUN_DOT_NAME, lunName, - OntapStorageConstants.IGROUP_DOT_NAME, igroupName, - OntapStorageConstants.FIELDS, OntapStorageConstants.LOGICAL_UNIT_NUMBER + OntapStorageConstants.IGROUP_DOT_NAME, igroupName )); - if (lunMapResponse != null && lunMapResponse.getRecords() != null && !lunMapResponse.getRecords().isEmpty()) { - Integer lunLogicalUnitNum = lunMapResponse.getRecords().get(0).getLogicalUnitNumber(); - lunNumber = lunLogicalUnitNum != null ? lunLogicalUnitNum.toString() : null; - } + return lunMapResponse != null && lunMapResponse.getRecords() != null && !lunMapResponse.getRecords().isEmpty(); } catch (Exception e) { logger.warn("getLogicalAccess: LunMap not found for Lun: {} and igroup: {} ({}).", lunName, igroupName, e.getMessage()); + return false; } - return lunNumber; } @Override - public String ensureLunMapped(String svmName, String lunName, String accessGroupName) { + public void ensureLunMapped(String svmName, String lunName, String accessGroupName) { logger.trace("ensureLunMapped: Ensuring LUN [{}] is mapped to igroup [{}] on SVM [{}]", lunName, accessGroupName, svmName); - // Check existing map first - Map getMap = Map.of( + Map mapRequest = Map.of( OntapStorageConstants.LUN_DOT_NAME, lunName, OntapStorageConstants.SVM_DOT_NAME, svmName, OntapStorageConstants.IGROUP_DOT_NAME, accessGroupName ); - String lunNumber = getLogicalAccess(getMap); - if (lunNumber != null) { - logger.info("ensureLunMapped: Existing LunMap found for LUN [{}] in igroup [{}] with LUN number [{}]", lunName, accessGroupName, lunNumber); - return lunNumber; + if (getLogicalAccess(mapRequest)) { + logger.info("ensureLunMapped: Existing LunMap found for LUN [{}] in igroup [{}]", lunName, accessGroupName); + return; } - // Create if not exists - Map enableMap = new HashMap<>(); - enableMap.put(OntapStorageConstants.LUN_DOT_NAME, lunName); - enableMap.put(OntapStorageConstants.SVM_DOT_NAME, svmName); - enableMap.put(OntapStorageConstants.IGROUP_DOT_NAME, accessGroupName); - String response = enableLogicalAccess(enableMap); - if (response == null ) { - throw new CloudRuntimeException("Failed to map LUN [" + lunName + "] to iGroup [" + accessGroupName + "]"); - } - logger.trace("ensureLunMapped: Successfully mapped LUN [{}] to igroup [{}] with LUN number [{}]", lunName, accessGroupName, response); - return response; + enableLogicalAccess(mapRequest); + logger.trace("ensureLunMapped: Successfully mapped LUN [{}] to igroup [{}]", lunName, accessGroupName); } /** diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java index 7fb765cbaf4d..8e5ae6c44f8b 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/OntapStorageConstants.java @@ -138,7 +138,6 @@ public class OntapStorageConstants { public static final String QOS_POLICY_NAME_IOPS = "iops_"; public static final String UUID = "uuid"; public static final String QOS_POLICY_OBJECT_COUNT_FIELDS = "uuid,name,object_count"; - public static final String LOGICAL_UNIT_NUMBER = "logical_unit_number"; public static final String IGROUP_DOT_NAME = "igroup.name"; public static final String IGROUP_DOT_UUID = "igroup.uuid"; public static final String UNDERSCORE = "_"; diff --git a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java index 5c07a66088a0..f0b60f131c7d 100644 --- a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java +++ b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java @@ -744,7 +744,7 @@ void testGrantAccess_ClusterScope_Success() { .thenReturn("igroup1"); when(sanStrategy.getAccessGroup(any())).thenReturn(existingAccessGroup); - when(sanStrategy.ensureLunMapped(anyString(), anyString(), anyString())).thenReturn("7"); + doNothing().when(sanStrategy).ensureLunMapped(anyString(), anyString(), anyString()); when(sanStrategy.getLunSerialNumber(anyString(), anyString())).thenReturn(LUN_SERIAL_NUMBER); // Execute @@ -845,7 +845,7 @@ void testGrantAccess_IgroupNotFound_CreatesNewIgroup() { when(sanStrategy.getAccessGroup(any())).thenReturn(null); when(sanStrategy.createAccessGroup(any())).thenReturn(createdAccessGroup); - when(sanStrategy.ensureLunMapped(anyString(), anyString(), anyString())).thenReturn("0"); + doNothing().when(sanStrategy).ensureLunMapped(anyString(), anyString(), anyString()); when(sanStrategy.getLunSerialNumber(anyString(), anyString())).thenReturn(LUN_SERIAL_NUMBER); // Execute @@ -2037,7 +2037,7 @@ void testGrantAccess_Template_WritesInstallPathAndRefreshesStoreTarget() { utilityMock.when(() -> OntapStorageUtils.getIgroupName(anyString(), anyString())).thenReturn("igroup1"); when(sanStrategy.getAccessGroup(any())).thenReturn(existingAccessGroup); - when(sanStrategy.ensureLunMapped(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"), eq("igroup1"))).thenReturn("3"); + doNothing().when(sanStrategy).ensureLunMapped(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"), eq("igroup1")); when(sanStrategy.getLunSerialNumber(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"))).thenReturn(LUN_SERIAL_NUMBER); assertTrue(driver.grantAccess(templateInfo, host, primaryDataStore)); @@ -2093,7 +2093,7 @@ void testGrantAccess_Template_UnmapsWhenInstallPathUpdateFails() { utilityMock.when(() -> OntapStorageUtils.getIgroupName(anyString(), anyString())).thenReturn("igroup1"); when(sanStrategy.getAccessGroup(any())).thenReturn(existingAccessGroup); - when(sanStrategy.ensureLunMapped(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"), eq("igroup1"))).thenReturn("3"); + doNothing().when(sanStrategy).ensureLunMapped(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"), eq("igroup1")); when(sanStrategy.getLunSerialNumber(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"))).thenReturn(LUN_SERIAL_NUMBER); when(sanStrategy.getCloudStackVolume(argThat(map -> map != null && "/vol/vol1/cs_tmpl_50".equals(map.get("name"))))) @@ -3392,7 +3392,7 @@ void testGrantAccess_Template_CreatesIgroupWhenMissing() { when(sanStrategy.getAccessGroup(any())).thenReturn(null); when(sanStrategy.createAccessGroup(any())).thenReturn(createdAccessGroup); - when(sanStrategy.ensureLunMapped(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"), eq("igroup1"))).thenReturn("3"); + doNothing().when(sanStrategy).ensureLunMapped(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"), eq("igroup1")); when(sanStrategy.getLunSerialNumber(eq("svm1"), eq("/vol/vol1/cs_tmpl_50"))).thenReturn(LUN_SERIAL_NUMBER); assertTrue(driver.grantAccess(templateInfo, hostVo, primaryDataStore)); @@ -4267,7 +4267,7 @@ void testGrantAccess_TemporarySnapshotCopy_SyncsIscsiPathOnInMemoryVolume() { utilityMock.when(() -> OntapStorageUtils.getStrategyByStoragePoolDetails(storagePoolDetails)).thenReturn(sanStrategy); utilityMock.when(() -> OntapStorageUtils.getIgroupName(anyString(), anyString())).thenReturn("igroup1"); when(sanStrategy.getAccessGroup(any())).thenReturn(existingAccessGroup); - when(sanStrategy.ensureLunMapped(anyString(), anyString(), anyString())).thenReturn("0"); + doNothing().when(sanStrategy).ensureLunMapped(anyString(), anyString(), anyString()); when(sanStrategy.getLunSerialNumber(anyString(), anyString())).thenReturn(LUN_SERIAL_NUMBER); assertTrue(driver.grantAccess(volumeInfo, host, dataStore)); diff --git a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/StorageStrategyTest.java b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/StorageStrategyTest.java index 064a28ff512e..b61832d1eed1 100644 --- a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/StorageStrategyTest.java +++ b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/StorageStrategyTest.java @@ -211,8 +211,7 @@ public AccessGroup getAccessGroup(Map values) { } @Override - public String enableLogicalAccess(Map values) { - return null; + public void enableLogicalAccess(Map values) { } @Override @@ -220,8 +219,8 @@ public void disableLogicalAccess(Map values) { } @Override - public String getLogicalAccess(Map values) { - return null; + public boolean getLogicalAccess(Map values) { + return false; } } diff --git a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java index a767f483c8f8..7e9e6e76d540 100644 --- a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java +++ b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java @@ -725,16 +725,17 @@ void testEnableLogicalAccess_Success() { when(sanFeignClient.createLunMap(eq(authHeader), eq(false), any(LunMap.class))) .thenReturn(new OntapResponse<>()); - String result = unifiedSANStrategy.enableLogicalAccess(values); + // Execute + unifiedSANStrategy.enableLogicalAccess(values); - assertEquals("", result); - verify(sanFeignClient).createLunMap(eq(authHeader), eq(false), any(LunMap.class)); + // Verify: map is created and no follow-up lookup is made + verify(sanFeignClient).createLunMap(eq(authHeader), eq(true), any(LunMap.class)); verify(sanFeignClient, never()).getLunMapResponse(any(), anyMap()); } } @Test - void testEnableLogicalAccess_AlreadyMapped_ReturnsLunNumber() { + void testEnableLogicalAccess_AlreadyMapped_DoesNotThrow() { // Setup Map values = new HashMap<>(); values.put(OntapStorageConstants.SVM_DOT_NAME, "svm1"); @@ -748,9 +749,8 @@ void testEnableLogicalAccess_AlreadyMapped_ReturnsLunNumber() { Exception exception = new RuntimeException("LUN already mapped to this group"); doThrow(exception).when(sanFeignClient).createLunMap(eq(authHeader), eq(false), any(LunMap.class)); - String result = unifiedSANStrategy.enableLogicalAccess(values); - - assertEquals("", result); + // Execute / Verify + assertDoesNotThrow(() -> unifiedSANStrategy.enableLogicalAccess(values)); verify(sanFeignClient, never()).getLunMapResponse(any(), anyMap()); } } @@ -805,11 +805,8 @@ void testGetLogicalAccess_Success() { values.put(OntapStorageConstants.LUN_DOT_NAME, "/vol/vol1/lun1"); values.put(OntapStorageConstants.IGROUP_DOT_NAME, "igroup1"); - LunMap lunMap = new LunMap(); - lunMap.setLogicalUnitNumber(3); - OntapResponse response = new OntapResponse<>(); - response.setRecords(List.of(lunMap)); + response.setRecords(List.of(new LunMap())); try (MockedStatic utilityMock = mockStatic(OntapStorageUtils.class)) { utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password")) @@ -817,17 +814,13 @@ void testGetLogicalAccess_Success() { when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(response); - // Execute - String result = unifiedSANStrategy.getLogicalAccess(values); - - // Verify - assertNotNull(result); - assertEquals("3", result); + // Execute / Verify + assertTrue(unifiedSANStrategy.getLogicalAccess(values)); } } @Test - void testGetLogicalAccess_NotFound_ReturnsNull() { + void testGetLogicalAccess_NotFound_ReturnsFalse() { // Setup Map values = new HashMap<>(); values.put(OntapStorageConstants.SVM_DOT_NAME, "svm1"); @@ -841,26 +834,20 @@ void testGetLogicalAccess_NotFound_ReturnsNull() { when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())) .thenThrow(new RuntimeException("Not found")); - // Execute - String result = unifiedSANStrategy.getLogicalAccess(values); - - // Verify - assertNull(result); + // Execute / Verify + assertFalse(unifiedSANStrategy.getLogicalAccess(values)); } } @Test - void testEnsureLunMapped_ExistingMapping_ReturnsLunNumber() { + void testEnsureLunMapped_ExistingMapping_SkipsCreate() { // Setup String svmName = "svm1"; String lunName = "/vol/vol1/lun1"; String accessGroupName = "igroup1"; - LunMap lunMap = new LunMap(); - lunMap.setLogicalUnitNumber(2); - OntapResponse response = new OntapResponse<>(); - response.setRecords(List.of(lunMap)); + response.setRecords(List.of(new LunMap())); try (MockedStatic utilityMock = mockStatic(OntapStorageUtils.class)) { utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password")) @@ -869,49 +856,37 @@ void testEnsureLunMapped_ExistingMapping_ReturnsLunNumber() { when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(response); // Execute - String result = unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); + unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); // Verify - assertEquals("2", result); verify(sanFeignClient, never()).createLunMap(any(), anyBoolean(), any()); } } @Test - void testEnsureLunMapped_CreatesNewMapping_ReturnsLunNumber() { + void testEnsureLunMapped_CreatesNewMapping_SingleLookup() { // Setup String svmName = "svm1"; String lunName = "/vol/vol1/lun1"; String accessGroupName = "igroup1"; - LunMap lunMap = new LunMap(); - lunMap.setLogicalUnitNumber(4); - OntapResponse emptyResponse = new OntapResponse<>(); emptyResponse.setRecords(new ArrayList<>()); - OntapResponse response = new OntapResponse<>(); - response.setRecords(List.of(lunMap)); - try (MockedStatic utilityMock = mockStatic(OntapStorageUtils.class)) { utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password")) .thenReturn(authHeader); - // First call returns empty (no existing mapping), second call returns the new mapping - when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())) - .thenReturn(emptyResponse) // First call - no records - .thenReturn(response); // Second call after creation - + when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(emptyResponse); when(sanFeignClient.createLunMap(eq(authHeader), eq(false), any(LunMap.class))) .thenReturn(new OntapResponse<>()); // Execute - String result = unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); + unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); - ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(LunMap.class); - verify(sanFeignClient).createLunMap(eq(authHeader), eq(false), requestCaptor.capture()); - assertNull(requestCaptor.getValue().getLogicalUnitNumber()); - assertEquals("", result); + // Verify: one existence lookup and one create, no follow-up lookup + verify(sanFeignClient, times(1)).getLunMapResponse(eq(authHeader), anyMap()); + verify(sanFeignClient).createLunMap(eq(authHeader), eq(true), any(LunMap.class)); } } @@ -2159,7 +2134,7 @@ void testEnableLogicalAccess_MissingIgroupName_ThrowsException() { } @Test - void testEnableLogicalAccess_FetchLunMapFails_ThrowsException() { + void testEnableLogicalAccess_CreateLunMapFails_ThrowsException() { Map values = new HashMap<>(); values.put(OntapStorageConstants.SVM_DOT_NAME, "svm1"); values.put(OntapStorageConstants.LUN_DOT_NAME, "/vol/vol1/lun1"); @@ -2169,8 +2144,8 @@ void testEnableLogicalAccess_FetchLunMapFails_ThrowsException() { utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password")) .thenReturn(authHeader); - doThrow(new RuntimeException("ONTAP unavailable")).when(sanFeignClient) - .createLunMap(eq(authHeader), eq(false), any(LunMap.class)); + when(sanFeignClient.createLunMap(eq(authHeader), eq(true), any(LunMap.class))) + .thenThrow(new RuntimeException("Failed to create LunMap")); assertThrows(CloudRuntimeException.class, () -> unifiedSANStrategy.enableLogicalAccess(values)); @@ -2248,16 +2223,15 @@ void testEnsureLunMapped_CreateNewMapping_Success() { utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password")) .thenReturn(authHeader); - when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())) - .thenReturn(emptyResponse); - - when(sanFeignClient.createLunMap(eq(authHeader), eq(false), any(LunMap.class))) + // Single lookup returns empty (no existing mapping), then the map is created + when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(emptyResponse); + when(sanFeignClient.createLunMap(eq(authHeader), eq(true), any(LunMap.class))) .thenReturn(new OntapResponse<>()); - String result = unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); + unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); - assertEquals("", result); - verify(sanFeignClient).createLunMap(eq(authHeader), eq(false), any(LunMap.class)); + verify(sanFeignClient, times(1)).getLunMapResponse(eq(authHeader), anyMap()); + verify(sanFeignClient).createLunMap(eq(authHeader), eq(true), any(LunMap.class)); } } @@ -2274,11 +2248,9 @@ void testEnsureLunMapped_FailedToMap_ThrowsException() { utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password")) .thenReturn(authHeader); - when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())) - .thenReturn(emptyResponse); - - doThrow(new RuntimeException("ONTAP unavailable")).when(sanFeignClient) - .createLunMap(eq(authHeader), eq(false), any(LunMap.class)); + when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(emptyResponse); + when(sanFeignClient.createLunMap(eq(authHeader), eq(true), any(LunMap.class))) + .thenThrow(new RuntimeException("ONTAP rejected lun-map create")); assertThrows(CloudRuntimeException.class, () -> unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName)); @@ -2649,7 +2621,7 @@ void testGetLogicalAccess_MissingIgroupName_ThrowsException() { } @Test - void testGetLogicalAccess_EmptyResponse_ReturnsNull() { + void testGetLogicalAccess_EmptyResponse_ReturnsFalse() { Map values = new HashMap<>(); values.put(OntapStorageConstants.SVM_DOT_NAME, "svm1"); values.put(OntapStorageConstants.LUN_DOT_NAME, "/vol/vol1/lun1"); @@ -2664,14 +2636,12 @@ void testGetLogicalAccess_EmptyResponse_ReturnsNull() { when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(emptyResponse); - String result = unifiedSANStrategy.getLogicalAccess(values); - - assertNull(result); + assertFalse(unifiedSANStrategy.getLogicalAccess(values)); } } @Test - void testGetLogicalAccess_ExceptionThrown_ReturnsNull() { + void testGetLogicalAccess_ExceptionThrown_ReturnsFalse() { Map values = new HashMap<>(); values.put(OntapStorageConstants.SVM_DOT_NAME, "svm1"); values.put(OntapStorageConstants.LUN_DOT_NAME, "/vol/vol1/lun1"); @@ -2684,9 +2654,7 @@ void testGetLogicalAccess_ExceptionThrown_ReturnsNull() { when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())) .thenThrow(new RuntimeException("Connection failed")); - String result = unifiedSANStrategy.getLogicalAccess(values); - - assertNull(result); + assertFalse(unifiedSANStrategy.getLogicalAccess(values)); } } @@ -2770,17 +2738,14 @@ void testDeleteAccessGroup_NotFoundInResponse_SkipsDeletion() { } @Test - void testEnsureLunMapped_ExistingMapping_ReturnsExistingNumber() { + void testEnsureLunMapped_ExistingMapping_DoesNotCreateAgain() { // Setup String svmName = "svm1"; String lunName = "/vol/vol1/lun1"; String accessGroupName = "igroup1"; - LunMap lunMap = new LunMap(); - lunMap.setLogicalUnitNumber(3); - OntapResponse response = new OntapResponse<>(); - response.setRecords(List.of(lunMap)); + response.setRecords(List.of(new LunMap())); try (MockedStatic utilityMock = mockStatic(OntapStorageUtils.class)) { utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password")) @@ -2789,10 +2754,8 @@ void testEnsureLunMapped_ExistingMapping_ReturnsExistingNumber() { when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(response); // Execute - String result = unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); + unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); - // Verify - assertEquals("3", result); // Verify createLunMap was NOT called verify(sanFeignClient, never()).createLunMap(any(), anyBoolean(), any(LunMap.class)); } From 040077092c89a0d94b0035377e9663b87d44c82b Mon Sep 17 00:00:00 2001 From: sandeeplocharla Date: Mon, 12 Oct 2026 10:29:53 +0530 Subject: [PATCH 2/3] Addressing comments from Claude --- .../cloud/vm/VirtualMachineManagerImpl.java | 1 + .../kvm/storage/KVMStorageProcessor.java | 2 - plugins/storage/volume/ontap/pom.xml | 5 --- .../driver/OntapPrimaryDatastoreDriver.java | 3 +- .../storage/service/UnifiedSANStrategy.java | 6 ++- .../OntapPrimaryDatastoreDriverTest.java | 38 +++++++++++++++++++ 6 files changed, 45 insertions(+), 10 deletions(-) diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index 043bfbb22a15..8bbaa45c38d7 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -3564,6 +3564,7 @@ protected boolean isSupportedOntapLiveStorageMigration(StoragePoolVO currentPool return false; } + // Same rule as OntapDataMotionStrategy.isSupportedOntapMigrationPoolPair; keep both copies in sync. Map currentDetails = _storagePoolDao.getDetails(currentPool.getId()); Map targetDetails = _storagePoolDao.getDetails(targetPool.getId()); if (currentDetails == null || targetDetails == null) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index a0354a783e36..04bfc56dee6f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -3457,8 +3457,6 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { if (!storagePoolMgr.connectPhysicalDisk(destPrimaryStore.getPoolType(), destPrimaryStore.getUuid(), destVolumePath, destDetails)) { logger.warn("Failed to connect dest volume {}, in storage pool {}", destVol, destPrimaryStore); } - } - if (destPrimaryStore.isManaged()) { destVolumeName = StringUtils.defaultIfBlank( derivePath(destPrimaryStore, destData, destDetails), destVolumePath); } else { diff --git a/plugins/storage/volume/ontap/pom.xml b/plugins/storage/volume/ontap/pom.xml index 1ffb2ceb4808..05929c188c92 100644 --- a/plugins/storage/volume/ontap/pom.xml +++ b/plugins/storage/volume/ontap/pom.xml @@ -86,11 +86,6 @@ cloud-engine-storage-volume ${project.version} - - org.apache.cloudstack - cloud-engine-storage-datamotion - ${project.version} - org.apache.cloudstack cloud-framework-cluster diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java index 627fbd808426..a49aca9b0edb 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java @@ -1207,6 +1207,7 @@ private boolean isCompatibleIscsiOfflineCopy(DataObject srcData, DataObject dest } private boolean areCompatibleIscsiCopyPools(Map srcDetails, Map destDetails) { + // This check is narrower than the core migration rule because canCopy already requires two ONTAP iSCSI pools. if (srcDetails == null || destDetails == null || !isIscsi(srcDetails) || !isIscsi(destDetails) || !StringUtils.equals(srcDetails.get(OntapStorageConstants.STORAGE_IP), @@ -1240,8 +1241,6 @@ private String persistCopiedVolume(VolumeInfo destVolumeInfo, StoragePoolVO dest destVolumeVO.setFolder(copiedLun.getUuid()); destVolumeVO.set_iScsiName(null); copiedPath = copiedLun.getName(); - } else if (copiedVolume.getFile() != null && copiedVolume.getFile().getPath() != null) { - copiedPath = copiedVolume.getFile().getPath(); } destVolumeVO.setPath(copiedPath); volumeDao.update(destVolumeVO.getId(), destVolumeVO); diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java index bc056e431dd2..1387525ca441 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java @@ -362,8 +362,12 @@ private CloudStackVolume buildLunCopyRequest(VolumeInfo srcVolumeInfo, VolumeInf Lun.Copy copy = new Lun.Copy(); copy.setSource(source); + String svmName = destDetails.get(OntapStorageConstants.SVM_NAME); + if (StringUtils.isBlank(svmName)) { + throw new CloudRuntimeException("Destination storage pool has no ONTAP SVM name"); + } Svm svm = new Svm(); - svm.setName(destDetails.get(OntapStorageConstants.SVM_NAME)); + svm.setName(svmName); Lun lun = new Lun(); lun.setSvm(svm); lun.setName(OntapStorageUtils.getLunName(destStoragePool.getName(), destLunName)); diff --git a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java index f0b60f131c7d..01cb2be8bff7 100644 --- a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java +++ b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java @@ -325,6 +325,19 @@ void copyAsyncUsesOntapLunCopyAndPersistsDestinationIdentity() { } } + @Test + void copyAsyncExceptionWithoutMessageCompletesCallbackWithFailure() { + VolumeInfo srcVolume = mock(VolumeInfo.class); + VolumeInfo destVolume = mock(VolumeInfo.class); + when(srcVolume.getState()).thenThrow(new RuntimeException()); + + driver.copyAsync(srcVolume, destVolume, copyCallback); + + verify(copyCallback).complete(argThat(result -> result != null + && result.isFailed() + && result.getResult().contains(RuntimeException.class.getName()))); + } + @Test void testCreateAsync_NullDataObject_ThrowsException() { assertThrows(InvalidParameterValueException.class, @@ -967,6 +980,31 @@ void testGrantAccess_NFSReady_DoesNotUpdateExportPolicy() { } } + @Test + void testGrantAccess_NFSAttachingUnattached_DoesNotUpdateExportPolicy() throws Exception { + storagePoolDetails.put(OntapStorageConstants.PROTOCOL, ProtocolType.NFS3.name()); + when(dataStore.getId()).thenReturn(1L); + when(volumeInfo.getType()).thenReturn(VOLUME); + when(volumeInfo.getId()).thenReturn(100L); + when(storagePoolDao.findById(1L)).thenReturn(storagePool); + when(storagePool.getId()).thenReturn(1L); + when(storagePool.getScope()).thenReturn(ScopeType.CLUSTER); + when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails); + when(volumeDao.findById(100L)).thenReturn(volumeVO); + when(volumeVO.getUuid()).thenReturn("vol-uuid"); + when(volumeVO.getState()).thenReturn(Volume.State.Attaching); + when(volumeVO.getInstanceId()).thenReturn(null); + + try (MockedStatic utilityMock = mockStatic(OntapStorageUtils.class, CALLS_REAL_METHODS)) { + utilityMock.when(() -> OntapStorageUtils.getStrategyByStoragePoolDetails(storagePoolDetails)) + .thenReturn(nasStrategy); + + assertTrue(driver.grantAccess(volumeInfo, host, dataStore)); + verify(nasStrategy, never()).updateAccessGroup(any()); + verify(storageManager, never()).connectHostToSharedPool(any(), anyLong()); + } + } + @Test void testGrantAccess_NFSTaggedMigrationDest_AddsHostToExportPolicy() throws Exception { storagePoolDetails.put(OntapStorageConstants.PROTOCOL, ProtocolType.NFS3.name()); From 7ef496a39f0b2a88b173131a4111d1a2ea18df4a Mon Sep 17 00:00:00 2001 From: sandeeplocharla Date: Mon, 23 Nov 2026 11:38:18 +0530 Subject: [PATCH 3/3] rebased the code --- .../driver/OntapPrimaryDatastoreDriver.java | 3 +- .../OntapPrimaryDatastoreDriverTest.java | 45 ++++++++++++++----- .../service/UnifiedSANStrategyTest.java | 12 ++--- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java index a49aca9b0edb..20ae71a13cc4 100644 --- a/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java +++ b/plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java @@ -1141,7 +1141,8 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As copiedVolumeTO.setPath(copiedPath); copiedVolumeTO.setFormat(getImageFormat(destStoragePool)); } catch (Exception e) { - errMsg = e.getMessage(); + // A null message would be read as success below, so fall back to the exception description. + errMsg = e.getMessage() != null ? e.getMessage() : e.toString(); if (storageStrategy != null && copiedVolume != null) { try { storageStrategy.deleteCloudStackVolume(copiedVolume); diff --git a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java index 01cb2be8bff7..7a65764fad60 100644 --- a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java +++ b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java @@ -329,13 +329,39 @@ void copyAsyncUsesOntapLunCopyAndPersistsDestinationIdentity() { void copyAsyncExceptionWithoutMessageCompletesCallbackWithFailure() { VolumeInfo srcVolume = mock(VolumeInfo.class); VolumeInfo destVolume = mock(VolumeInfo.class); - when(srcVolume.getState()).thenThrow(new RuntimeException()); + StoragePoolVO srcPool = mock(StoragePoolVO.class); + StoragePoolVO destPool = mock(StoragePoolVO.class); + Map srcDetails = Map.of( + OntapStorageConstants.PROTOCOL, ProtocolType.ISCSI.name(), + OntapStorageConstants.STORAGE_IP, "10.0.0.1", + OntapStorageConstants.SVM_NAME, "svm1"); + Map destDetails = new HashMap<>(srcDetails); + + when(srcVolume.getState()).thenReturn(Volume.State.Migrating); + when(srcVolume.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM); + when(srcVolume.getPoolId()).thenReturn(1L); + when(destVolume.getPoolId()).thenReturn(2L); + when(storagePoolDao.findById(1L)).thenReturn(srcPool); + when(storagePoolDao.findById(2L)).thenReturn(destPool); + when(srcPool.getId()).thenReturn(1L); + when(destPool.getId()).thenReturn(2L); + when(srcPool.getStorageProviderName()).thenReturn(DataStoreProvider.ONTAP_PLUGIN_NAME); + when(destPool.getStorageProviderName()).thenReturn(DataStoreProvider.ONTAP_PLUGIN_NAME); + when(srcPool.getPoolType()).thenReturn(Storage.StoragePoolType.OntapiSCSI); + when(destPool.getPoolType()).thenReturn(Storage.StoragePoolType.OntapiSCSI); + when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(srcDetails); + when(storagePoolDetailsDao.listDetailsKeyPairs(2L)).thenReturn(destDetails); - driver.copyAsync(srcVolume, destVolume, copyCallback); + try (MockedStatic utilityMock = mockStatic(OntapStorageUtils.class, CALLS_REAL_METHODS)) { + utilityMock.when(() -> OntapStorageUtils.getStrategyByStoragePoolDetails(destDetails)) + .thenThrow(new RuntimeException()); - verify(copyCallback).complete(argThat(result -> result != null - && result.isFailed() - && result.getResult().contains(RuntimeException.class.getName()))); + driver.copyAsync(srcVolume, destVolume, copyCallback); + + verify(copyCallback).complete(argThat(result -> result != null + && result.isFailed() + && result.getResult().contains(RuntimeException.class.getName()))); + } } @Test @@ -808,7 +834,7 @@ void testGrantAccess_UpdatesPathWhenOntapAssignsDifferentLunId() { .thenReturn("igroup1"); when(sanStrategy.getAccessGroup(any())).thenReturn(existingAccessGroup); - when(sanStrategy.ensureLunMapped(anyString(), anyString(), anyString())).thenReturn("1"); + doNothing().when(sanStrategy).ensureLunMapped(anyString(), anyString(), anyString()); when(sanStrategy.getLunSerialNumber(anyString(), anyString())).thenReturn(LUN_SERIAL_NUMBER); boolean result = driver.grantAccess(volumeInfo, host, dataStore); @@ -905,7 +931,7 @@ void testGrantAccess_IscsiMigrating_ConnectsHostToPool() throws Exception { .thenReturn("igroup1"); when(sanStrategy.getAccessGroup(any())).thenReturn(existingAccessGroup); - when(sanStrategy.ensureLunMapped(anyString(), anyString(), anyString())).thenReturn("0"); + doNothing().when(sanStrategy).ensureLunMapped(anyString(), anyString(), anyString()); when(sanStrategy.getLunSerialNumber(anyString(), anyString())).thenReturn(LUN_SERIAL_NUMBER); assertTrue(driver.grantAccess(volumeInfo, hostVO, dataStore)); @@ -948,7 +974,7 @@ void testGrantAccess_IscsiRemap_UpdatesCallerVolumePath() throws Exception { .thenReturn("igroup1"); when(sanStrategy.getAccessGroup(any())).thenReturn(existingAccessGroup); - when(sanStrategy.ensureLunMapped(anyString(), anyString(), anyString())).thenReturn("2"); + doNothing().when(sanStrategy).ensureLunMapped(anyString(), anyString(), anyString()); when(sanStrategy.getLunSerialNumber(anyString(), anyString())).thenReturn(LUN_SERIAL_NUMBER); assertTrue(driver.grantAccess(volumeInfo, hostVO, dataStore)); @@ -993,7 +1019,6 @@ void testGrantAccess_NFSAttachingUnattached_DoesNotUpdateExportPolicy() throws E when(volumeDao.findById(100L)).thenReturn(volumeVO); when(volumeVO.getUuid()).thenReturn("vol-uuid"); when(volumeVO.getState()).thenReturn(Volume.State.Attaching); - when(volumeVO.getInstanceId()).thenReturn(null); try (MockedStatic utilityMock = mockStatic(OntapStorageUtils.class, CALLS_REAL_METHODS)) { utilityMock.when(() -> OntapStorageUtils.getStrategyByStoragePoolDetails(storagePoolDetails)) @@ -1101,7 +1126,7 @@ private void verifyIscsiGrantConnectsHost(boolean tagged) throws Exception { .thenReturn("igroup1"); when(sanStrategy.getAccessGroup(any())).thenReturn(existingAccessGroup); - when(sanStrategy.ensureLunMapped(anyString(), anyString(), anyString())).thenReturn("0"); + doNothing().when(sanStrategy).ensureLunMapped(anyString(), anyString(), anyString()); when(sanStrategy.getLunSerialNumber(anyString(), anyString())).thenReturn(LUN_SERIAL_NUMBER); assertTrue(driver.grantAccess(volumeInfo, hostVO, dataStore)); diff --git a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java index 7e9e6e76d540..0d957acebc08 100644 --- a/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java +++ b/plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java @@ -729,7 +729,7 @@ void testEnableLogicalAccess_Success() { unifiedSANStrategy.enableLogicalAccess(values); // Verify: map is created and no follow-up lookup is made - verify(sanFeignClient).createLunMap(eq(authHeader), eq(true), any(LunMap.class)); + verify(sanFeignClient).createLunMap(eq(authHeader), eq(false), any(LunMap.class)); verify(sanFeignClient, never()).getLunMapResponse(any(), anyMap()); } } @@ -886,7 +886,7 @@ void testEnsureLunMapped_CreatesNewMapping_SingleLookup() { // Verify: one existence lookup and one create, no follow-up lookup verify(sanFeignClient, times(1)).getLunMapResponse(eq(authHeader), anyMap()); - verify(sanFeignClient).createLunMap(eq(authHeader), eq(true), any(LunMap.class)); + verify(sanFeignClient).createLunMap(eq(authHeader), eq(false), any(LunMap.class)); } } @@ -2144,7 +2144,7 @@ void testEnableLogicalAccess_CreateLunMapFails_ThrowsException() { utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password")) .thenReturn(authHeader); - when(sanFeignClient.createLunMap(eq(authHeader), eq(true), any(LunMap.class))) + when(sanFeignClient.createLunMap(eq(authHeader), eq(false), any(LunMap.class))) .thenThrow(new RuntimeException("Failed to create LunMap")); assertThrows(CloudRuntimeException.class, @@ -2225,13 +2225,13 @@ void testEnsureLunMapped_CreateNewMapping_Success() { // Single lookup returns empty (no existing mapping), then the map is created when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(emptyResponse); - when(sanFeignClient.createLunMap(eq(authHeader), eq(true), any(LunMap.class))) + when(sanFeignClient.createLunMap(eq(authHeader), eq(false), any(LunMap.class))) .thenReturn(new OntapResponse<>()); unifiedSANStrategy.ensureLunMapped(svmName, lunName, accessGroupName); verify(sanFeignClient, times(1)).getLunMapResponse(eq(authHeader), anyMap()); - verify(sanFeignClient).createLunMap(eq(authHeader), eq(true), any(LunMap.class)); + verify(sanFeignClient).createLunMap(eq(authHeader), eq(false), any(LunMap.class)); } } @@ -2249,7 +2249,7 @@ void testEnsureLunMapped_FailedToMap_ThrowsException() { .thenReturn(authHeader); when(sanFeignClient.getLunMapResponse(eq(authHeader), anyMap())).thenReturn(emptyResponse); - when(sanFeignClient.createLunMap(eq(authHeader), eq(true), any(LunMap.class))) + when(sanFeignClient.createLunMap(eq(authHeader), eq(false), any(LunMap.class))) .thenThrow(new RuntimeException("ONTAP rejected lun-map create")); assertThrows(CloudRuntimeException.class,