Skip to content

Commit 607a63b

Browse files
wilderrodriguesyadvr
authored andcommitted
Mocking the Connect object used in the LibvirtMigrateCommandWrapper
When executing the tests in an environment where Libvirt is also installed, it caused errors. Signed-off-by: Rohit Yadav <[email protected]> This closes #342
1 parent 6c1dde8 commit 607a63b

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Answer execute(final MigrateCommand command, final LibvirtComputingResour
8686
*/
8787
xmlDesc = dm.getXMLDesc(0).replace(libvirtComputingResource.getPrivateIp(), command.getDestinationIp());
8888

89-
dconn = new Connect("qemu+tcp://" + command.getDestinationIp() + "/system");
89+
dconn = libvirtUtilitiesHelper.retrieveQemuConnection("qemu+tcp://" + command.getDestinationIp() + "/system");
9090

9191
//run migration in thread so we can monitor it
9292
s_logger.info("Live migration of instance " + vmName + " initiated");

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@ public String retrieveSshPrvKeyPath() {
8686
public String retrieveBashScriptPath() {
8787
return LibvirtComputingResource.BASH_SCRIPT_PATH;
8888
}
89+
90+
public Connect retrieveQemuConnection(final String qemuURI) throws LibvirtException {
91+
return new Connect(qemuURI);
92+
}
8993
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,13 +1205,10 @@ public void testPrepareForMigrationCommandInternalErrorException() {
12051205
verify(vm, times(1)).getNics();
12061206
}
12071207

1208-
@Test(expected = UnsatisfiedLinkError.class)
1208+
@Test
12091209
public void testMigrateCommand() {
1210-
// The Connect constructor used inside the LibvirtMigrateCommandWrapper has a call to native methods, which
1211-
// makes difficult to test it now.
1212-
// Will keep it expecting the UnsatisfiedLinkError and fix later.
1213-
12141210
final Connect conn = Mockito.mock(Connect.class);
1211+
final Connect dconn = Mockito.mock(Connect.class);
12151212
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
12161213

12171214
final String vmName = "Test";
@@ -1225,6 +1222,8 @@ public void testMigrateCommand() {
12251222
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
12261223
try {
12271224
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
1225+
when(libvirtUtilitiesHelper.retrieveQemuConnection("qemu+tcp://" + command.getDestinationIp() + "/system")).thenReturn(dconn);
1226+
12281227
} catch (final LibvirtException e) {
12291228
fail(e.getMessage());
12301229
}
@@ -1259,11 +1258,12 @@ public void testMigrateCommand() {
12591258
assertNotNull(wrapper);
12601259

12611260
final Answer answer = wrapper.execute(command, libvirtComputingResource);
1262-
assertFalse(answer.getResult());
1261+
assertTrue(answer.getResult());
12631262

12641263
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
12651264
try {
12661265
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
1266+
verify(libvirtUtilitiesHelper, times(1)).retrieveQemuConnection("qemu+tcp://" + command.getDestinationIp() + "/system");
12671267
} catch (final LibvirtException e) {
12681268
fail(e.getMessage());
12691269
}

0 commit comments

Comments
 (0)