Skip to content
Open
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 @@ -389,7 +389,11 @@ public void deleteStorageVolume(Volume volume) {
throw new CloudRuntimeException("Volume deletion job failed for volume: " + volume.getName());
}
logger.info("Volume deleted successfully: " + volume.getName());
} catch (FeignException.FeignClientException e) {
} catch (FeignException e) {
Comment thread
sandeeplocharla marked this conversation as resolved.
if (e.status() == 404) {
logger.warn("deleteStorageVolume: Volume '{}' not found in ONTAP, treating as no-op", volume.getName());
Comment thread
sandeeplocharla marked this conversation as resolved.
return;
}
Comment thread
sandeeplocharla marked this conversation as resolved.
logger.error("Exception while deleting volume: ", e);
throw new CloudRuntimeException("Failed to delete volume: " + e.getMessage());
Comment thread
sandeeplocharla marked this conversation as resolved.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,15 @@ public void deleteAccessGroup(AccessGroup accessGroup) {
String exportPolicyId = details.get(OntapStorageConstants.EXPORT_POLICY_ID);

try {
nasFeignClient.deleteExportPolicyById(authHeader,exportPolicyId);
nasFeignClient.deleteExportPolicyById(authHeader, exportPolicyId);
logger.info("deleteAccessGroup: Successfully deleted export policy '{}'", exportPolicyName);
} catch (Exception e) {
} catch (FeignException e) {
if (e.status() == 404) {
logger.warn("deleteAccessGroup: Export policy '{}' not found in ONTAP, treating as no-op", exportPolicyName);
return;
}
Comment thread
sandeeplocharla marked this conversation as resolved.
logger.error("deleteAccessGroup: Failed to delete export policy. Exception: {}", e.getMessage(), e);
throw new CloudRuntimeException("Failed to delete export policy: " + e.getMessage(), e);

}
} catch (Exception e) {
logger.error("deleteAccessGroup: Failed to delete export policy. Exception: {}", e.getMessage(), e);
Comment thread
sandeeplocharla marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,25 @@ public void testDeleteStorageVolume_feignException() {
assertTrue(ex.getMessage().contains("Failed to delete volume"));
}

@Test
public void testDeleteStorageVolume_notFound_404_returnsWithoutThrowing() {
// Setup
Volume volume = new Volume();
volume.setName("test-volume");
volume.setUuid("vol-uuid-1");

FeignException feignEx = mock(FeignException.class);
when(feignEx.status()).thenReturn(404);
when(volumeFeignClient.deleteVolume(anyString(), eq("vol-uuid-1")))
.thenThrow(feignEx);

// Execute - 404 means volume already gone on ONTAP, treated as no-op
storageStrategy.deleteStorageVolume(volume);

// Verify the delete was attempted
verify(volumeFeignClient).deleteVolume(anyString(), eq("vol-uuid-1"));
}

// ========== getStoragePath() Tests ==========

@Test
Expand Down Expand Up @@ -950,4 +969,17 @@ void testDeleteFlexVolSnapshotForCloudStackVolume_AlreadyAbsentOnOntap() {

verify(snapshotFeignClient).deleteSnapshot(anyString(), eq("fv-uuid-1"), eq("snap-uuid-1"));
}

@Test
void testDeleteFlexVolSnapshotForCloudStackVolume_Feign404_TreatedAsSuccess() {
FeignException notFoundException = mock(FeignException.class);
when(notFoundException.status()).thenReturn(404);
when(snapshotFeignClient.deleteSnapshot(anyString(), eq("fv-uuid-1"), eq("snap-uuid-1")))
.thenThrow(notFoundException);

storageStrategy.deleteFlexVolSnapshotForCloudStackVolume("fv-uuid-1", "snap-uuid-1", "snap-name-1");

verify(snapshotFeignClient).deleteSnapshot(anyString(), eq("fv-uuid-1"), eq("snap-uuid-1"));
verify(jobFeignClient, never()).getJobByUUID(anyString(), anyString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import feign.FeignException;

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class UnifiedNASStrategyTest {
Expand Down Expand Up @@ -516,6 +518,26 @@ public void testDeleteAccessGroup_Failed() {
});
}

// Test deleteAccessGroup - Export policy not found should be treated as no-op
@Test
public void testDeleteAccessGroup_NotFound404_NoThrow() {
AccessGroup accessGroup = mock(AccessGroup.class);
Map<String, String> details = new HashMap<>();
details.put(OntapStorageConstants.EXPORT_POLICY_NAME, "export-policy-1");
details.put(OntapStorageConstants.EXPORT_POLICY_ID, "1");

when(accessGroup.getStoragePoolId()).thenReturn(1L);
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(details);

FeignException feignException = mock(FeignException.class);
when(feignException.status()).thenReturn(404);
doThrow(feignException).when(nasFeignClient).deleteExportPolicyById(anyString(), eq("1"));

strategy.deleteAccessGroup(accessGroup);

verify(nasFeignClient).deleteExportPolicyById(anyString(), eq("1"));
}

// Test deleteCloudStackVolume - Success
@Test
public void testDeleteCloudStackVolume_Success() throws Exception {
Expand Down
Loading