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 @@ -23,8 +23,10 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -36,13 +38,10 @@ public class Svm {
@JsonProperty("name")
private String name = null;

@JsonProperty("iscsi.enabled")
private Boolean iscsiEnabled = null;

@JsonProperty("fcp.enabled")
private Boolean fcpEnabled = null;

@JsonProperty("nfs.enabled")
private Boolean nfsEnabled = null;

@JsonProperty("aggregates")
Expand Down Expand Up @@ -73,28 +72,43 @@ public void setName(String name) {
this.name = name;
}

public Boolean getNfsEnabled() {
return Boolean.TRUE.equals(nfsEnabled);
}

public void setNfsEnabled(Boolean nfsEnabled) {
this.nfsEnabled = nfsEnabled;
}

@JsonSetter("nfs")
public void setNfs(Map<String, Object> nfs) {
this.nfsEnabled = nfs != null ? Boolean.TRUE.equals(nfs.get("enabled")) : false;
}

public Boolean getIscsiEnabled() {
return iscsiEnabled;
return Boolean.TRUE.equals(iscsiEnabled);
}

public void setIscsiEnabled(Boolean iscsiEnabled) {
this.iscsiEnabled = iscsiEnabled;
}

@JsonSetter("iscsi")
public void setIscsi(Map<String, Object> iscsi) {
this.iscsiEnabled = iscsi != null ? Boolean.TRUE.equals(iscsi.get("enabled")) : false;
}

public Boolean getFcpEnabled() {
return fcpEnabled;
return Boolean.TRUE.equals(fcpEnabled);
}

public void setFcpEnabled(Boolean fcpEnabled) {
this.fcpEnabled = fcpEnabled;
}

public Boolean getNfsEnabled() {
return nfsEnabled;
}

public void setNfsEnabled(Boolean nfsEnabled) {
this.nfsEnabled = nfsEnabled;
@JsonSetter("fcp")
public void setFcp(Map<String, Object> fcp) {
this.fcpEnabled = fcp != null ? Boolean.TRUE.equals(fcp.get("enabled")) : false;
}

public List<Aggregate> getAggregates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,32 @@ public boolean connect() {
Svm svm = new Svm();
logger.info("Fetching the SVM details...");
Map<String, Object> queryParams = Map.of(OntapStorageConstants.NAME, svmName, OntapStorageConstants.FIELDS, OntapStorageConstants.AGGREGATES +
OntapStorageConstants.COMMA + OntapStorageConstants.STATE);
OntapStorageConstants.COMMA + OntapStorageConstants.STATE +
OntapStorageConstants.COMMA + OntapStorageConstants.NFS_ENABLED + OntapStorageConstants.COMMA + OntapStorageConstants.ISCSI_ENABLED);
OntapResponse<Svm> svms = svmFeignClient.getSvmResponse(queryParams, authHeader);
if (svms != null && svms.getRecords() != null && !svms.getRecords().isEmpty()) {
svm = svms.getRecords().get(0);
} else {
logger.error("No SVM found on the ONTAP cluster by the name" + svmName + ".");
return false;
logger.error("No SVM found on the ONTAP cluster by the name " + svmName + ".");
throw new CloudRuntimeException("No SVM found on the ONTAP cluster by the name " + svmName + ".");
}

logger.info("Validating SVM state and protocol settings...");
if (!Objects.equals(svm.getState(), OntapStorageConstants.RUNNING)) {
logger.error("SVM " + svmName + " is not in running state.");
return false;
throw new CloudRuntimeException("SVM " + svmName + " is not in running state.");
}
if (Objects.equals(storage.getProtocol(), OntapStorageConstants.NFS) && !svm.getNfsEnabled()) {
if (Objects.equals(storage.getProtocol(), ProtocolType.NFS3) && !svm.getNfsEnabled()) {
logger.error("NFS protocol is not enabled on SVM " + svmName);
return false;
} else if (Objects.equals(storage.getProtocol(), OntapStorageConstants.ISCSI) && !svm.getIscsiEnabled()) {
logger.error("iSCSI protocol is not enabled on SVM " + svmName);
return false;
throw new CloudRuntimeException("NFS protocol is not enabled on SVM " + svmName);
} else if (Objects.equals(storage.getProtocol(), ProtocolType.ISCSI) && !svm.getIscsiEnabled()) {
logger.error("ISCSI protocol is not enabled on SVM " + svmName);
throw new CloudRuntimeException("ISCSI protocol is not enabled on SVM " + svmName);
}
List<Aggregate> aggrs = svm.getAggregates();
if (aggrs == null || aggrs.isEmpty()) {
logger.error("No aggregates are assigned to SVM " + svmName);
return false;
throw new CloudRuntimeException("No aggregates are assigned to SVM " + svmName);
}
for (Aggregate aggr : aggrs) {
logger.debug("Found aggregate: " + aggr.getName() + " with UUID: " + aggr.getUuid());
Expand All @@ -155,13 +156,13 @@ public boolean connect() {
}
if (this.aggregates == null || this.aggregates.isEmpty()) {
logger.error("No suitable aggregates found on SVM " + svmName + " for volume creation.");
return false;
throw new CloudRuntimeException("No suitable aggregates found on SVM " + svmName + " for volume creation.");
}

logger.info("Successfully connected to ONTAP cluster and validated ONTAP details provided");
} catch (Exception e) {
logger.error("Failed to connect to ONTAP cluster: " + e.getMessage(), e);
return false;
throw new CloudRuntimeException("Failed to connect to ONTAP cluster: " + e.getMessage(), e);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class OntapStorageConstants {

public static final String NFS = "nfs";
public static final String ISCSI = "iscsi";

public static final String NFS_ENABLED = "nfs.enabled";
public static final String ISCSI_ENABLED = "iscsi.enabled";
public static final String SIZE = "size";
public static final String PROTOCOL = "protocol";
public static final String SVM_NAME = "svmName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -239,11 +238,9 @@ public void testConnect_svmNotFound() {

when(svmFeignClient.getSvmResponse(anyMap(), anyString())).thenReturn(svmResponse);

// Execute
boolean result = storageStrategy.connect();

// Verify
assertFalse(result, "connect() should return false when SVM is not found");
// Execute & Verify
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class, () -> storageStrategy.connect());
assertTrue(ex.getMessage().contains("No SVM found"));
}

@Test
Expand All @@ -259,11 +256,9 @@ public void testConnect_svmNotRunning() {

when(svmFeignClient.getSvmResponse(anyMap(), anyString())).thenReturn(svmResponse);

// Execute
boolean result = storageStrategy.connect();

// Verify
assertFalse(result, "connect() should return false when SVM is not running");
// Execute & Verify
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class, () -> storageStrategy.connect());
assertTrue(ex.getMessage().contains("not in running state"));
}

@Test
Expand All @@ -285,8 +280,8 @@ public void testConnect_nfsNotEnabled() {
when(svmFeignClient.getSvmResponse(anyMap(), anyString())).thenReturn(svmResponse);

// Execute & Verify
boolean result = storageStrategy.connect();
assertFalse(result, "connect() should fail when NFS is disabled");
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class, () -> storageStrategy.connect());
assertTrue(ex.getMessage().contains("NFS protocol is not enabled"));
}

@Test
Expand Down Expand Up @@ -314,8 +309,8 @@ public void testConnect_iscsiNotEnabled() {
when(svmFeignClient.getSvmResponse(anyMap(), anyString())).thenReturn(svmResponse);

// Execute & Verify
boolean result = storageStrategy.connect();
assertFalse(result, "connect() should fail when iSCSI is disabled");
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class, () -> storageStrategy.connect());
assertTrue(ex.getMessage().contains("ISCSI protocol is not enabled"));
}

@Test
Expand All @@ -332,23 +327,19 @@ public void testConnect_noAggregates() {

when(svmFeignClient.getSvmResponse(anyMap(), anyString())).thenReturn(svmResponse);

// Execute
boolean result = storageStrategy.connect();

// Verify
assertFalse(result, "connect() should return false when no aggregates are assigned");
// Execute & Verify
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class, () -> storageStrategy.connect());
assertTrue(ex.getMessage().contains("No aggregates"));
}

@Test
public void testConnect_nullSvmResponse() {
// Setup
when(svmFeignClient.getSvmResponse(anyMap(), anyString())).thenReturn(null);

// Execute
boolean result = storageStrategy.connect();

// Verify
assertFalse(result, "connect() should return false when SVM response is null");
// Execute & Verify
CloudRuntimeException ex = assertThrows(CloudRuntimeException.class, () -> storageStrategy.connect());
assertTrue(ex.getMessage().contains("No SVM found"));
}

// ========== createStorageVolume() Tests ==========
Expand Down
Loading