[Kimchi-devel] [PATCH v4 1/3] Generate libvirt's interface XML definition for vlan tagged bridge
Aline Manera
alinefm at linux.vnet.ibm.com
Fri Jan 10 12:25:51 UTC 2014
On 01/10/2014 01:33 AM, Mark Wu wrote:
> On 01/09/2014 09:19 PM, Aline Manera wrote:
>>
>> Sorry, I wasn't clear in previous patch.
>> But you need to rebase the whole patch set.
> I thought just sending the changed patch could avoid duplicated review
> on the unchanged patch.
It is easier to track if the whole patch is sent after rebase.
> Maybe your tool depends on the whole patchset.
In fact, it does not! But the merge problem was with patch 2/3 and it
wasn't sent after rebasing.
> In gerrit, the patch is merged by cherry-pick, so
> it doesn't have problem to only update some of a series patches.
>>
>> On 01/09/2014 03:39 AM, Mark Wu wrote:
>>> To support vlan tagged virtual network, kimchi needs create the
>>> underlying
>>> vlan and bridge interface. Libvirt's interface driver can do it with
>>> a given XML definition. This patch targets to generate the XML
>>> according
>>> to the interface and vlan id.
>>>
>>> Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
>>> ---
>>> src/kimchi/networkxml.py | 19 +++++++++++++++++++
>>> tests/test_networkxml.py | 22 ++++++++++++++++++++++
>>> tests/utils.py | 6 ++++++
>>> 3 files changed, 47 insertions(+)
>>>
>>> diff --git a/src/kimchi/networkxml.py b/src/kimchi/networkxml.py
>>> index 786cb69..63cb210 100644
>>> --- a/src/kimchi/networkxml.py
>>> +++ b/src/kimchi/networkxml.py
>>> @@ -21,6 +21,10 @@
>>> # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>>> 02110-1301 USA
>>>
>>> import ipaddr
>>> +import lxml.etree as ET
>>> +
>>> +
>>> +from lxml.builder import E
>>>
>>>
>>> # FIXME, do not support ipv6
>>> @@ -109,3 +113,18 @@ def to_network_xml(**kwargs):
>>> </network>
>>> """ % params
>>> return xml
>>> +
>>> +
>>> +def create_vlan_tagged_bridge_xml(bridge, interface, vlan_id):
>>> + vlan = E.vlan(E.interface(name=interface))
>>> + vlan.set('tag', vlan_id)
>>> + m = E.interface(
>>> + E.start(mode='onboot'),
>>> + E.bridge(
>>> + E.interface(
>>> + vlan,
>>> + type='vlan',
>>> + name='.'.join([interface, vlan_id]))),
>>> + type='bridge',
>>> + name=bridge)
>>> + return ET.tostring(m)
>>> diff --git a/tests/test_networkxml.py b/tests/test_networkxml.py
>>> index 3073bce..42b3ea9 100644
>>> --- a/tests/test_networkxml.py
>>> +++ b/tests/test_networkxml.py
>>> @@ -25,6 +25,9 @@ import unittest
>>>
>>>
>>> import kimchi.networkxml as nxml
>>> +import utils
>>> +
>>> +
>>> from kimchi.xmlutils import xpath_get_text
>>>
>>>
>>> @@ -151,3 +154,22 @@ class NetworkXmlTests(unittest.TestCase):
>>> netmask = xpath_get_text(xml, "/network/ip/@netmask")[0]
>>> self.assertEquals(netmask,
>>> str(ipaddr.IPNetwork(params["net"]).netmask))
>>> +
>>> +
>>> +class InterfaceXmlTests(unittest.TestCase):
>>> +
>>> + def test_vlan_tagged_bridge_no_ip(self):
>>> + expected_xml = """
>>> + <interface type='bridge' name='br10'>
>>> + <start mode='onboot'/>
>>> + <bridge>
>>> + <interface type='vlan' name='em1.10'>
>>> + <vlan tag='10'>
>>> + <interface name='em1'/>
>>> + </vlan>
>>> + </interface>
>>> + </bridge>
>>> + </interface>
>>> + """
>>> + actual_xml = nxml.create_vlan_tagged_bridge_xml('br10',
>>> 'em1', '10')
>>> + self.assertEquals(actual_xml,
>>> utils.normalize_xml(expected_xml))
>>> diff --git a/tests/utils.py b/tests/utils.py
>>> index 008f668..79fc2e2 100644
>>> --- a/tests/utils.py
>>> +++ b/tests/utils.py
>>> @@ -32,6 +32,7 @@ import unittest
>>>
>>>
>>> from contextlib import closing
>>> +from lxml import etree
>>>
>>>
>>> import kimchi.server
>>> @@ -159,3 +160,8 @@ def patch_auth():
>>>
>>> import kimchi.auth
>>> kimchi.auth.authenticate = _authenticate
>>> +
>>> +
>>> +def normalize_xml(xml_str):
>>> + return etree.tostring(etree.fromstring(xml_str,
>>> + etree.XMLParser(remove_blank_text=True)))
>>
>
More information about the Kimchi-devel
mailing list