1717package org .apache .cloudstack .engine .orchestration ;
1818
1919import com .cloud .configuration .Resource ;
20+ import com .cloud .deploy .DeploymentClusterPlanner ;
2021import com .cloud .exception .InvalidParameterValueException ;
2122import com .cloud .exception .StorageAccessException ;
2223import com .cloud .host .Host ;
4647import org .apache .cloudstack .engine .subsystem .api .storage .VolumeDataFactory ;
4748import org .apache .cloudstack .engine .subsystem .api .storage .VolumeInfo ;
4849import org .apache .cloudstack .engine .subsystem .api .storage .VolumeService ;
50+ import org .apache .cloudstack .framework .config .ConfigDepot ;
4951import org .apache .cloudstack .framework .config .ConfigKey ;
52+ import org .apache .cloudstack .framework .config .dao .ConfigurationDao ;
5053import org .apache .cloudstack .secret .PassphraseVO ;
5154import org .apache .cloudstack .secret .dao .PassphraseDao ;
5255import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
6972import java .util .Date ;
7073import java .util .List ;
7174
75+ import static org .apache .cloudstack .engine .orchestration .service .VolumeOrchestrationService .VolumeAllocationAlgorithm ;
7276import static org .junit .Assert .assertNotNull ;
77+ import static org .junit .Assert .assertTrue ;
7378
7479@ RunWith (MockitoJUnitRunner .class )
7580public class VolumeOrchestratorTest {
@@ -96,20 +101,22 @@ public class VolumeOrchestratorTest {
96101 protected DiskOfferingDao diskOfferingDao ;
97102 @ Mock
98103 protected CallContext mockCallContext ;
104+ @ Mock
105+ ConfigDepot configDepot ;
106+ @ Mock
107+ ConfigurationDao configurationDao ;
108+
99109
100110 @ Spy
101111 @ InjectMocks
102112 private VolumeOrchestrator volumeOrchestrator = new VolumeOrchestrator ();
103113
114+
104115 private static final Long DEFAULT_ACCOUNT_PS_RESOURCE_COUNT = 100L ;
105116 private Long accountPSResourceCount ;
106- private static final long MOCK_VOLUME_ID = 101L ;
107117 private static final long MOCK_VM_ID = 202L ;
108118 private static final long MOCK_POOL_ID = 303L ;
109- private static final long MOCK_DISK_OFFERING_ID = 404L ;
110- private static final long MOCK_ACCOUNT_ID = 505L ;
111119 private static final String MOCK_VM_NAME = "Test-VM" ;
112- private static final String MOCK_VOLUME_UUID = "vol-uuid-123" ;
113120
114121 @ Before
115122 public void setUp () throws Exception {
@@ -375,7 +382,7 @@ public void testVolumeOnSharedStoragePoolTrue() {
375382 Mockito .when (pool .getScope ()).thenReturn (ScopeType .CLUSTER ); // Shared scope
376383 Mockito .when (storagePoolDao .findById (MOCK_POOL_ID )).thenReturn (pool );
377384
378- Assert . assertTrue (volumeOrchestrator .volumeOnSharedStoragePool (volume ));
385+ assertTrue (volumeOrchestrator .volumeOnSharedStoragePool (volume ));
379386 }
380387
381388 @ Test
@@ -414,7 +421,7 @@ public void testVolumeOnSharedStoragePoolFalsePoolNotFound() {
414421 public void testVolumeInactiveNoVmId () {
415422 VolumeVO volume = Mockito .mock (VolumeVO .class );
416423 Mockito .when (volume .getInstanceId ()).thenReturn (null );
417- Assert . assertTrue (volumeOrchestrator .volumeInactive (volume ));
424+ assertTrue (volumeOrchestrator .volumeInactive (volume ));
418425 Mockito .verify (entityMgr , Mockito .never ()).findById (Mockito .eq (UserVm .class ), Mockito .anyLong ());
419426 }
420427
@@ -423,7 +430,7 @@ public void testVolumeInactiveVmNotFound() {
423430 VolumeVO volume = Mockito .mock (VolumeVO .class );
424431 Mockito .when (volume .getInstanceId ()).thenReturn (MOCK_VM_ID );
425432 Mockito .when (entityMgr .findById (UserVm .class , MOCK_VM_ID )).thenReturn (null );
426- Assert . assertTrue (volumeOrchestrator .volumeInactive (volume ));
433+ assertTrue (volumeOrchestrator .volumeInactive (volume ));
427434 }
428435
429436 @ Test
@@ -433,7 +440,7 @@ public void testVolumeInactiveVmStopped() {
433440 UserVm vm = Mockito .mock (UserVm .class );
434441 Mockito .when (vm .getState ()).thenReturn (VirtualMachine .State .Stopped );
435442 Mockito .when (entityMgr .findById (UserVm .class , MOCK_VM_ID )).thenReturn (vm );
436- Assert . assertTrue (volumeOrchestrator .volumeInactive (volume ));
443+ assertTrue (volumeOrchestrator .volumeInactive (volume ));
437444 }
438445
439446 @ Test
@@ -443,7 +450,7 @@ public void testVolumeInactiveVmDestroyed() {
443450 UserVm vm = Mockito .mock (UserVm .class );
444451 Mockito .when (vm .getState ()).thenReturn (VirtualMachine .State .Destroyed );
445452 Mockito .when (entityMgr .findById (UserVm .class , MOCK_VM_ID )).thenReturn (vm );
446- Assert . assertTrue (volumeOrchestrator .volumeInactive (volume ));
453+ assertTrue (volumeOrchestrator .volumeInactive (volume ));
447454 }
448455
449456 @ Test
@@ -485,8 +492,8 @@ public void testGetVmNameOnVolumeSuccess() {
485492 @ Test
486493 public void testValidateVolumeSizeRangeValid () throws Exception {
487494 overrideDefaultConfigValue (VolumeOrchestrator .MaxVolumeSize , "2000" );
488- Assert . assertTrue (volumeOrchestrator .validateVolumeSizeRange (1024 * 1024 * 1024 )); // 1 GiB
489- Assert . assertTrue (volumeOrchestrator .validateVolumeSizeRange (2000 * 1024 * 1024 * 1024 )); // 2 TiB
495+ assertTrue (volumeOrchestrator .validateVolumeSizeRange (1024 * 1024 * 1024 )); // 1 GiB
496+ assertTrue (volumeOrchestrator .validateVolumeSizeRange (2000 * 1024 * 1024 * 1024 )); // 2 TiB
490497 }
491498
492499 @ Test (expected = InvalidParameterValueException .class )
@@ -525,7 +532,7 @@ public void testCanVmRestartOnAnotherServerAllShared() {
525532 Mockito .when (storagePoolDao .findById (20L )).thenReturn (pool2 );
526533
527534
528- Assert . assertTrue (volumeOrchestrator .canVmRestartOnAnotherServer (MOCK_VM_ID ));
535+ assertTrue (volumeOrchestrator .canVmRestartOnAnotherServer (MOCK_VM_ID ));
529536 }
530537
531538 @ Test
@@ -567,7 +574,7 @@ public void testCanVmRestartOnAnotherServerOneLocalRecreatable() {
567574 Mockito .when (storagePoolDao .findById (10L )).thenReturn (pool1 );
568575 Mockito .when (storagePoolDao .findById (30L )).thenReturn (pool2 );
569576
570- Assert . assertTrue ("VM restart should be true if local disk is recreatable" ,
577+ assertTrue ("VM restart should be true if local disk is recreatable" ,
571578 volumeOrchestrator .canVmRestartOnAnotherServer (MOCK_VM_ID ));
572579 }
573580
@@ -576,4 +583,17 @@ private void overrideDefaultConfigValue(final ConfigKey configKey, final String
576583 f .setAccessible (true );
577584 f .set (configKey , value );
578585 }
586+
587+ @ Test
588+ public void testStart () throws Exception {
589+ Mockito .when (configDepot .isNewConfig (VolumeAllocationAlgorithm )).thenReturn (true );
590+ overrideDefaultConfigValue (DeploymentClusterPlanner .VmAllocationAlgorithm , "firstfit" );
591+ Mockito .when (configurationDao .update (Mockito .anyString (), Mockito .anyString ())).thenReturn (true );
592+ volumeOrchestrator .start ();
593+ }
594+
595+ @ Test
596+ public void testConfigKeys () {
597+ assertTrue (volumeOrchestrator .getConfigKeys ().length > 0 );
598+ }
579599}
0 commit comments