Skip to content

Commit f3a5e12

Browse files
committed
CLOUDSTACK-9438: Fix for global default
1 parent 1cea32e commit f3a5e12

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,6 @@ public String updateConfiguration(final long userId, final String name, final St
535535
throw new InvalidParameterValueException("unable to find image store by id " + resourceId);
536536
}
537537
ImageStoreDetailVO imgStoreDetail = _imageStoreDetailsDao.findDetail(imgStore.getId(), name);
538-
if (imgStoreDetail == null){
539-
throw new InvalidParameterValueException("unable to find image store details by id " + resourceId + " and name " + name);
540-
}
541538
_imageStoreDetailsDao.addDetail(resourceId, name, value, true);
542539
break;
543540

server/src/com/cloud/storage/ImageStoreDetailsUtil.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import javax.inject.Inject;
2222

23+
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
24+
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
2325
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
2426
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
2527
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
@@ -32,23 +34,40 @@ public class ImageStoreDetailsUtil {
3234
protected ImageStoreDao imageStoreDao;
3335
@Inject
3436
protected ImageStoreDetailsDao imageStoreDetailsDao;
37+
@Inject
38+
protected ConfigurationDao configurationDao;
3539

3640
/**
37-
* Obtain NFS protocol version (if provided) for a store id.<br/>
41+
* Retrieve global secondary storage NFS version default value
42+
* @return global default value
43+
*/
44+
protected Integer getGlobalDefaultNfsVersion(){
45+
ConfigurationVO globalNfsVersion = configurationDao.findByName(CapacityManager.ImageStoreNFSVersion.key());
46+
String value = globalNfsVersion.getValue();
47+
return (value != null ? Integer.valueOf(value) : null);
48+
}
49+
/**
50+
* Obtain NFS protocol version (if provided) for a store id, if not use default config value<br/>
3851
* @param storeId image store id
3952
* @return {@code null} if {@code secstorage.nfs.version} is not found for storeId <br/>
4053
* {@code X} if {@code secstorage.nfs.version} is found found for storeId
4154
*/
4255
public Integer getNfsVersion(long storeId) throws NumberFormatException {
43-
String nfsVersion = null;
56+
Integer nfsVersion;
4457
if (imageStoreDetailsDao.getDetails(storeId) != null){
4558
Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
46-
String nfsVersionKey = CapacityManager.ImageStoreNFSVersion.key();
47-
if (storeDetails != null && storeDetails.containsKey(nfsVersionKey)){
48-
nfsVersion = storeDetails.get(nfsVersionKey);
59+
if (storeDetails.containsKey(CapacityManager.ImageStoreNFSVersion.key())){
60+
String val = storeDetails.get(CapacityManager.ImageStoreNFSVersion.key());
61+
nfsVersion = (val != null ? Integer.valueOf(val) : null);
62+
}
63+
else {
64+
nfsVersion = getGlobalDefaultNfsVersion();
4965
}
5066
}
51-
return (nfsVersion != null ? Integer.valueOf(nfsVersion) : null);
67+
else {
68+
nfsVersion = getGlobalDefaultNfsVersion();
69+
}
70+
return nfsVersion;
5271
}
5372

5473
/**
@@ -62,7 +81,7 @@ public Integer getNfsVersionByUuid(String storeUuid){
6281
if (imageStore != null){
6382
return getNfsVersion(imageStore.getId());
6483
}
65-
return null;
84+
return getGlobalDefaultNfsVersion();
6685
}
6786

6887
}

server/test/com/cloud/storage/ImageStoreDetailsUtilTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
package com.cloud.storage;
1818

1919
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNull;
2120
import static org.mockito.Mockito.mock;
2221
import static org.mockito.Mockito.when;
2322

2423
import java.util.HashMap;
2524
import java.util.Map;
2625

26+
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
27+
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
2728
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
2829
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
2930
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
@@ -37,11 +38,13 @@ public class ImageStoreDetailsUtilTest {
3738
private final static long STORE_ID = 1l;
3839
private final static String STORE_UUID = "aaaa-aaaa-aaaa-aaaa";
3940
private final static Integer NFS_VERSION = 3;
41+
private final static Integer NFS_VERSION_DEFAULT = 2;
4042

4143
ImageStoreDetailsUtil imageStoreDetailsUtil = new ImageStoreDetailsUtil();
4244

4345
ImageStoreDao imgStoreDao = mock(ImageStoreDao.class);
4446
ImageStoreDetailsDao imgStoreDetailsDao = mock(ImageStoreDetailsDao.class);
47+
ConfigurationDao configurationDao = mock(ConfigurationDao.class);
4548

4649
@Before
4750
public void setup() throws Exception {
@@ -54,8 +57,14 @@ public void setup() throws Exception {
5457
when(imgStoreVO.getId()).thenReturn(Long.valueOf(STORE_ID));
5558
when(imgStoreDao.findByUuid(STORE_UUID)).thenReturn(imgStoreVO);
5659

60+
ConfigurationVO confVO = mock(ConfigurationVO.class);
61+
String defaultValue = (NFS_VERSION_DEFAULT == null ? null : String.valueOf(NFS_VERSION_DEFAULT));
62+
when(confVO.getValue()).thenReturn(defaultValue);
63+
when(configurationDao.findByName(nfsVersionKey)).thenReturn(confVO);
64+
5765
imageStoreDetailsUtil.imageStoreDao = imgStoreDao;
5866
imageStoreDetailsUtil.imageStoreDetailsDao = imgStoreDetailsDao;
67+
imageStoreDetailsUtil.configurationDao = configurationDao;
5968
}
6069

6170
@Test
@@ -71,7 +80,7 @@ public void testGetNfsVersionNotFound(){
7180
when(imgStoreDetailsDao.getDetails(STORE_ID)).thenReturn(imgStoreDetails);
7281

7382
Integer nfsVersion = imageStoreDetailsUtil.getNfsVersion(STORE_ID);
74-
assertNull(nfsVersion);
83+
assertEquals(NFS_VERSION_DEFAULT, nfsVersion);
7584
}
7685

7786
@Test
@@ -80,7 +89,7 @@ public void testGetNfsVersionNoDetails(){
8089
when(imgStoreDetailsDao.getDetails(STORE_ID)).thenReturn(imgStoreDetails);
8190

8291
Integer nfsVersion = imageStoreDetailsUtil.getNfsVersion(STORE_ID);
83-
assertNull(nfsVersion);
92+
assertEquals(NFS_VERSION_DEFAULT, nfsVersion);
8493
}
8594

8695
@Test
@@ -93,6 +102,13 @@ public void testGetNfsVersionByUuid(){
93102
public void testGetNfsVersionByUuidNoImgStore(){
94103
when(imgStoreDao.findByUuid(STORE_UUID)).thenReturn(null);
95104
Integer nfsVersion = imageStoreDetailsUtil.getNfsVersionByUuid(STORE_UUID);
96-
assertNull(nfsVersion);
105+
assertEquals(NFS_VERSION_DEFAULT, nfsVersion);
97106
}
98-
}
107+
108+
@Test
109+
public void testGetGlobalDefaultNfsVersion(){
110+
Integer globalDefaultNfsVersion = imageStoreDetailsUtil.getGlobalDefaultNfsVersion();
111+
assertEquals(NFS_VERSION_DEFAULT, globalDefaultNfsVersion);
112+
}
113+
114+
}

0 commit comments

Comments
 (0)