Skip to content

Commit 38006b2

Browse files
authored
ssvm: use mgmt network if no storage network (#10735)
* ssvm: use mgmt network if no storage network Fixes #10163 Based on #10163 (comment) Signed-off-by: Abhishek Kumar <[email protected]> * update Signed-off-by: Abhishek Kumar <[email protected]> * fix Signed-off-by: Abhishek Kumar <[email protected]> --------- Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 7c727a3 commit 38006b2

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@
8484
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
8585
import org.apache.cloudstack.utils.security.DigestHelper;
8686
import org.apache.commons.codec.digest.DigestUtils;
87+
import org.apache.commons.collections.MapUtils;
8788
import org.apache.commons.io.FileUtils;
8889
import org.apache.commons.io.FilenameUtils;
8990
import org.apache.commons.lang3.BooleanUtils;
91+
import org.apache.commons.lang3.ObjectUtils;
9092
import org.apache.http.HttpEntity;
9193
import org.apache.http.HttpResponse;
9294
import org.apache.http.NameValuePair;
@@ -2717,6 +2719,20 @@ public PingCommand getCurrentStatus(final long id) {
27172719
return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
27182720
}
27192721

2722+
protected void configureStorageNetwork(Map<String, Object> params) {
2723+
_storageIp = MapUtils.getString(params, "storageip");
2724+
_storageNetmask = (String) params.get("storagenetmask");
2725+
_storageGateway = (String) params.get("storagegateway");
2726+
if (_storageIp == null && _inSystemVM && _eth1ip != null) {
2727+
String eth1Gateway = ObjectUtils.firstNonNull(_localgw, MapUtils.getString(params, "localgw"));
2728+
logger.info("Storage network not configured, using management network[ip: {}, netmask: {}, gateway: {}] for storage traffic",
2729+
_eth1ip, _eth1mask, eth1Gateway);
2730+
_storageIp = _eth1ip;
2731+
_storageNetmask = _eth1mask;
2732+
_storageGateway = eth1Gateway;
2733+
}
2734+
}
2735+
27202736
@Override
27212737
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
27222738
_eth1ip = (String)params.get("eth1ip");
@@ -2739,12 +2755,10 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
27392755
_inSystemVM = true;
27402756
}
27412757

2742-
_storageIp = (String)params.get("storageip");
2758+
configureStorageNetwork(params);
27432759
if (_storageIp == null && _inSystemVM) {
2744-
logger.warn("There is no storageip in /proc/cmdline, something wrong!");
2760+
logger.warn("No storageip in /proc/cmdline, something wrong! Even fallback to management network did not resolve storage IP.");
27452761
}
2746-
_storageNetmask = (String)params.get("storagenetmask");
2747-
_storageGateway = (String)params.get("storagegateway");
27482762
super.configure(name, params);
27492763

27502764
_params = params;

services/secondary-storage/server/src/test/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,39 @@
1818
*/
1919
package org.apache.cloudstack.storage.resource;
2020

21-
import org.apache.logging.log4j.Logger;
2221
import static org.mockito.ArgumentMatchers.any;
23-
import org.mockito.Mock;
2422
import static org.mockito.Mockito.doThrow;
2523
import static org.mockito.Mockito.spy;
24+
import static org.mockito.Mockito.times;
2625

2726
import java.io.File;
2827
import java.nio.file.Files;
2928
import java.nio.file.Path;
29+
import java.util.HashMap;
3030
import java.util.List;
31+
import java.util.Map;
3132
import java.util.stream.Stream;
3233

33-
import com.cloud.exception.InvalidParameterValueException;
34-
import com.cloud.utils.EncryptionUtil;
35-
import com.cloud.utils.net.NetUtils;
3634
import org.apache.cloudstack.storage.command.DeleteCommand;
3735
import org.apache.cloudstack.storage.command.QuerySnapshotZoneCopyAnswer;
3836
import org.apache.cloudstack.storage.command.QuerySnapshotZoneCopyCommand;
3937
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
4038
import org.apache.cloudstack.storage.to.TemplateObjectTO;
39+
import org.apache.logging.log4j.Logger;
4140
import org.junit.Assert;
4241
import org.junit.Test;
4342
import org.junit.runner.RunWith;
43+
import org.mockito.Mock;
4444
import org.mockito.MockedStatic;
4545
import org.mockito.Mockito;
46-
import static org.mockito.Mockito.times;
4746
import org.mockito.Spy;
4847
import org.mockito.junit.MockitoJUnitRunner;
48+
import org.springframework.test.util.ReflectionTestUtils;
4949

5050
import com.cloud.agent.api.to.DataStoreTO;
51+
import com.cloud.exception.InvalidParameterValueException;
52+
import com.cloud.utils.EncryptionUtil;
53+
import com.cloud.utils.net.NetUtils;
5154

5255
@RunWith(MockitoJUnitRunner.class)
5356
public class NfsSecondaryStorageResourceTest {
@@ -242,4 +245,45 @@ public void getUploadProtocolTestReturnHttpWhenUseHttpsToUploadIsFalse() {
242245

243246
Assert.assertEquals(NetUtils.HTTP_PROTO, result);
244247
}
248+
249+
@Test
250+
public void configureStorageNetworkSetsStorageNetworkWhenParamsContainValues() {
251+
Map<String, Object> params = new HashMap<>();
252+
String ip = "192.168.1.10";
253+
String netmask = "255.255.255.0";
254+
String gateway = "192.168.1.1";
255+
params.put("storageip", ip);
256+
params.put("storagenetmask", netmask);
257+
params.put("storagegateway", gateway);
258+
resource.configureStorageNetwork(params);
259+
Assert.assertEquals(ip, ReflectionTestUtils.getField(resource, "_storageIp"));
260+
Assert.assertEquals(netmask, ReflectionTestUtils.getField(resource, "_storageNetmask"));
261+
Assert.assertEquals(gateway, ReflectionTestUtils.getField(resource, "_storageGateway"));
262+
}
263+
264+
@Test
265+
public void configureStorageNetworkUsesManagementNetworkWhenStorageIpIsNullAndInSystemVM() {
266+
Map<String, Object> params = new HashMap<>();
267+
resource._inSystemVM = true;
268+
String ip = "10.0.0.10";
269+
String netmask = "255.255.255.0";
270+
String gateway = "10.0.0.1";
271+
ReflectionTestUtils.setField(resource, "_eth1ip", ip);
272+
ReflectionTestUtils.setField(resource, "_eth1mask", netmask);
273+
ReflectionTestUtils.setField(resource, "_localgw", gateway);
274+
resource.configureStorageNetwork(params);
275+
Assert.assertEquals(ip, ReflectionTestUtils.getField(resource, "_storageIp"));
276+
Assert.assertEquals(netmask, ReflectionTestUtils.getField(resource, "_storageNetmask"));
277+
Assert.assertEquals(gateway, ReflectionTestUtils.getField(resource, "_storageGateway"));
278+
}
279+
280+
@Test
281+
public void configureStorageNetworkDoesNotSetStorageNetworkWhenNotInSystemVMAndStorageIpIsNull() {
282+
Map<String, Object> params = new HashMap<>();
283+
resource._inSystemVM = false;
284+
resource.configureStorageNetwork(params);
285+
Assert.assertNull(ReflectionTestUtils.getField(resource, "_storageIp"));
286+
Assert.assertNull(ReflectionTestUtils.getField(resource, "_storageNetmask"));
287+
Assert.assertNull(ReflectionTestUtils.getField(resource, "_storageGateway"));
288+
}
245289
}

0 commit comments

Comments
 (0)