|
18 | 18 | */
|
19 | 19 | package org.apache.cloudstack.storage.resource;
|
20 | 20 |
|
21 |
| -import org.apache.logging.log4j.Logger; |
22 | 21 | import static org.mockito.ArgumentMatchers.any;
|
23 |
| -import org.mockito.Mock; |
24 | 22 | import static org.mockito.Mockito.doThrow;
|
25 | 23 | import static org.mockito.Mockito.spy;
|
| 24 | +import static org.mockito.Mockito.times; |
26 | 25 |
|
27 | 26 | import java.io.File;
|
28 | 27 | import java.nio.file.Files;
|
29 | 28 | import java.nio.file.Path;
|
| 29 | +import java.util.HashMap; |
30 | 30 | import java.util.List;
|
| 31 | +import java.util.Map; |
31 | 32 | import java.util.stream.Stream;
|
32 | 33 |
|
33 |
| -import com.cloud.exception.InvalidParameterValueException; |
34 |
| -import com.cloud.utils.EncryptionUtil; |
35 |
| -import com.cloud.utils.net.NetUtils; |
36 | 34 | import org.apache.cloudstack.storage.command.DeleteCommand;
|
37 | 35 | import org.apache.cloudstack.storage.command.QuerySnapshotZoneCopyAnswer;
|
38 | 36 | import org.apache.cloudstack.storage.command.QuerySnapshotZoneCopyCommand;
|
39 | 37 | import org.apache.cloudstack.storage.to.SnapshotObjectTO;
|
40 | 38 | import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
| 39 | +import org.apache.logging.log4j.Logger; |
41 | 40 | import org.junit.Assert;
|
42 | 41 | import org.junit.Test;
|
43 | 42 | import org.junit.runner.RunWith;
|
| 43 | +import org.mockito.Mock; |
44 | 44 | import org.mockito.MockedStatic;
|
45 | 45 | import org.mockito.Mockito;
|
46 |
| -import static org.mockito.Mockito.times; |
47 | 46 | import org.mockito.Spy;
|
48 | 47 | import org.mockito.junit.MockitoJUnitRunner;
|
| 48 | +import org.springframework.test.util.ReflectionTestUtils; |
49 | 49 |
|
50 | 50 | 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; |
51 | 54 |
|
52 | 55 | @RunWith(MockitoJUnitRunner.class)
|
53 | 56 | public class NfsSecondaryStorageResourceTest {
|
@@ -242,4 +245,45 @@ public void getUploadProtocolTestReturnHttpWhenUseHttpsToUploadIsFalse() {
|
242 | 245 |
|
243 | 246 | Assert.assertEquals(NetUtils.HTTP_PROTO, result);
|
244 | 247 | }
|
| 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 | + } |
245 | 289 | }
|
0 commit comments