[PATCH rhel7-branch pykickstart] network: add support for bridge (#1075195)

Radek Vykydal rvykydal at redhat.com
Thu Sep 25 11:30:36 UTC 2014


Related: rhbz#1075195
---
 pykickstart/commands/network.py | 27 +++++++++++++++++++++++++++
 tests/commands/network.py       | 26 ++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/pykickstart/commands/network.py b/pykickstart/commands/network.py
index 7b1341c..4b14846 100644
--- a/pykickstart/commands/network.py
+++ b/pykickstart/commands/network.py
@@ -270,11 +270,17 @@ class RHEL7_NetworkData(F20_NetworkData):
     def __init__(self, *args, **kwargs):
         F20_NetworkData.__init__(self, *args, **kwargs)
         self.interfacename = kwargs.get("interfacename", "")
+        self.bridgeslaves = kwargs.get("bridgeslaves", "")
+        self.bridgeopts = kwargs.get("bridgeopts", "")
 
     def _getArgsAsStr(self):
         retval = F20_NetworkData._getArgsAsStr(self)
         if self.interfacename:
             retval += " --interfacename=%s" % self.interfacename
+        if self.bridgeslaves != "":
+            retval += " --bridgeslaves=%s" % self.bridgeslaves
+        if self.bridgeopts != "":
+            retval += " --bridgeopts=%s" % self.bridgeopts
 
         return retval
 
@@ -522,4 +528,25 @@ class RHEL7_Network(F20_Network):
         op = F20_Network._getParser(self)
         op.add_option("--interfacename", dest="interfacename", action="store",
                 default="")
+        op.add_option("--bridgeslaves", dest="bridgeslaves", action="store",
+                default="")
+        op.add_option("--bridgeopts", dest="bridgeopts", action="store",
+                default="")
         return op
+
+    def parse(self, args):
+        retval = F20_Network.parse(self, args)
+
+        if retval.bridgeopts:
+            if not retval.bridgeslaves:
+                msg = formatErrorMsg(self.lineno, msg=_("Option --bridgeopts requires"\
+                                        "--bridgeslaves to be specified"))
+                raise KickstartValueError(msg)
+            opts = retval.bridgeopts.split(",")
+            for opt in opts:
+                key, _sep, value = opt.partition("=")
+                if not value or "=" in value:
+                    msg = formatErrorMsg(self.lineno, msg=_("Bad format of --bridgeopts, expecting key=value options separated by ','"))
+                    raise KickstartValueError(msg)
+
+        return retval
diff --git a/tests/commands/network.py b/tests/commands/network.py
index 9643c74..f5c73d5 100644
--- a/tests/commands/network.py
+++ b/tests/commands/network.py
@@ -69,5 +69,31 @@ class F20_TestCase(CommandTest):
             nd2 = self.assert_parse(s)
             self.assertEquals(value, nd2.teamslaves)
 
+class RHEL7_TestCase(F20_TestCase):
+    def runTest(self):
+        F20_TestCase.runTest(self)
+
+        # bridge options
+        # pass
+        self.assert_parse("network --device team0 --bootproto dhcp "\
+                          "--bridgeslaves=ens3,ens7 "\
+                          "--bridgeopts=priority=40000")
+        self.assert_parse("network --device team0 --bootproto dhcp "\
+                          "--bridgeslaves=ens3,ens7 "\
+                          "--bridgeopts=priority=40000,hello-time=3")
+
+        # fail
+        # slaves missing
+        self.assert-parse_error("network --device team0 --bootproto dhcp "\
+                                "--bridgeopts=priority=40000")
+        # bad options format
+        self.assert_parse_error("network --device team0 --bootproto dhcp "\
+                                "--bridgeslaves=ens3,ens7 "\
+                                '--bridgeopts="priority=40000 hello-time=3"')
+        self.assert_parse_error("network --device team0 --bootproto dhcp "\
+                                "--bridgeslaves=ens3,ens7 "\
+                                "--bridgeopts=priority")
+
+
 if __name__ == "__main__":
     unittest.main()
-- 
1.9.3



More information about the anaconda-patches mailing list