|
18 | 18 | package com.cloud.resource; |
19 | 19 |
|
20 | 20 | import com.cloud.agent.AgentManager; |
| 21 | +import com.cloud.agent.api.StartupCommand; |
21 | 22 | import com.cloud.agent.api.GetVncPortAnswer; |
22 | 23 | import com.cloud.agent.api.GetVncPortCommand; |
23 | 24 | import com.cloud.capacity.dao.CapacityDao; |
@@ -335,6 +336,74 @@ public void testGetHostCredentialsMissingParameter() { |
335 | 336 | resourceManager.getHostCredentials(host); |
336 | 337 | } |
337 | 338 |
|
| 339 | + private HostVO mockExistingRoutingHost(long dcId, Long podId, Long clusterId) { |
| 340 | + HostVO existing = Mockito.mock(HostVO.class); |
| 341 | + when(existing.getType()).thenReturn(Host.Type.Routing); |
| 342 | + when(existing.getDataCenterId()).thenReturn(dcId); |
| 343 | + when(existing.getPodId()).thenReturn(podId); |
| 344 | + when(existing.getClusterId()).thenReturn(clusterId); |
| 345 | + when(existing.getUuid()).thenReturn("host-uuid"); |
| 346 | + return existing; |
| 347 | + } |
| 348 | + |
| 349 | + @Test(expected = InvalidParameterValueException.class) |
| 350 | + public void testValidateExistingHostLocationImmutableRejectsZoneChange() { |
| 351 | + HostVO existing = mockExistingRoutingHost(1L, 10L, 100L); |
| 352 | + StartupCommand startup = Mockito.mock(StartupCommand.class); |
| 353 | + when(startup.getPrivateIpAddress()).thenReturn("10.10.10.10"); |
| 354 | + resourceManager.validateExistingHostLocationImmutable(existing, false, 2L, 10L, 100L, startup); |
| 355 | + } |
| 356 | + |
| 357 | + @Test(expected = InvalidParameterValueException.class) |
| 358 | + public void testValidateExistingHostLocationImmutableRejectsPodChange() { |
| 359 | + HostVO existing = mockExistingRoutingHost(1L, 10L, 100L); |
| 360 | + StartupCommand startup = Mockito.mock(StartupCommand.class); |
| 361 | + when(startup.getPrivateIpAddress()).thenReturn("10.10.10.10"); |
| 362 | + resourceManager.validateExistingHostLocationImmutable(existing, false, 1L, 11L, 100L, startup); |
| 363 | + } |
| 364 | + |
| 365 | + @Test(expected = InvalidParameterValueException.class) |
| 366 | + public void testValidateExistingHostLocationImmutableRejectsClusterChange() { |
| 367 | + HostVO existing = mockExistingRoutingHost(1L, 10L, 100L); |
| 368 | + StartupCommand startup = Mockito.mock(StartupCommand.class); |
| 369 | + when(startup.getPrivateIpAddress()).thenReturn("10.10.10.10"); |
| 370 | + resourceManager.validateExistingHostLocationImmutable(existing, false, 1L, 10L, 101L, startup); |
| 371 | + } |
| 372 | + |
| 373 | + @Test |
| 374 | + public void testValidateExistingHostLocationImmutableAllowsSameTupleReconnect() { |
| 375 | + HostVO existing = mockExistingRoutingHost(1L, 10L, 100L); |
| 376 | + resourceManager.validateExistingHostLocationImmutable(existing, false, 1L, 10L, 100L, null); |
| 377 | + } |
| 378 | + |
| 379 | + @Test |
| 380 | + public void testValidateExistingHostLocationImmutableAllowsNewHost() { |
| 381 | + HostVO existing = mockExistingRoutingHost(2L, 20L, 200L); |
| 382 | + resourceManager.validateExistingHostLocationImmutable(existing, true, 1L, 10L, 100L, null); |
| 383 | + } |
| 384 | + |
| 385 | + @Test |
| 386 | + public void testValidateExistingHostLocationImmutableSkipsNonRoutingHost() { |
| 387 | + HostVO existing = Mockito.mock(HostVO.class); |
| 388 | + when(existing.getType()).thenReturn(Host.Type.SecondaryStorageVM); |
| 389 | + resourceManager.validateExistingHostLocationImmutable(existing, false, 1L, 10L, 100L, null); |
| 390 | + } |
| 391 | + |
| 392 | + @Test |
| 393 | + public void testValidateExistingHostLocationImmutableSkipsPartialLocationRow() { |
| 394 | + HostVO existing = Mockito.mock(HostVO.class); |
| 395 | + when(existing.getType()).thenReturn(Host.Type.Routing); |
| 396 | + when(existing.getDataCenterId()).thenReturn(1L); |
| 397 | + when(existing.getPodId()).thenReturn(null); |
| 398 | + when(existing.getClusterId()).thenReturn(null); |
| 399 | + resourceManager.validateExistingHostLocationImmutable(existing, false, 2L, 10L, 100L, null); |
| 400 | + } |
| 401 | + |
| 402 | + @Test |
| 403 | + public void testValidateExistingHostLocationImmutableSkipsNullExistingHost() { |
| 404 | + resourceManager.validateExistingHostLocationImmutable(null, false, 2L, 10L, 100L, null); |
| 405 | + } |
| 406 | + |
338 | 407 | @Test |
339 | 408 | public void testGetHostCredentials() { |
340 | 409 | Ternary<String, String, String> credentials = resourceManager.getHostCredentials(host); |
|
0 commit comments