Skip to content

Commit 792f835

Browse files
KVM: revert libvirtd config and retry if fail to add a host (#7090)
1 parent fe0e44a commit 792f835

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

scripts/util/keystore-setup

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ KS_VALIDITY="$4"
2323
CSR_FILE="$5"
2424

2525
ALIAS="cloud"
26+
LIBVIRTD_FILE="/etc/libvirt/libvirtd.conf"
2627

2728
# Re-use existing password or use the one provided
2829
if [ -f "$PROPS_FILE" ]; then
@@ -46,6 +47,27 @@ keytool -genkey -storepass "$KS_PASS" -keypass "$KS_PASS" -alias "$ALIAS" -keyal
4647
rm -f "$CSR_FILE"
4748
addresses=$(ip address | grep inet | awk '{print $2}' | sed 's/\/.*//g' | grep -v '^169.254.' | grep -v '^127.0.0.1' | egrep -v '^::1|^fe80' | grep -v '^::1' | sed 's/^/ip:/g' | tr '\r\n' ',')
4849
keytool -certreq -storepass "$KS_PASS" -alias "$ALIAS" -file $CSR_FILE -keystore "$KS_FILE" -ext san="$addresses" > /dev/null 2>&1
50+
51+
if [ $? -ne 0 ];then
52+
echo "Failed to generate CSR file, retrying after removing existing settings"
53+
54+
if [ -f "$LIBVIRTD_FILE" ]; then
55+
echo "Reverting libvirtd to not listen on TLS"
56+
sed -i "s,^listen_tls=1,listen_tls=0,g" $LIBVIRTD_FILE
57+
systemctl restart libvirtd
58+
fi
59+
60+
echo "Removing cloud.* files in /etc/cloudstack/agent"
61+
rm -f /etc/cloudstack/agent/cloud.*
62+
63+
echo "Retrying to generate CSR file"
64+
keytool -certreq -storepass "$KS_PASS" -alias "$ALIAS" -file $CSR_FILE -keystore "$KS_FILE" -ext san="$addresses" >/dev/null 2>&1
65+
if [ $? -ne 0 ];then
66+
echo "Failed to generate CSR file while retrying"
67+
exit 1
68+
fi
69+
fi
70+
4971
cat "$CSR_FILE"
5072

5173
# Fix file permissions

server/src/main/java/com/cloud/hypervisor/kvm/discoverer/LibvirtServerDiscoverer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ private void setupAgentSecurity(final Connection sshConnection, final String age
260260

261261
final String privateKey = _configDao.getValue("ssh.privatekey");
262262
if (!SSHCmdHelper.acquireAuthorizedConnectionWithPublicKey(sshConnection, username, privateKey)) {
263-
s_logger.error("Failed to authenticate with ssh key");
264263
if (org.apache.commons.lang3.StringUtils.isEmpty(password)) {
264+
s_logger.error("Failed to authenticate with ssh key");
265265
throw new DiscoveredWithErrorException("Authentication error with ssh private key");
266266
}
267+
s_logger.info("Failed to authenticate with ssh key, retrying with password");
267268
if (!sshConnection.authenticateWithPassword(username, password)) {
268269
s_logger.error("Failed to authenticate with password");
269270
throw new DiscoveredWithErrorException("Authentication error with host password");

0 commit comments

Comments
 (0)