Skip to content

Commit 2bc9051

Browse files
author
kunal.behbudzade
committed
KVM: add regression tests for UEFI disk-only instance snapshots
Cover host capability synchronization, UEFI NVRAM sidecar handling across create/revert/delete flows, and the running-VM recovery paths for disk-only instance snapshots.
1 parent 703a0ce commit 2bc9051

File tree

3 files changed

+1160
-1
lines changed

3 files changed

+1160
-1
lines changed

engine/orchestration/src/test/java/com/cloud/agent/manager/AgentManagerImplTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
import com.cloud.agent.Listener;
2020
import com.cloud.agent.api.Answer;
21+
import com.cloud.agent.api.ReadyAnswer;
2122
import com.cloud.agent.api.ReadyCommand;
2223
import com.cloud.agent.api.StartupCommand;
2324
import com.cloud.agent.api.StartupRoutingCommand;
2425
import com.cloud.exception.ConnectionException;
26+
import com.cloud.host.DetailVO;
2527
import com.cloud.host.Host;
2628
import com.cloud.host.HostVO;
2729
import com.cloud.host.Status;
2830
import com.cloud.host.dao.HostDao;
31+
import com.cloud.host.dao.HostDetailsDao;
2932
import com.cloud.hypervisor.Hypervisor;
3033
import com.cloud.utils.Pair;
3134
import org.junit.Assert;
@@ -34,10 +37,13 @@
3437
import org.mockito.Mockito;
3538

3639
import java.util.ArrayList;
40+
import java.util.HashMap;
41+
import java.util.Map;
3742

3843
public class AgentManagerImplTest {
3944

4045
private HostDao hostDao;
46+
private HostDetailsDao hostDetailsDao;
4147
private Listener storagePoolMonitor;
4248
private AgentAttache attache;
4349
private AgentManagerImpl mgr = Mockito.spy(new AgentManagerImpl());
@@ -46,15 +52,18 @@ public class AgentManagerImplTest {
4652

4753
@Before
4854
public void setUp() throws Exception {
49-
host = new HostVO("some-Uuid");
55+
host = Mockito.spy(new HostVO("some-Uuid"));
56+
Mockito.when(host.getId()).thenReturn(1L);
5057
host.setDataCenterId(1L);
5158
cmds = new StartupCommand[]{new StartupRoutingCommand()};
5259
attache = new ConnectedAgentAttache(null, 1L, "uuid", "kvm-attache", Hypervisor.HypervisorType.KVM, null, false);
5360

5461
hostDao = Mockito.mock(HostDao.class);
62+
hostDetailsDao = Mockito.mock(HostDetailsDao.class);
5563
storagePoolMonitor = Mockito.mock(Listener.class);
5664

5765
mgr._hostDao = hostDao;
66+
mgr._hostDetailsDao = hostDetailsDao;
5867
mgr._hostMonitors = new ArrayList<>();
5968
mgr._hostMonitors.add(new Pair<>(0, storagePoolMonitor));
6069
}
@@ -86,6 +95,32 @@ public void testNotifyMonitorsOfConnectionWhenStoragePoolConnectionHostFailure()
8695
Mockito.verify(mgr, Mockito.times(1)).handleDisconnectWithoutInvestigation(Mockito.any(attache.getClass()), Mockito.eq(Status.Event.AgentDisconnected), Mockito.eq(true), Mockito.eq(true));
8796
}
8897

98+
@Test
99+
public void testNotifyMonitorsOfConnectionClearsStaleNvramCapabilityOnReconnect() throws ConnectionException {
100+
DetailVO staleNvramCapability = Mockito.mock(DetailVO.class);
101+
ReadyAnswer readyAnswer = Mockito.mock(ReadyAnswer.class);
102+
host.setDetails(new HashMap<>(Map.of(Host.HOST_UEFI_ENABLE, Boolean.TRUE.toString(),
103+
Host.HOST_KVM_DISK_ONLY_VM_SNAPSHOT_NVRAM, Boolean.TRUE.toString())));
104+
105+
Mockito.when(staleNvramCapability.getId()).thenReturn(11L);
106+
Mockito.when(hostDao.findById(Mockito.anyLong())).thenReturn(host);
107+
Mockito.doNothing().when(hostDao).loadDetails(host);
108+
Mockito.when(hostDetailsDao.findDetail(host.getId(), Host.HOST_KVM_DISK_ONLY_VM_SNAPSHOT_NVRAM)).thenReturn(staleNvramCapability);
109+
Mockito.doNothing().when(storagePoolMonitor).processConnect(Mockito.eq(host), Mockito.eq(cmds[0]), Mockito.eq(false));
110+
Mockito.doReturn(true).when(mgr).handleDisconnectWithoutInvestigation(Mockito.any(attache.getClass()), Mockito.any(Status.Event.class), Mockito.anyBoolean(), Mockito.anyBoolean());
111+
Mockito.when(readyAnswer.getResult()).thenReturn(true);
112+
Mockito.when(readyAnswer.getDetailsMap()).thenReturn(Map.of(Host.HOST_UEFI_ENABLE, Boolean.TRUE.toString()));
113+
Mockito.doReturn(readyAnswer).when(mgr).easySend(Mockito.anyLong(), Mockito.any(ReadyCommand.class));
114+
Mockito.doReturn(true).when(mgr).agentStatusTransitTo(Mockito.eq(host), Mockito.eq(Status.Event.Ready), Mockito.anyLong());
115+
116+
final AgentAttache agentAttache = mgr.notifyMonitorsOfConnection(attache, cmds, false);
117+
118+
Assert.assertTrue(agentAttache.isReady());
119+
Assert.assertFalse(host.getDetails().containsKey(Host.HOST_KVM_DISK_ONLY_VM_SNAPSHOT_NVRAM));
120+
Mockito.verify(hostDetailsDao).remove(11L);
121+
Mockito.verify(hostDao).saveDetails(host);
122+
}
123+
89124
@Test
90125
public void testGetTimeoutWithPositiveTimeout() {
91126
Commands commands = Mockito.mock(Commands.class);

0 commit comments

Comments
 (0)