|
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; |
| 23 | +import static org.mockito.Mockito.times; |
25 | 24 |
|
26 | 25 | import java.io.File; |
27 | 26 | import java.nio.file.Files; |
28 | 27 | import java.nio.file.Path; |
| 28 | +import java.util.HashMap; |
29 | 29 | import java.util.List; |
| 30 | +import java.util.Map; |
30 | 31 | import java.util.stream.Stream; |
31 | 32 |
|
32 | | -import com.cloud.exception.InvalidParameterValueException; |
33 | | -import com.cloud.utils.EncryptionUtil; |
34 | | -import com.cloud.utils.net.NetUtils; |
35 | 33 | import org.apache.cloudstack.storage.command.DeleteCommand; |
36 | 34 | import org.apache.cloudstack.storage.command.QuerySnapshotZoneCopyAnswer; |
37 | 35 | import org.apache.cloudstack.storage.command.QuerySnapshotZoneCopyCommand; |
38 | 36 | import org.apache.cloudstack.storage.to.SnapshotObjectTO; |
39 | 37 | import org.apache.cloudstack.storage.to.TemplateObjectTO; |
| 38 | +import org.apache.logging.log4j.Logger; |
40 | 39 | import org.junit.Assert; |
41 | 40 | import org.junit.Test; |
42 | 41 | import org.junit.runner.RunWith; |
| 42 | +import org.mockito.Mock; |
43 | 43 | import org.mockito.MockedStatic; |
44 | 44 | import org.mockito.Mockito; |
45 | | -import static org.mockito.Mockito.times; |
46 | 45 | import org.mockito.Spy; |
47 | 46 | import org.mockito.junit.MockitoJUnitRunner; |
| 47 | +import org.springframework.test.util.ReflectionTestUtils; |
48 | 48 |
|
49 | 49 | import com.cloud.agent.api.to.DataStoreTO; |
| 50 | +import com.cloud.exception.InvalidParameterValueException; |
| 51 | +import com.cloud.utils.EncryptionUtil; |
| 52 | +import com.cloud.utils.net.NetUtils; |
50 | 53 |
|
51 | 54 | @RunWith(MockitoJUnitRunner.class) |
52 | 55 | public class NfsSecondaryStorageResourceTest { |
@@ -241,4 +244,45 @@ public void getUploadProtocolTestReturnHttpWhenUseHttpsToUploadIsFalse() { |
241 | 244 |
|
242 | 245 | Assert.assertEquals(NetUtils.HTTP_PROTO, result); |
243 | 246 | } |
| 247 | + |
| 248 | + @Test |
| 249 | + public void configureStorageNetworkSetsStorageNetworkWhenParamsContainValues() { |
| 250 | + Map<String, Object> params = new HashMap<>(); |
| 251 | + String ip = "192.168.1.10"; |
| 252 | + String netmask = "255.255.255.0"; |
| 253 | + String gateway = "192.168.1.1"; |
| 254 | + params.put("storageip", ip); |
| 255 | + params.put("storagenetmask", netmask); |
| 256 | + params.put("storagegateway", gateway); |
| 257 | + resource.configureStorageNetwork(params); |
| 258 | + Assert.assertEquals(ip, ReflectionTestUtils.getField(resource, "_storageIp")); |
| 259 | + Assert.assertEquals(netmask, ReflectionTestUtils.getField(resource, "_storageNetmask")); |
| 260 | + Assert.assertEquals(gateway, ReflectionTestUtils.getField(resource, "_storageGateway")); |
| 261 | + } |
| 262 | + |
| 263 | + @Test |
| 264 | + public void configureStorageNetworkUsesManagementNetworkWhenStorageIpIsNullAndInSystemVM() { |
| 265 | + Map<String, Object> params = new HashMap<>(); |
| 266 | + resource._inSystemVM = true; |
| 267 | + String ip = "10.0.0.10"; |
| 268 | + String netmask = "255.255.255.0"; |
| 269 | + String gateway = "10.0.0.1"; |
| 270 | + ReflectionTestUtils.setField(resource, "_eth1ip", ip); |
| 271 | + ReflectionTestUtils.setField(resource, "_eth1mask", netmask); |
| 272 | + ReflectionTestUtils.setField(resource, "_localgw", gateway); |
| 273 | + resource.configureStorageNetwork(params); |
| 274 | + Assert.assertEquals(ip, ReflectionTestUtils.getField(resource, "_storageIp")); |
| 275 | + Assert.assertEquals(netmask, ReflectionTestUtils.getField(resource, "_storageNetmask")); |
| 276 | + Assert.assertEquals(gateway, ReflectionTestUtils.getField(resource, "_storageGateway")); |
| 277 | + } |
| 278 | + |
| 279 | + @Test |
| 280 | + public void configureStorageNetworkDoesNotSetStorageNetworkWhenNotInSystemVMAndStorageIpIsNull() { |
| 281 | + Map<String, Object> params = new HashMap<>(); |
| 282 | + resource._inSystemVM = false; |
| 283 | + resource.configureStorageNetwork(params); |
| 284 | + Assert.assertNull(ReflectionTestUtils.getField(resource, "_storageIp")); |
| 285 | + Assert.assertNull(ReflectionTestUtils.getField(resource, "_storageNetmask")); |
| 286 | + Assert.assertNull(ReflectionTestUtils.getField(resource, "_storageGateway")); |
| 287 | + } |
244 | 288 | } |
0 commit comments