Skip to content

Commit 839e73e

Browse files
committed
update
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent f629b62 commit 839e73e

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,19 @@ public PingCommand getCurrentStatus(final long id) {
27182718
return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
27192719
}
27202720

2721+
protected void configureStorageNetwork(Map<String, Object> params) {
2722+
_storageIp = MapUtils.getString(params, "storageip");
2723+
_storageNetmask = (String) params.get("storagenetmask");
2724+
_storageGateway = (String) params.get("storagegateway");
2725+
if (_storageIp == null && _inSystemVM && _eth1ip != null) {
2726+
logger.info("Storage network not configured, using management network[ip: {}, netmask: {}, gateway: {}] for storage traffic",
2727+
_eth1ip, _eth1mask, _localgw);
2728+
_storageIp = _eth1ip;
2729+
_storageNetmask = _eth1mask;
2730+
_storageGateway = _localgw;
2731+
}
2732+
}
2733+
27212734
@Override
27222735
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
27232736
_eth1ip = (String)params.get("eth1ip");
@@ -2740,12 +2753,10 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
27402753
_inSystemVM = true;
27412754
}
27422755

2743-
_storageIp = MapUtils.getString(params, "storageip", _eth1ip);
2756+
configureStorageNetwork(params);
27442757
if (_storageIp == null && _inSystemVM) {
2745-
logger.warn("There is no storageip in /proc/cmdline, something wrong!");
2758+
logger.warn("No storageip in /proc/cmdline, something wrong! Even fallback to management network did not resolve storage IP.");
27462759
}
2747-
_storageNetmask = (String)params.get("storagenetmask");
2748-
_storageGateway = (String)params.get("storagegateway");
27492760
super.configure(name, params);
27502761

27512762
_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)