From 73fabb588deb2224bd57fab34a7919a9a061df71 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 14 Mar 2019 09:18:58 +0000 Subject: [PATCH 1/3] ubuntu16: fix unable to add host if cloudbrX is not configured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit while add a ubuntu16.04 host with native eth0 (cloudbrX is not configured), the operation failed and I got the following error in /var/log/cloudstack/agent/setup.log ``` DEBUG:root:execute:ifconfig eth0 DEBUG:root:[Errno 2] No such file or directory File "/usr/lib/python2.7/dist-packages/cloudutils/serviceConfig.py", line 38, in configration result = self.config() File "/usr/lib/python2.7/dist-packages/cloudutils/serviceConfig.py", line 211, in config super(networkConfigUbuntu, self).cfgNetwork() File "/usr/lib/python2.7/dist-packages/cloudutils/serviceConfig.py", line 108, in cfgNetwork device = self.netcfg.getDefaultNetwork() File "/usr/lib/python2.7/dist-packages/cloudutils/networkConfig.py", line 53, in getDefaultNetwork pdi = networkConfig.getDevInfo(dev) File "/usr/lib/python2.7/dist-packages/cloudutils/networkConfig.py", line 157, in getDevInfo elif networkConfig.isBridge(dev) or networkConfig.isOvsBridge(dev): ``` The issue is caused by commit 9c7cd8c2485412bc847b2c2473b962fa01435b24 2017-09-19 16:45 Sigert Goeminne ● CLOUDSTACK-10081: CloudUtils getDevInfo function will now return "bridge" instead o --- python/lib/cloudutils/networkConfig.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/lib/cloudutils/networkConfig.py b/python/lib/cloudutils/networkConfig.py index b3ae26951bab..27988433e2e9 100644 --- a/python/lib/cloudutils/networkConfig.py +++ b/python/lib/cloudutils/networkConfig.py @@ -103,6 +103,9 @@ def isBridge(devName): @staticmethod def isOvsBridge(devName): + cmd = bash("which ovs-vsctl") + if not cmd.isSuccess(): + return False try: return 0==subprocess.check_call(("ovs-vsctl", "br-exists", devName)) except subprocess.CalledProcessError: From 04a447c7e980bfbec468721508938d3306e0b870 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 14 Mar 2019 09:38:11 +0000 Subject: [PATCH 2/3] ubuntu16: Stop service libvirt-bin.socket while add a host service libvirt-bin.socket will be started when add a ubuntu 16.04 host DEBUG:root:execute:sudo /usr/sbin/service libvirt-bin start However, libvirt-bin service will be broken by it after restarting Stopping service libvirt-bin.socket will fix the issue. An example is given as below. ``` root@node32:~# /etc/init.d/libvirt-bin restart [ ok ] Restarting libvirt-bin (via systemctl): libvirt-bin.service. root@node32:~# virsh list error: failed to connect to the hypervisor error: no valid connection error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory root@node32:~# systemctl stop libvirt-bin.socket root@node32:~# /etc/init.d/libvirt-bin restart [ ok ] Restarting libvirt-bin (via systemctl): libvirt-bin.service. root@node32:~# virsh list Id Name State ---------------------------------------------------- ``` --- python/lib/cloudutils/serviceConfig.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/lib/cloudutils/serviceConfig.py b/python/lib/cloudutils/serviceConfig.py index 994c822ca017..cc7a22d5c4f2 100755 --- a/python/lib/cloudutils/serviceConfig.py +++ b/python/lib/cloudutils/serviceConfig.py @@ -581,6 +581,8 @@ def config(self): self.syscfg.svo.stopService("libvirt-bin") self.syscfg.svo.enableService("libvirt-bin") + if os.path.exists("/lib/systemd/system/libvirt-bin.socket"): + bash("systemctl stop libvirt-bin.socket") return True except: raise From fd8fff41bd6353b597ec7f1b93c7f112ee60acfc Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 14 Mar 2019 09:39:50 +0000 Subject: [PATCH 3/3] ubuntu16: Diable libvirt default network By default, libvirt will create default network virbr0 on kvm hypervisors. If vm uses the same ip range 192.168.122.0/24, there will be some issues. In some cases, if we run tcpdump inside vm, we will see the ip of kvm hypervisor as source ip. --- .../kvm/resource/LibvirtComputingResource.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index c07b2d93435b..1cdc1f0d03b8 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -72,6 +72,7 @@ import org.libvirt.DomainSnapshot; import org.libvirt.LibvirtException; import org.libvirt.MemoryStatistic; +import org.libvirt.Network; import org.libvirt.NodeInfo; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -925,6 +926,20 @@ public boolean configure(final String name, final Map params) th throw new CloudRuntimeException(e.getMessage()); } + // destroy default network, see https://libvirt.org/sources/java/javadoc/org/libvirt/Network.html + try { + Network network = conn.networkLookupByName("default"); + s_logger.debug("Found libvirt default network, destroying it and setting autostart to false"); + if (network.isActive() == 1) { + network.destroy(); + } + if (network.getAutostart()) { + network.setAutostart(false); + } + } catch (final LibvirtException e) { + s_logger.warn("Ignoring libvirt error.", e); + } + if (HypervisorType.KVM == _hypervisorType) { /* Does node support HVM guest? If not, exit */ if (!IsHVMEnabled(conn)) {