libvirt-vif: Allow to configure a script on bridge interface

While running with libvirt-xen driver, it is possible to have the Xen
toolstack running a different script than the default on a vif. This patch
allow Nova to change this script.

Also do not set script to the empty string '' in designer.py for a linux
bridge. The empty string for script does not appear to be use anywhere in
the libvirt code when the vif is a bridge.

Change-Id: Ib6d6542d22decccfa68a058d362a42d60e6c2cca
Partial-Bug: #1461642
This commit is contained in:
Anthony PERARD 2015-07-06 17:47:17 +01:00
parent ab5d3387bf
commit cd17662878
3 changed files with 19 additions and 1 deletions

View File

@ -1243,6 +1243,21 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest):
</virtualport>
</interface>""")
def test_config_bridge_xen(self):
obj = config.LibvirtConfigGuestInterface()
obj.net_type = "bridge"
obj.source_dev = "br0"
obj.mac_addr = "CA:FE:BE:EF:CA:FE"
obj.script = "/path/to/test-vif-openstack"
xml = obj.to_xml()
self.assertXmlEqual(xml, """
<interface type="bridge">
<mac address="CA:FE:BE:EF:CA:FE"/>
<source bridge="br0"/>
<script path="/path/to/test-vif-openstack"/>
</interface>""")
def test_config_8021Qbh(self):
obj = config.LibvirtConfigGuestInterface()
obj.net_type = "direct"

View File

@ -1173,6 +1173,10 @@ class LibvirtConfigGuestInterface(LibvirtConfigGuestDevice):
dev.append(etree.Element("source", type=self.vhostuser_type,
mode=self.vhostuser_mode,
path=self.vhostuser_path))
elif self.net_type == "bridge":
dev.append(etree.Element("source", bridge=self.source_dev))
if self.script is not None:
dev.append(etree.Element("script", path=self.script))
else:
dev.append(etree.Element("source", bridge=self.source_dev))

View File

@ -43,7 +43,6 @@ def set_vif_host_backend_bridge_config(conf, brname, tapname=None):
conf.source_dev = brname
if tapname:
conf.target_dev = tapname
conf.script = ""
def set_vif_host_backend_ethernet_config(conf, tapname):