Skip to content

Commit

Permalink
fix(snapshot): give offline cause on snapshot revert to avoid NPE
Browse files Browse the repository at this point in the history
related to #JENKINS-23205
  • Loading branch information
menski authored and g-k-r committed Jul 25, 2015
1 parent b9599f5 commit 34c70fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -7,6 +7,7 @@
import hudson.plugins.libvirt.lib.IDomainSnapshot;
import hudson.plugins.libvirt.lib.VirtException;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.OfflineCause;

import java.io.IOException;
import java.util.Map;
Expand Down Expand Up @@ -82,7 +83,7 @@ private static void revertVMSnapshot(VirtualMachineSlave slave, String snapshotN
computer.getChannel().syncLocalIO();
try {
computer.getChannel().close();
computer.disconnect(null);
computer.disconnect(new OfflineCause.ByCLI("Stopping " + vmName + " to revert to snapshot " + snapshotName + "."));
try {
computer.waitUntilOffline();

Expand Down
Expand Up @@ -56,7 +56,11 @@ public Future<?> disconnect(OfflineCause cause) {
String virtualMachineName = slave.getVirtualMachineName();
VirtualMachineLauncher vmL = (VirtualMachineLauncher) getLauncher();
Hypervisor hypervisor = vmL.findOurHypervisorInstance();
logger.log(Level.INFO, "Virtual machine \"" + virtualMachineName + "\" (slave \"" + getDisplayName() + "\") is to be shut down. reason: "+cause+" ("+cause.getClass().getName()+")");
String reason = "";
if (cause != null) {
reason = "reason: "+cause+" ("+cause.getClass().getName()+")";
}
logger.log(Level.INFO, "Virtual machine \"" + virtualMachineName + "\" (slave \"" + getDisplayName() + "\") is to be shut down." + reason);
taskListener.getLogger().println("Virtual machine \"" + virtualMachineName + "\" (slave \"" + getDisplayName() + "\") is to be shut down.");
try {
Map<String, IDomain> computers = hypervisor.getDomains();
Expand Down

0 comments on commit 34c70fd

Please sign in to comment.