nvazquez commented on a change in pull request #3239: KVM: Fix agents dont
reconnect post maintenance
URL: https://github.com/apache/cloudstack/pull/3239#discussion_r269583052
##########
File path: server/src/com/cloud/resource/ResourceManagerImpl.java
##########
@@ -2344,45 +2345,74 @@ private boolean doCancelMaintenance(final long hostId)
{
}
}
+ handleAgentIfNotConnected(host, vms_migrating);
+
try {
resourceStateTransitTo(host,
ResourceState.Event.AdminCancelMaintenance, _nodeId);
_agentMgr.pullAgentOutMaintenance(hostId);
retryHostMaintenance.remove(hostId);
+ } catch (final NoTransitionException e) {
+ s_logger.debug("Cannot transmit host " + host.getId() + "to
Enabled state", e);
+ return false;
+ }
- // for kvm, need to log into kvm host, restart cloudstack-agent
- if ((host.getHypervisorType() == HypervisorType.KVM &&
!vms_migrating) || host.getHypervisorType() == HypervisorType.LXC) {
-
- final boolean sshToAgent =
Boolean.parseBoolean(_configDao.getValue(Config.KvmSshToAgentEnabled.key()));
- if (!sshToAgent) {
- s_logger.info("Configuration tells us not to SSH into
Agents. Please restart the Agent (" + hostId + ") manually");
- return true;
- }
+ return true;
- _hostDao.loadDetails(host);
- final String password = host.getDetail("password");
- final String username = host.getDetail("username");
- if (password == null || username == null) {
- s_logger.debug("Can't find password/username");
- return false;
- }
- final com.trilead.ssh2.Connection connection =
SSHCmdHelper.acquireAuthorizedConnection(host.getPrivateIpAddress(), 22,
username, password);
- if (connection == null) {
- s_logger.debug("Failed to connect to host: " +
host.getPrivateIpAddress());
- return false;
- }
+ }
- try {
- SSHCmdHelper.SSHCmdResult result =
SSHCmdHelper.sshExecuteCmdOneShot(connection, "service cloudstack-agent
restart");
- s_logger.debug("cloudstack-agent restart result: " +
result.toString());
- } catch (final SshException e) {
- return false;
+ /**
+ * Handle agent (if available) if its not connected before cancelling
maintenance.
+ * Agent must be connected before cancelling maintenance.
+ * If the host status is not Up:
+ * - If kvm.ssh.to.agent is true, then SSH into the host and restart the
agent.
+ * - If kvm.shh.to.agent is false, then fail cancelling maintenance
+ */
+ protected void handleAgentIfNotConnected(HostVO host, boolean
vmsMigrating) {
+ final boolean isAgentOnHost = host.getHypervisorType() ==
HypervisorType.KVM ||
+ host.getHypervisorType() == HypervisorType.LXC;
Review comment:
Great, done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services