Skip to content

Commit 0f97674

Browse files
João JandreJoaoJandre
authored andcommitted
Fix waiting for block commit
1 parent 64178ea commit 0f97674

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BlockCommitListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public class BlockCommitListener implements BlockJobListener {
3737
protected BlockCommitListener(String vmName, String logid) {
3838
this.vmName = vmName;
3939
this.logid = logid;
40-
logger = LogManager.getLogger(getClass());
40+
this.logger = LogManager.getLogger(getClass());
41+
this.result = String.format("Failed to block commit disk of VM [%s]. Libvirt did not launch an event for it.", vmName);
4142
}
4243

4344
protected String getResult() {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6656,8 +6656,7 @@ protected void mergeSnapshotIntoBaseFileWithEventsAndConfigurableTimeout(Domain
66566656
vm.addBlockJobListener(blockCommitListener);
66576657

66586658
logger.info("Starting block commit of QCOW2 delta [{}] of VM [{}]. Using parameters: diskLabel [{}]; baseFilePath [{}]; topFilePath [{}]; commitFlags [{}]",
6659-
snapshotName,
6660-
vmName, diskLabel, baseFilePath, topFilePath, commitFlags);
6659+
snapshotName, vmName, diskLabel, baseFilePath, topFilePath, commitFlags);
66616660

66626661
vm.blockCommit(diskLabel, baseFilePath, topFilePath, 0, commitFlags);
66636662

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6696,9 +6696,11 @@ public void mergeSnapshotIntoBaseFileTestActiveAndDeleteFlags() throws Exception
66966696

66976697
threadContextMockedStatic.when(() ->
66986698
ThreadContext.get(Mockito.anyString())).thenReturn("logid");
6699-
Mockito.doNothing().when(domainMock).addBlockJobListener(Mockito.any());
6699+
Mockito.doReturn(blockCommitListenerMock).when(libvirtComputingResourceSpy).getBlockCommitListener(Mockito.any());
6700+
Mockito.doReturn(null).when(blockCommitListenerMock).getResult();
6701+
Mockito.doNothing().when(domainMock).addBlockJobListener(blockCommitListenerMock);
67006702
Mockito.doReturn(null).when(domainMock).getBlockJobInfo(Mockito.anyString(), Mockito.anyInt());
6701-
Mockito.doNothing().when(domainMock).removeBlockJobListener(Mockito.any());
6703+
Mockito.doNothing().when(domainMock).removeBlockJobListener(blockCommitListenerMock);
67026704

67036705
String diskLabel = "vda";
67046706
String baseFilePath = "/file";
@@ -6723,8 +6725,10 @@ public void mergeSnapshotIntoBaseFileTestActiveFlag() throws Exception {
67236725

67246726
threadContextMockedStatic.when(() ->
67256727
ThreadContext.get(Mockito.anyString())).thenReturn("logid");
6726-
Mockito.doNothing().when(domainMock).addBlockJobListener(Mockito.any());
6727-
Mockito.doNothing().when(domainMock).removeBlockJobListener(Mockito.any());
6728+
Mockito.doReturn(blockCommitListenerMock).when(libvirtComputingResourceSpy).getBlockCommitListener(Mockito.any());
6729+
Mockito.doReturn(null).when(blockCommitListenerMock).getResult();
6730+
Mockito.doNothing().when(domainMock).addBlockJobListener(blockCommitListenerMock);
6731+
Mockito.doNothing().when(domainMock).removeBlockJobListener(blockCommitListenerMock);
67286732
Mockito.doNothing().when(libvirtComputingResourceSpy).manuallyDeleteUnusedSnapshotFile(Mockito.anyBoolean(), Mockito.anyString());
67296733

67306734
String diskLabel = "vda";
@@ -6748,9 +6752,11 @@ public void mergeSnapshotIntoBaseFileTestDeleteFlag() throws Exception {
67486752
libvirtComputingResourceSpy.qcow2DeltaMergeTimeout = 10;
67496753
libvirtUtilitiesHelperMockedStatic.when(() -> LibvirtUtilitiesHelper.isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit(Mockito.any())).thenReturn(true);
67506754
threadContextMockedStatic.when(() -> ThreadContext.get(Mockito.anyString())).thenReturn("logid");
6751-
Mockito.doNothing().when(domainMock).addBlockJobListener(Mockito.any());
6755+
Mockito.doReturn(blockCommitListenerMock).when(libvirtComputingResourceSpy).getBlockCommitListener(Mockito.any());
6756+
Mockito.doReturn(null).when(blockCommitListenerMock).getResult();
6757+
Mockito.doNothing().when(domainMock).addBlockJobListener(blockCommitListenerMock);
67526758
Mockito.doReturn(null).when(domainMock).getBlockJobInfo(Mockito.anyString(), Mockito.anyInt());
6753-
Mockito.doNothing().when(domainMock).removeBlockJobListener(Mockito.any());
6759+
Mockito.doNothing().when(domainMock).removeBlockJobListener(blockCommitListenerMock);
67546760
Mockito.doNothing().when(libvirtComputingResourceSpy).manuallyDeleteUnusedSnapshotFile(Mockito.anyBoolean(), Mockito.anyString());
67556761

67566762
String diskLabel = "vda";
@@ -6774,9 +6780,11 @@ public void mergeSnapshotIntoBaseFileTestNoFlags() throws Exception {
67746780
libvirtComputingResourceSpy.qcow2DeltaMergeTimeout = 10;
67756781
libvirtUtilitiesHelperMockedStatic.when(() -> LibvirtUtilitiesHelper.isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit(Mockito.any())).thenReturn(false);
67766782
threadContextMockedStatic.when(() -> ThreadContext.get(Mockito.anyString())).thenReturn("logid");
6777-
Mockito.doNothing().when(domainMock).addBlockJobListener(Mockito.any());
6783+
Mockito.doReturn(blockCommitListenerMock).when(libvirtComputingResourceSpy).getBlockCommitListener(Mockito.any());
6784+
Mockito.doReturn(null).when(blockCommitListenerMock).getResult();
6785+
Mockito.doNothing().when(domainMock).addBlockJobListener(blockCommitListenerMock);
67786786
Mockito.doReturn(null).when(domainMock).getBlockJobInfo(Mockito.anyString(), Mockito.anyInt());
6779-
Mockito.doNothing().when(domainMock).removeBlockJobListener(Mockito.any());
6787+
Mockito.doNothing().when(domainMock).removeBlockJobListener(blockCommitListenerMock);
67806788
Mockito.doNothing().when(libvirtComputingResourceSpy).manuallyDeleteUnusedSnapshotFile(Mockito.anyBoolean(), Mockito.anyString());
67816789

67826790
String diskLabel = "vda";

0 commit comments

Comments
 (0)