Skip to content

Commit a58dcd0

Browse files
CSTACKEX-198: revert workflows should also have lun path in ONTAP pattern
1 parent baf883a commit a58dcd0

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ public JobResponse revertSnapshotForCloudStackVolume(String snapshotName, String
565565
logger.trace("revertSnapshotForCloudStackVolume [iSCSI]: Reverting LUN [{}] from clone [{}] on FlexVol [{}]",
566566
volumePath, snapshotName, flexVolName);
567567

568+
if (snapshotName == null || snapshotName.isEmpty()) {
569+
throw new CloudRuntimeException("Source clone LUN name is required for iSCSI snapshot revert");
570+
}
568571
if (volumePath == null || volumePath.isEmpty()) {
569572
throw new CloudRuntimeException("Destination LUN name is required for iSCSI snapshot revert");
570573
}
@@ -574,10 +577,25 @@ public JobResponse revertSnapshotForCloudStackVolume(String snapshotName, String
574577
if (lunUuid == null || lunUuid.isEmpty()) {
575578
throw new CloudRuntimeException("Source clone LUN UUID is required for iSCSI snapshot revert");
576579
}
580+
if (storage.getSvmName() == null || storage.getSvmName().isEmpty()) {
581+
throw new CloudRuntimeException("SVM name is required for iSCSI snapshot revert");
582+
}
583+
584+
String sourceLunPath = snapshotName.startsWith(OntapStorageConstants.VOLUME_PATH_PREFIX)
585+
? snapshotName : OntapStorageUtils.getLunName(flexVolName, snapshotName);
586+
String destinationLunPath = volumePath.startsWith(OntapStorageConstants.VOLUME_PATH_PREFIX)
587+
? volumePath : OntapStorageUtils.getLunName(flexVolName, volumePath);
588+
589+
if (!sourceLunPath.startsWith(OntapStorageConstants.VOLUME_PATH_PREFIX)) {
590+
throw new CloudRuntimeException("Invalid source LUN path for iSCSI snapshot revert: " + sourceLunPath);
591+
}
592+
if (!destinationLunPath.startsWith(OntapStorageConstants.VOLUME_PATH_PREFIX)) {
593+
throw new CloudRuntimeException("Invalid destination LUN path for iSCSI snapshot revert: " + destinationLunPath);
594+
}
577595

578596
String authHeader = getAuthHeader();
579597
Lun revertCloneRequest = new Lun();
580-
revertCloneRequest.setName(volumePath);
598+
revertCloneRequest.setName(destinationLunPath);
581599
Svm svm = new Svm();
582600
svm.setName(storage.getSvmName());
583601
revertCloneRequest.setSvm(svm);
@@ -588,13 +606,14 @@ public JobResponse revertSnapshotForCloudStackVolume(String snapshotName, String
588606
revertCloneRequest.setLocation(location);
589607
Lun.Clone clone = new Lun.Clone();
590608
Lun.Source source = new Lun.Source();
609+
source.setName(sourceLunPath);
591610
source.setUuid(lunUuid);
592611
clone.setSource(source);
593612
revertCloneRequest.setClone(clone);
594613
revertCloneRequest.setIsOverride(Boolean.TRUE);
595614

596-
logger.debug("revertSnapshotForCloudStackVolume [iSCSI]: lun clone sourceUuid={} destinationLun={} isOverride=true",
597-
lunUuid, volumePath);
615+
logger.debug("revertSnapshotForCloudStackVolume [iSCSI]: lun clone sourcePath={} sourceUuid={} destinationLun={} isOverride=true",
616+
sourceLunPath, lunUuid, destinationLunPath);
598617
return sanFeignClient.cloneLun(authHeader, revertCloneRequest);
599618
}
600619
}

plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedSANStrategyTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,10 @@ void testRevertSnapshotForCloudStackVolume_UsesLunCloneWithOverride() {
18161816
try (MockedStatic<OntapStorageUtils> utilityMock = mockStatic(OntapStorageUtils.class)) {
18171817
utilityMock.when(() -> OntapStorageUtils.generateAuthHeader("admin", "password"))
18181818
.thenReturn(authHeader);
1819+
utilityMock.when(() -> OntapStorageUtils.getLunName("flexvol1", "clone-snap-1"))
1820+
.thenReturn("/vol/flexvol1/clone-snap-1");
1821+
utilityMock.when(() -> OntapStorageUtils.getLunName("flexvol1", "dest-lun-1"))
1822+
.thenReturn("/vol/flexvol1/dest-lun-1");
18191823

18201824
JobResponse result = unifiedSANStrategy.revertSnapshotForCloudStackVolume(
18211825
"clone-snap-1", "flexvol-uuid-1", "clone-lun-uuid-1", "dest-lun-1", "clone-lun-uuid-1", "flexvol1");
@@ -1824,9 +1828,10 @@ void testRevertSnapshotForCloudStackVolume_UsesLunCloneWithOverride() {
18241828
verify(sanFeignClient).cloneLun(eq(authHeader), argThat(lun ->
18251829
lun != null
18261830
&& Boolean.TRUE.equals(lun.getIsOverride())
1827-
&& "dest-lun-1".equals(lun.getName())
1831+
&& "/vol/flexvol1/dest-lun-1".equals(lun.getName())
18281832
&& lun.getClone() != null
18291833
&& lun.getClone().getSource() != null
1834+
&& "/vol/flexvol1/clone-snap-1".equals(lun.getClone().getSource().getName())
18301835
&& "clone-lun-uuid-1".equals(lun.getClone().getSource().getUuid())
18311836
&& lun.getLocation() != null
18321837
&& lun.getLocation().getVolume() != null

0 commit comments

Comments
 (0)