Repository navigation
CLOUDSTACK-8704: Schedule restart of router VMs ahead of user VMs as … #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.lang.reflect.Array; | ||
| import java.lang.reflect.Field; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
|
|
@@ -57,6 +58,7 @@ | |
| import com.cloud.storage.dao.GuestOSDao; | ||
| import com.cloud.user.AccountManager; | ||
| import com.cloud.vm.VMInstanceVO; | ||
| import com.cloud.vm.VirtualMachine; | ||
| import com.cloud.vm.VirtualMachineManager; | ||
| import com.cloud.vm.dao.VMInstanceDao; | ||
|
|
||
|
|
@@ -74,13 +76,10 @@ public class HighAvailabilityManagerImplTest { | |
| HostPodDao _podDao; | ||
| @Mock | ||
| ClusterDetailsDao _clusterDetailsDao; | ||
|
|
||
| @Mock | ||
| ServiceOfferingDao _serviceOfferingDao; | ||
|
|
||
| @Mock | ||
| ManagedContext _managedContext; | ||
|
|
||
| @Mock | ||
| AgentManager _agentMgr; | ||
| @Mock | ||
|
|
@@ -103,7 +102,6 @@ public class HighAvailabilityManagerImplTest { | |
| ConfigurationDao _configDao; | ||
| @Mock | ||
| VolumeOrchestrationService volumeMgr; | ||
|
|
||
| @Mock | ||
| HostVO hostVO; | ||
|
|
||
|
|
@@ -113,12 +111,18 @@ public class HighAvailabilityManagerImplTest { | |
| public void setup() throws IllegalArgumentException, | ||
| IllegalAccessException, NoSuchFieldException, SecurityException { | ||
| highAvailabilityManager = new HighAvailabilityManagerImpl(); | ||
| for (Field injectField : HighAvailabilityManagerImpl.class | ||
| .getDeclaredFields()) { | ||
| for (Field injectField : HighAvailabilityManagerImpl.class.getDeclaredFields()) { | ||
| if (injectField.isAnnotationPresent(Inject.class)) { | ||
| injectField.setAccessible(true); | ||
| injectField.set(highAvailabilityManager, this.getClass() | ||
| .getDeclaredField(injectField.getName()).get(this)); | ||
| injectField.set(highAvailabilityManager, this.getClass().getDeclaredField(injectField.getName()).get(this)); | ||
| } else if (injectField.getName().equals("_workers")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this is needed for the extra tests. Can you explain?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. "_workers" is the set of worker threads that perform HA related tasks in HighAvaiabilityManagerImpl class. As part of the test wakeupWorkers() methods get invoked which needs _workers to be initialized. |
||
| injectField.setAccessible(true); | ||
| for (Class<?> clz : HighAvailabilityManagerImpl.class.getDeclaredClasses()) { | ||
| if (clz.getName().equals("com.cloud.ha.HighAvailabilityManagerImpl$WorkerThread")) { | ||
| Object obj = Array.newInstance(clz, 0); | ||
| injectField.set(highAvailabilityManager, obj); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -127,10 +131,47 @@ public void setup() throws IllegalArgumentException, | |
| public void scheduleRestartForVmsOnHost() { | ||
| Mockito.when(hostVO.getType()).thenReturn(Host.Type.Routing); | ||
| Mockito.when(hostVO.getHypervisorType()).thenReturn(HypervisorType.KVM); | ||
| Mockito.when(_instanceDao.listByHostId(42l)).thenReturn( | ||
| Arrays.asList(Mockito.mock(VMInstanceVO.class))); | ||
| Mockito.when(_instanceDao.listByHostId(42l)).thenReturn(Arrays.asList(Mockito.mock(VMInstanceVO.class))); | ||
| Mockito.when(_podDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(HostPodVO.class)); | ||
| Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(DataCenterVO.class)); | ||
|
|
||
| highAvailabilityManager.scheduleRestartForVmsOnHost(hostVO, true); | ||
| } | ||
|
|
||
| @Test | ||
| public void scheduleRestartForVmsOnHostNotSupported() { | ||
| Mockito.when(hostVO.getType()).thenReturn(Host.Type.Routing); | ||
| Mockito.when(hostVO.getHypervisorType()).thenReturn(HypervisorType.VMware); | ||
|
|
||
| highAvailabilityManager.scheduleRestartForVmsOnHost(hostVO, true); | ||
| } | ||
|
|
||
| @Test | ||
| public void scheduleRestartForVmsOnHostNonEmptyVMList() { | ||
| Mockito.when(hostVO.getId()).thenReturn(1l); | ||
| Mockito.when(hostVO.getType()).thenReturn(Host.Type.Routing); | ||
| Mockito.when(hostVO.getHypervisorType()).thenReturn(HypervisorType.XenServer); | ||
| List<VMInstanceVO> vms = new ArrayList<VMInstanceVO>(); | ||
| VMInstanceVO vm1 = Mockito.mock(VMInstanceVO.class); | ||
| Mockito.when(vm1.getHostId()).thenReturn(1l); | ||
| Mockito.when(vm1.getInstanceName()).thenReturn("i-2-3-VM"); | ||
| Mockito.when(vm1.getType()).thenReturn(VirtualMachine.Type.User); | ||
| Mockito.when(vm1.isHaEnabled()).thenReturn(true); | ||
| vms.add(vm1); | ||
| VMInstanceVO vm2 = Mockito.mock(VMInstanceVO.class); | ||
| Mockito.when(vm2.getHostId()).thenReturn(1l); | ||
| Mockito.when(vm2.getInstanceName()).thenReturn("r-2-VM"); | ||
| Mockito.when(vm2.getType()).thenReturn(VirtualMachine.Type.DomainRouter); | ||
| Mockito.when(vm2.isHaEnabled()).thenReturn(true); | ||
| vms.add(vm2); | ||
| Mockito.when(_instanceDao.listByHostId(Mockito.anyLong())).thenReturn(vms); | ||
| Mockito.when(_instanceDao.findByUuid(vm1.getUuid())).thenReturn(vm1); | ||
| Mockito.when(_instanceDao.findByUuid(vm2.getUuid())).thenReturn(vm2); | ||
| Mockito.when(_podDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(HostPodVO.class)); | ||
| Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(Mockito.mock(DataCenterVO.class)); | ||
| Mockito.when(_haDao.findPreviousHA(Mockito.anyLong())).thenReturn(Arrays.asList(Mockito.mock(HaWorkVO.class))); | ||
| Mockito.when(_haDao.persist((HaWorkVO)Mockito.anyObject())).thenReturn(Mockito.mock(HaWorkVO.class)); | ||
|
|
||
| highAvailabilityManager.scheduleRestartForVmsOnHost(hostVO, true); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no biggy for this PR, but why is this chack needed? The vms are retrieved by the host id of the host being down in the first place (see line 240).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaanHoogland The host check you are referring to existed even before this PR. One reason for the check is to ensure that the VM has not moved to another host since the time it was fetched using listByHostId(). If it has moved to another host (and vmsync has updated the host id) then no need to perform restart/HA.