Skip to content

Commit d38c1f8

Browse files
authored
Fix error message while creating local storage pool (#12767)
* Fix error message while creating local storage pool
1 parent 2416db2 commit d38c1f8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19+
import static com.cloud.configuration.ConfigurationManagerImpl.SystemVMUseLocalStorage;
1920
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
2021

2122
import java.io.UnsupportedEncodingException;
@@ -144,6 +145,7 @@
144145
import org.apache.commons.collections.CollectionUtils;
145146
import org.apache.commons.collections.MapUtils;
146147
import org.apache.commons.lang.time.DateUtils;
148+
import org.apache.commons.lang3.BooleanUtils;
147149
import org.apache.commons.lang3.EnumUtils;
148150
import org.springframework.stereotype.Component;
149151

@@ -176,7 +178,6 @@
176178
import com.cloud.cluster.ClusterManagerListener;
177179
import com.cloud.configuration.Config;
178180
import com.cloud.configuration.ConfigurationManager;
179-
import com.cloud.configuration.ConfigurationManagerImpl;
180181
import com.cloud.configuration.Resource.ResourceType;
181182
import com.cloud.cpu.CPU;
182183
import com.cloud.dc.ClusterVO;
@@ -803,19 +804,18 @@ protected DataStore createLocalStorage(Map<String, Object> poolInfos) throws Con
803804
return createLocalStorage(host, pInfo);
804805
}
805806

807+
private boolean isLocalStorageEnabledForZone(DataCenterVO zone) {
808+
return zone.isLocalStorageEnabled() || BooleanUtils.toBoolean(SystemVMUseLocalStorage.valueIn(zone.getId()));
809+
}
810+
806811
@DB
807812
@Override
808813
public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws ConnectionException {
809814
DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
810815
if (dc == null) {
811816
return null;
812817
}
813-
boolean useLocalStorageForSystemVM = false;
814-
Boolean isLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dc.getId());
815-
if (isLocal != null) {
816-
useLocalStorageForSystemVM = isLocal.booleanValue();
817-
}
818-
if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
818+
if (!isLocalStorageEnabledForZone(dc)) {
819819
return null;
820820
}
821821
DataStore store = null;
@@ -1017,6 +1017,10 @@ public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws Resource
10171017
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
10181018
throw new PermissionDeniedException(String.format("Cannot perform this operation, Zone is currently disabled: %s", zone));
10191019
}
1020+
// Check if it's local storage and if it's enabled on the zone
1021+
if (isFileScheme && !isLocalStorageEnabledForZone(zone)) {
1022+
throw new InvalidParameterValueException("Local storage is not enabled for zone: " + zone);
1023+
}
10201024

10211025
managementService.checkJsInterpretationAllowedIfNeededForParameterValue(ApiConstants.IS_TAG_A_RULE,
10221026
Boolean.TRUE.equals(cmd.isTagARule()));

0 commit comments

Comments
 (0)