@@ -4855,6 +4855,7 @@ public void testStartCommand() {
48554855
48564856 final NicTO nic = Mockito .mock (NicTO .class );
48574857 final NicTO [] nics = new NicTO []{nic };
4858+ final int [] vms = new int [0 ];
48584859
48594860 final String vmName = "Test" ;
48604861 final String controlIp = "127.0.0.1" ;
@@ -4868,6 +4869,7 @@ public void testStartCommand() {
48684869 when (libvirtComputingResource .getLibvirtUtilitiesHelper ()).thenReturn (libvirtUtilitiesHelper );
48694870 try {
48704871 when (libvirtUtilitiesHelper .getConnectionByType (vmDef .getHvsType ())).thenReturn (conn );
4872+ when (conn .listDomains ()).thenReturn (vms );
48714873 doNothing ().when (libvirtComputingResource ).createVbd (conn , vmSpec , vmName , vmDef );
48724874 } catch (final LibvirtException e ) {
48734875 fail (e .getMessage ());
@@ -4927,6 +4929,7 @@ public void testStartCommandIsolationEc2() {
49274929
49284930 final NicTO nic = Mockito .mock (NicTO .class );
49294931 final NicTO [] nics = new NicTO []{nic };
4932+ final int [] vms = new int [0 ];
49304933
49314934 final String vmName = "Test" ;
49324935 final String controlIp = "127.0.0.1" ;
@@ -4940,6 +4943,7 @@ public void testStartCommandIsolationEc2() {
49404943 when (libvirtComputingResource .getLibvirtUtilitiesHelper ()).thenReturn (libvirtUtilitiesHelper );
49414944 try {
49424945 when (libvirtUtilitiesHelper .getConnectionByType (vmDef .getHvsType ())).thenReturn (conn );
4946+ when (conn .listDomains ()).thenReturn (vms );
49434947 doNothing ().when (libvirtComputingResource ).createVbd (conn , vmSpec , vmName , vmDef );
49444948 } catch (final LibvirtException e ) {
49454949 fail (e .getMessage ());
@@ -4989,6 +4993,61 @@ public void testStartCommandIsolationEc2() {
49894993 }
49904994 }
49914995
4996+ @ Test
4997+ public void testStartCommandHostMemory () {
4998+ final VirtualMachineTO vmSpec = Mockito .mock (VirtualMachineTO .class );
4999+ final com .cloud .host .Host host = Mockito .mock (com .cloud .host .Host .class );
5000+ final boolean executeInSequence = false ;
5001+
5002+ final StartCommand command = new StartCommand (vmSpec , host , executeInSequence );
5003+
5004+ final KVMStoragePoolManager storagePoolMgr = Mockito .mock (KVMStoragePoolManager .class );
5005+ final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito .mock (LibvirtUtilitiesHelper .class );
5006+ final Connect conn = Mockito .mock (Connect .class );
5007+ final LibvirtVMDef vmDef = Mockito .mock (LibvirtVMDef .class );
5008+
5009+ final NicTO nic = Mockito .mock (NicTO .class );
5010+ final NicTO [] nics = new NicTO []{nic };
5011+ int vmId = 1 ;
5012+ final int [] vms = new int []{vmId };
5013+ final Domain dm = Mockito .mock (Domain .class );
5014+
5015+ final String vmName = "Test" ;
5016+
5017+ when (libvirtComputingResource .getStoragePoolMgr ()).thenReturn (storagePoolMgr );
5018+ when (vmSpec .getNics ()).thenReturn (nics );
5019+ when (vmSpec .getType ()).thenReturn (VirtualMachine .Type .User );
5020+ when (vmSpec .getName ()).thenReturn (vmName );
5021+ when (vmSpec .getMaxRam ()).thenReturn (512L );
5022+ when (libvirtComputingResource .createVMFromSpec (vmSpec )).thenReturn (vmDef );
5023+
5024+ when (libvirtComputingResource .getLibvirtUtilitiesHelper ()).thenReturn (libvirtUtilitiesHelper );
5025+ try {
5026+ when (libvirtUtilitiesHelper .getConnectionByType (vmDef .getHvsType ())).thenReturn (conn );
5027+ when (conn .listDomains ()).thenReturn (vms );
5028+ when (conn .domainLookupByID (vmId )).thenReturn (dm );
5029+ when (dm .getMaxMemory ()).thenReturn (1024L );
5030+ when (dm .getName ()).thenReturn (vmName );
5031+ when (libvirtComputingResource .getTotalMemory ()).thenReturn (2048 *1024L );
5032+ doNothing ().when (libvirtComputingResource ).createVbd (conn , vmSpec , vmName , vmDef );
5033+ } catch (final LibvirtException e ) {
5034+ fail (e .getMessage ());
5035+ } catch (final InternalErrorException e ) {
5036+ fail (e .getMessage ());
5037+ } catch (final URISyntaxException e ) {
5038+ fail (e .getMessage ());
5039+ }
5040+
5041+ when (storagePoolMgr .connectPhysicalDisksViaVmSpec (vmSpec )).thenReturn (true );
5042+
5043+ final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper .getInstance ();
5044+ assertNotNull (wrapper );
5045+
5046+ final Answer answer = wrapper .execute (command , libvirtComputingResource );
5047+ assertTrue (answer .getResult ());
5048+ }
5049+
5050+
49925051 @ Test
49935052 public void testUpdateHostPasswordCommand () {
49945053 final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito .mock (LibvirtUtilitiesHelper .class );
0 commit comments