You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ds...@apache.org on 2016/04/26 16:56:36 UTC
ambari git commit: AMBARI-14103 Incorrect firewall check on CentOS7
while adding new host to cluster (dsen)
Repository: ambari
Updated Branches:
refs/heads/trunk 2e2588efc -> 8add212b3
AMBARI-14103 Incorrect firewall check on CentOS7 while adding new host to cluster (dsen)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8add212b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8add212b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8add212b
Branch: refs/heads/trunk
Commit: 8add212b39500c2e38f389bf59ed427acce7c5ce
Parents: 2e2588e
Author: Dmytro Sen <ds...@apache.org>
Authored: Tue Apr 26 17:56:01 2016 +0300
Committer: Dmytro Sen <ds...@apache.org>
Committed: Tue Apr 26 17:56:22 2016 +0300
----------------------------------------------------------------------
.../src/main/python/ambari_commons/firewall.py | 23 +++++++++++++++++++-
.../src/test/python/TestAmbariServer.py | 14 ++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/8add212b/ambari-common/src/main/python/ambari_commons/firewall.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/firewall.py b/ambari-common/src/main/python/ambari_commons/firewall.py
index e077799..72e6d26 100644
--- a/ambari-common/src/main/python/ambari_commons/firewall.py
+++ b/ambari-common/src/main/python/ambari_commons/firewall.py
@@ -21,7 +21,7 @@ limitations under the License.
from ambari_commons import OSCheck, OSConst
from ambari_commons.logging_utils import print_warning_msg
from ambari_commons.os_family_impl import OsFamilyImpl
-from ambari_commons.os_utils import run_os_command
+from ambari_commons.os_utils import run_os_command, run_in_shell
class Firewall(object):
@@ -46,6 +46,8 @@ class FirewallLinux(Firewall):
return UbuntuFirewallChecks()
elif self.OS_TYPE == OSConst.OS_FEDORA and int(self.OS_VERSION) >= 18:
return Fedora18FirewallChecks()
+ elif OSCheck.is_redhat_family() and int(self.OS_VERSION) >= 7:
+ return RedHat7FirewallChecks()
elif OSCheck.is_suse_family():
return SuseFirewallChecks()
else:
@@ -110,6 +112,25 @@ class UbuntuFirewallChecks(FirewallChecks):
result = True
return result
+class RedHat7FirewallChecks(FirewallChecks):
+ def __init__(self):
+ super(RedHat7FirewallChecks, self).__init__()
+ self.SERVICE_CMD = "systemctl"
+
+ #firewalld added to support default firewall (started from RHEL7/CentOS7)
+ #script default iptables checked as user can use iptables as known from previous RHEL releases.
+ def get_command(self):
+ return "%(servcmd)s is-active %(fwl1)s || %(servcmd)s is-active %(fwl2)s" % {"servcmd":self.SERVICE_CMD,"fwl1":"iptables", "fwl2":"firewalld"}
+
+ def check_result(self):
+ return self.returncode == 0
+
+ def run_command(self):
+ retcode, out, err = run_in_shell(self.get_command())
+ self.returncode = retcode
+ self.stdoutdata = out
+ self.stderrdata = err
+
class Fedora18FirewallChecks(FirewallChecks):
def __init__(self):
super(Fedora18FirewallChecks, self).__init__()
http://git-wip-us.apache.org/repos/asf/ambari/blob/8add212b/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index e96a7bd..9f17e91 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -1917,6 +1917,7 @@ class TestAmbariServer(TestCase):
get_os_type_mock.return_value = ""
get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
+ get_os_major_version_mock.return_value = 6
firewall_obj = Firewall().getFirewallObject()
p.communicate.return_value = ("Table: filter", "err")
@@ -1927,6 +1928,19 @@ class TestAmbariServer(TestCase):
p.returncode = 3
self.assertFalse(firewall_obj.check_firewall())
self.assertEqual("err", firewall_obj.stderrdata)
+
+ get_os_major_version_mock.return_value = 7
+ get_os_type_mock.return_value = ""
+ get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
+
+ firewall_obj = Firewall().getFirewallObject()
+ p.returncode = 0
+ self.assertEqual("RedHat7FirewallChecks", firewall_obj.__class__.__name__)
+ self.assertTrue(firewall_obj.check_firewall())
+ p.returncode = 3
+ self.assertFalse(firewall_obj.check_firewall())
+ self.assertEqual("err", firewall_obj.stderrdata)
+
pass
@patch("ambari_server.setupHttps.get_validated_filepath_input")