[pykickstart][PATCH] Add --remove-service option for the firewall command (#957809)
Martin Kolman
mkolman at redhat.com
Fri Oct 4 16:07:04 UTC 2013
The --remove-service option makes it possible to remove services
that were enabled on the firewall.
Signed-off-by: Martin Kolman <mkolman at redhat.com>
---
pykickstart/commands/firewall.py | 42 ++++++++++++++++++++++++++++++++++++++++
pykickstart/handlers/control.py | 2 +-
tests/commands/firewall.py | 10 ++++++++++
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/pykickstart/commands/firewall.py b/pykickstart/commands/firewall.py
index 664bea6..1384d63 100644
--- a/pykickstart/commands/firewall.py
+++ b/pykickstart/commands/firewall.py
@@ -191,3 +191,45 @@ class F14_Firewall(F10_Firewall):
op = F10_Firewall._getParser(self)
op.remove_option("--telnet")
return op
+
+class F20_Firewall(F14_Firewall):
+ removedKeywords = F14_Firewall.removedKeywords
+ removedAttrs = F14_Firewall.removedAttrs
+
+ def _getParser(self):
+ def remove_service_cb(option, opt_str, value, parser):
+ # python2.4 does not support action="append_const" that we were
+ # using for these options. Instead, we have to fake it by
+ # appending whatever the option string is to the service list.
+ # XXX: is this still relevant ?
+ if not value:
+ parser.values.ensure_value(option.dest, []).append(opt_str[2:])
+ return
+
+ for p in value.split(","):
+ p = p.strip()
+ parser.values.ensure_value(option.dest, []).append(p)
+
+ op = F14_Firewall._getParser(self)
+ op.add_option("--remove-service", dest="remove_services",
+ action="callback", callback=remove_service_cb,
+ nargs=1, type="string")
+ return op
+
+ def __str__(self):
+ if self.enabled is None:
+ return ""
+
+ retval = F10_Firewall.__str__(self)
+ if self.enabled:
+ retval = retval.strip()
+
+ svcstr = ",".join(self.remove_services)
+ if len(svcstr) > 0:
+ svcstr = " --remove-service=" + svcstr
+ else:
+ svcstr = ""
+
+ return retval + "%s\n" % svcstr
+ else:
+ return retval
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index 83dece0..987158c 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -1040,7 +1040,7 @@ commandMap = {
"driverdisk": driverdisk.F14_DriverDisk,
"eula": eula.F20_Eula,
"fcoe": fcoe.F13_Fcoe,
- "firewall": firewall.F14_Firewall,
+ "firewall": firewall.F20_Firewall,
"firstboot": firstboot.FC3_Firstboot,
"graphical": displaymode.FC3_DisplayMode,
"group": group.F12_Group,
diff --git a/tests/commands/firewall.py b/tests/commands/firewall.py
index 392684e..bfe7426 100644
--- a/tests/commands/firewall.py
+++ b/tests/commands/firewall.py
@@ -43,6 +43,16 @@ class FC3_TestCase(CommandTest):
self.assert_parse("firewall --enable --trust=eth0,eth1 --ssh --http --smtp --ftp --port=1234:udp"
"firewall --enabled --port=1234:udp --trust=eth0,eth1 --service=ssh,http,smtp,ftp\n")
+ # remove service
+ if "--remove-service" in self.optionList:
+ self.assert_parse("firewall --remove-service=mdns") # remove only
+ # service & remove service at once
+ self.assert_parse("firewall --service=ssh --remove-service=mdns")
+ # with alternative service notation
+ self.assert_parse("firewall --ssh --smtp --ftp --remove-service=mdns")
+ # multiple remove & remove ssh
+ self.assert_parse("firewall --service=mdns --remove-service=dhcpv6-client --remove-service=ssh")
+
# disable firewall
self.assert_parse("firewall --disabled", "firewall --disabled\n")
self.assert_parse("firewall --disable", "firewall --disabled\n")
--
1.8.3.1
More information about the anaconda-patches
mailing list