[Kimchi-devel] [PATCH v3] [Kimchi 2/3] Passthrough macvtap network support: model and test changes

dhbarboza82 at gmail.com dhbarboza82 at gmail.com
Thu May 19 15:31:07 UTC 2016


From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>

Adding support for the new network type 'passthrough'. The
way it is supported in model and XML files is similar to what
we already do in the VEPA network.

New unit tests included.

Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
---
 model/networks.py        | 15 +++++++++------
 tests/test_networkxml.py | 42 ++++++++++++++++++++++++++++++++++++++++++
 xmlutils/network.py      |  2 +-
 3 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/model/networks.py b/model/networks.py
index cc59ca8..e04c8e4 100644
--- a/model/networks.py
+++ b/model/networks.py
@@ -102,8 +102,8 @@ class NetworksModel(object):
                 self._set_network_macvtap(params)
             elif connection == 'bridge':
                 self._set_network_bridge(params)
-            elif connection == 'vepa':
-                self._set_network_vepa(params)
+            elif connection in ['passthrough', 'vepa']:
+                self._set_network_multiple_interfaces(params)
 
         # create network XML
         xml = to_network_xml(**params)
@@ -194,13 +194,16 @@ class NetworksModel(object):
         # set macvtap network
         params['forward'] = {'mode': 'bridge', 'dev': iface}
 
-    def _set_network_vepa(self, params):
+    def _set_network_multiple_interfaces(self, params):
         for iface in params['interfaces']:
             if ('vlan_id' in params or not (netinfo.is_bare_nic(iface) or
                netinfo.is_bonding(iface))):
                 raise InvalidParameter('KCHNET0028E', {'name': iface})
 
-        params['forward'] = {'mode': 'vepa', 'devs': params['interfaces']}
+        params['forward'] = {
+            'mode': params["connection"],
+            'devs': params['interfaces']
+        }
 
     def _set_network_bridge(self, params):
         params['forward'] = {'mode': 'bridge'}
@@ -369,7 +372,7 @@ class NetworkModel(object):
             subnet = ipaddr.IPNetwork(subnet)
             subnet = "%s/%s" % (subnet.network, subnet.prefixlen)
 
-        if connection == 'vepa':
+        if connection in ['passthrough', 'vepa']:
             interfaces = xpath_get_text(
                 xml,
                 "/network/forward/interface/@dev"
@@ -509,7 +512,7 @@ class NetworkModel(object):
 
         # validate update parameters
         connection = info['connection']
-        if connection in ['bridge', 'macvtap', 'vepa']:
+        if connection in ['bridge', 'macvtap', 'passthrough', 'vepa']:
             if params.get('subnet'):
                 raise InvalidParameter("KCHNET0031E")
         elif connection in ['nat', 'isolated']:
diff --git a/tests/test_networkxml.py b/tests/test_networkxml.py
index 8e83744..a39cd61 100644
--- a/tests/test_networkxml.py
+++ b/tests/test_networkxml.py
@@ -195,6 +195,48 @@ class NetworkXmlTests(unittest.TestCase):
         xml_str = nxml.to_network_xml(**params)
         self.assertEqual(xml_str, expected_xml)
 
+    def test_passthrough_network_singledev_xml(self):
+        expected_xml = """<network>\
+<name>test_passthrough</name>\
+<forward mode="passthrough" dev="passthrough_interface">\
+<interface dev="passthrough_interface"/>\
+</forward>\
+</network>"""
+
+        params = {
+            "name": "test_passthrough",
+            "forward": {
+                "mode": "passthrough",
+                "devs": ["passthrough_interface"]
+            }
+        }
+        xml_str = nxml.to_network_xml(**params)
+        self.assertEqual(xml_str, expected_xml)
+
+    def test_passthrough_network_multipledevs_xml(self):
+        expected_xml = """<network>\
+<name>test_passthrough</name>\
+<forward mode="passthrough" dev="passthrough_interface1">\
+<interface dev="passthrough_interface1"/>\
+<interface dev="passthrough_interface2"/>\
+<interface dev="passthrough_interface3"/>\
+</forward>\
+</network>"""
+
+        params = {
+            "name": "test_passthrough",
+            "forward": {
+                "mode": "passthrough",
+                "devs": [
+                    "passthrough_interface1",
+                    "passthrough_interface2",
+                    "passthrough_interface3"
+                ]
+            }
+        }
+        xml_str = nxml.to_network_xml(**params)
+        self.assertEqual(xml_str, expected_xml)
+
 
 class InterfaceXmlTests(unittest.TestCase):
 
diff --git a/xmlutils/network.py b/xmlutils/network.py
index b35f65a..2e2966b 100644
--- a/xmlutils/network.py
+++ b/xmlutils/network.py
@@ -79,7 +79,7 @@ def _get_forward_elem(**kwargs):
     forward = E.forward()
     if 'mode' in kwargs.keys():
         forward.set('mode', kwargs['mode'])
-        if kwargs['mode'] == 'vepa':
+        if kwargs['mode'] in ['passthrough', 'vepa']:
             devs = kwargs['devs']
             forward.set('dev', devs[0])
 
-- 
2.5.5




More information about the Kimchi-devel mailing list