Improve messages on adding hosts errors (#5988)

* Improve messages on adding hosts errors

* Remove unreachable code

* Improve error logs

* Apply suggestions

* Improve error msg
This commit is contained in:
Nicolas Vazquez 2022-02-17 21:51:30 -03:00 committed by GitHub
parent f74e87fbf8
commit f96f6faf24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View File

@ -273,8 +273,11 @@ public abstract class LibvirtServerDiscoverer extends DiscovererBase implements
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "ls /dev/kvm")) {
s_logger.debug("It's not a KVM enabled machine");
return null;
String errorMsg = "This machine does not have KVM enabled.";
if (s_logger.isDebugEnabled()) {
s_logger.debug(errorMsg);
}
throw new DiscoveredWithErrorException(errorMsg);
}
if (SSHCmdHelper.sshExecuteCmd(sshConnection, "rpm -qa | grep -i ovmf", 3)) {
@ -335,9 +338,10 @@ public abstract class LibvirtServerDiscoverer extends DiscovererBase implements
setupAgentCommand = "sudo cloudstack-setup-agent ";
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, setupAgentCommand + parameters)) {
s_logger.info("cloudstack agent setup command failed: "
+ setupAgentCommand + parameters);
return null;
String errorMsg = String.format("CloudStack Agent setup through command [%s] with parameters [%s] failed.",
setupAgentCommand, parameters);
s_logger.info(errorMsg);
throw new DiscoveredWithErrorException(errorMsg);
}
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
@ -373,12 +377,14 @@ public abstract class LibvirtServerDiscoverer extends DiscovererBase implements
} catch (Exception e) {
String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage();
s_logger.warn(msg);
if (s_logger.isDebugEnabled()) {
s_logger.debug(msg, e);
}
throw new DiscoveredWithErrorException(msg, e);
} finally {
if (sshConnection != null)
sshConnection.close();
}
return null;
}
private HostVO waitForHostConnect(long dcId, long podId, long clusterId, String guid) {

View File

@ -807,9 +807,18 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
try {
resources = discoverer.find(dcId, podId, clusterId, uri, username, password, hostTags);
} catch (final DiscoveryException e) {
throw e;
String errorMsg = String.format("Could not add host at [%s] with zone [%s], pod [%s] and cluster [%s] due to: [%s].",
uri, dcId, podId, clusterId, e.getMessage());
if (s_logger.isDebugEnabled()) {
s_logger.debug(errorMsg, e);
}
throw new DiscoveryException(errorMsg, e);
} catch (final Exception e) {
s_logger.info("Exception in host discovery process with discoverer: " + discoverer.getName() + ", skip to another discoverer if there is any");
String err = "Exception in host discovery process with discoverer: " + discoverer.getName();
s_logger.info(err + ", skip to another discoverer if there is any");
if (s_logger.isDebugEnabled()) {
s_logger.debug(err + ":" + e.getMessage(), e);
}
}
processResourceEvent(ResourceListener.EVENT_DISCOVER_AFTER, resources);
@ -863,8 +872,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
s_logger.warn(msg);
throw new DiscoveryException(msg);
}
s_logger.warn("Unable to find the server resources at " + url);
throw new DiscoveryException("Unable to add the host");
String errorMsg = "Cannot find the server resources at " + url;
s_logger.warn(errorMsg);
throw new DiscoveryException("Unable to add the host: " + errorMsg);
}
@Override