From 1f6f3b72dbeeb0ef012227f6a4d1d566e0b16015 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Tue, 13 Sep 2016 07:57:10 +1000 Subject: [PATCH] firewalld should fail nicely when service is stopped (#2871) Ensure the HAVE_FIREWALLD checks check only for the presence of the python dependencies, and not the age of the library or the state of the service, which are checked later. --- system/firewalld.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/system/firewalld.py b/system/firewalld.py index b5406f63ec8..eefaa45dd98 100644 --- a/system/firewalld.py +++ b/system/firewalld.py @@ -114,10 +114,7 @@ try: from firewall.client import Rich_Rule from firewall.client import FirewallClient fw = FirewallClient() - if not fw.connected: - HAS_FIREWALLD = False - else: - HAS_FIREWALLD = True + HAS_FIREWALLD = True except ImportError: HAS_FIREWALLD = False @@ -359,6 +356,13 @@ def main(): ## Pre-run version checking if FW_VERSION < "0.2.11": module.fail_json(msg='unsupported version of firewalld, requires >= 2.0.11') + ## Check for firewalld running + try: + if fw.connected == False: + module.fail_json(msg='firewalld service must be running') + except AttributeError: + module.fail_json(msg="firewalld connection can't be established,\ + installed version (%s) likely too old. Requires firewalld >= 2.0.11" % FW_VERSION) ## Global Vars changed=False @@ -386,14 +390,6 @@ def main(): interface = module.params['interface'] masquerade = module.params['masquerade'] - ## Check for firewalld running - try: - if fw.connected == False: - module.fail_json(msg='firewalld service must be running') - except AttributeError: - module.fail_json(msg="firewalld connection can't be established,\ - version likely too old. Requires firewalld >= 2.0.11") - modification_count = 0 if service != None: modification_count += 1