From 9aab70deff8353671116e75e2cd31f4c5c136841 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Wed, 6 Oct 2021 11:23:39 +0200 Subject: [PATCH] VR: skip dhcp/dns health check in some cases this fixes #5536 --- .../VirtualNetworkApplianceManagerImpl.java | 8 +++++++- systemvm/debian/root/health_checks/dhcp_check.py | 15 +++++++++++---- systemvm/debian/root/health_checks/dns_check.py | 6 +++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 893ac58fba83..8e4fa4b4c0e3 100644 --- a/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -168,6 +168,7 @@ import com.cloud.network.dao.MonitoringServiceDao; import com.cloud.network.dao.MonitoringServiceVO; import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkServiceMapDao; import com.cloud.network.dao.NetworkVO; import com.cloud.network.dao.OpRouterMonitorServiceDao; import com.cloud.network.dao.OpRouterMonitorServiceVO; @@ -349,6 +350,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V @Inject private ApplicationLoadBalancerRuleDao applicationLoadBalancerRuleDao; @Inject private RouterHealthCheckResultDao routerHealthCheckResultDao; @Inject private LBStickinessPolicyDao lbStickinessPolicyDao; + @Inject private NetworkServiceMapDao _ntwkSrvcDao; @Inject private NetworkService networkService; @Inject private VpcService vpcService; @@ -1775,6 +1777,8 @@ private Map getRouterHealthChecksConfig(final DomainRouterVO rou SearchCriteria scvm = sbvm.create(); scvm.setParameters("networkId", routerJoinVO.getNetworkId()); List vms = userVmJoinDao.search(scvm, null); + boolean isDhcpSupported = _ntwkSrvcDao.areServicesSupportedInNetwork(routerJoinVO.getNetworkId(), Service.Dhcp); + boolean isDnsSupported = _ntwkSrvcDao.areServicesSupportedInNetwork(routerJoinVO.getNetworkId(), Service.Dns); for (UserVmJoinVO vm : vms) { if (vm.getState() != VirtualMachine.State.Running) { continue; @@ -1782,7 +1786,9 @@ private Map getRouterHealthChecksConfig(final DomainRouterVO rou vmsData.append("vmName=").append(vm.getName()) .append(",macAddress=").append(vm.getMacAddress()) - .append(",ip=").append(vm.getIpAddress()).append(";"); + .append(",ip=").append(vm.getIpAddress()) + .append(",dhcp=").append(isDhcpSupported) + .append(",dns=").append(isDnsSupported).append(";"); updateWithPortForwardingRules(routerJoinVO, vm, portData); } updateWithLbRules(routerJoinVO, loadBalancingData); diff --git a/systemvm/debian/root/health_checks/dhcp_check.py b/systemvm/debian/root/health_checks/dhcp_check.py index be7a8407e395..2618ee57cea5 100755 --- a/systemvm/debian/root/health_checks/dhcp_check.py +++ b/systemvm/debian/root/health_checks/dhcp_check.py @@ -27,13 +27,20 @@ def main(): print "No VMs running data available, skipping" exit(0) - with open('/etc/dhcphosts.txt', 'r') as hostsFile: - allHosts = hostsFile.readlines() - hostsFile.close() + try: + with open('/etc/dhcphosts.txt', 'r') as hostsFile: + allHosts = hostsFile.readlines() + hostsFile.close() + except IOError: + allHosts = [] failedCheck = False failureMessage = "Missing elements in dhcphosts.txt - \n" + COUNT = 0 for vM in vMs: + if vM["dhcp"] == "false": + continue + COUNT = COUNT + 1 entry = vM["macAddress"] + " " + vM["ip"] + " " + vM["vmName"] foundEntry = False for host in allHosts: @@ -60,7 +67,7 @@ def main(): print failureMessage[:-2] exit(1) else: - print "All " + str(len(vMs)) + " VMs are present in dhcphosts.txt" + print "All " + str(COUNT) + " VMs are present in dhcphosts.txt" exit(0) diff --git a/systemvm/debian/root/health_checks/dns_check.py b/systemvm/debian/root/health_checks/dns_check.py index c17788812330..d4fbc129d518 100644 --- a/systemvm/debian/root/health_checks/dns_check.py +++ b/systemvm/debian/root/health_checks/dns_check.py @@ -33,7 +33,11 @@ def main(): failedCheck = False failureMessage = "Missing entries for VMs in /etc/hosts -\n" + COUNT = 0 for vM in vMs: + if vM["dns"] == "false": + continue + COUNT = COUNT + 1 foundEntry = False for host in allHosts: components = host.split('\t') @@ -50,7 +54,7 @@ def main(): print failureMessage[:-2] exit(1) else: - print "All " + str(len(vMs)) + " VMs are present in /etc/hosts" + print "All " + str(COUNT) + " VMs are present in /etc/hosts" exit(0)