Skip to content

Commit 3729511

Browse files
ustcweizhouyadvr
authored andcommitted
kvm: Fix three issues with Ubuntu 16.04 hosts (#3227)
* ubuntu16: fix unable to add host if cloudbrX is not configured 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 9c7cd8c 2017-09-19 16:45 Sigert Goeminne ● CLOUDSTACK-10081: CloudUtils getDevInfo function will now return "bridge" instead o * 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 ---------------------------------------------------- ``` * 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.
1 parent de54522 commit 3729511

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.libvirt.DomainSnapshot;
7373
import org.libvirt.LibvirtException;
7474
import org.libvirt.MemoryStatistic;
75+
import org.libvirt.Network;
7576
import org.libvirt.NodeInfo;
7677
import org.w3c.dom.Document;
7778
import org.w3c.dom.Element;
@@ -925,6 +926,20 @@ public boolean configure(final String name, final Map<String, Object> params) th
925926
throw new CloudRuntimeException(e.getMessage());
926927
}
927928

929+
// destroy default network, see https://libvirt.org/sources/java/javadoc/org/libvirt/Network.html
930+
try {
931+
Network network = conn.networkLookupByName("default");
932+
s_logger.debug("Found libvirt default network, destroying it and setting autostart to false");
933+
if (network.isActive() == 1) {
934+
network.destroy();
935+
}
936+
if (network.getAutostart()) {
937+
network.setAutostart(false);
938+
}
939+
} catch (final LibvirtException e) {
940+
s_logger.warn("Ignoring libvirt error.", e);
941+
}
942+
928943
if (HypervisorType.KVM == _hypervisorType) {
929944
/* Does node support HVM guest? If not, exit */
930945
if (!IsHVMEnabled(conn)) {

python/lib/cloudutils/networkConfig.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def isBridge(devName):
103103

104104
@staticmethod
105105
def isOvsBridge(devName):
106+
cmd = bash("which ovs-vsctl")
107+
if not cmd.isSuccess():
108+
return False
106109
try:
107110
return 0==subprocess.check_call(("ovs-vsctl", "br-exists", devName))
108111
except subprocess.CalledProcessError:

python/lib/cloudutils/serviceConfig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ def config(self):
581581

582582
self.syscfg.svo.stopService("libvirt-bin")
583583
self.syscfg.svo.enableService("libvirt-bin")
584+
if os.path.exists("/lib/systemd/system/libvirt-bin.socket"):
585+
bash("systemctl stop libvirt-bin.socket")
584586
return True
585587
except:
586588
raise

0 commit comments

Comments
 (0)