ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject git commit: AMBARI-6934. Broken ambari-server setup on sles11sp1 (dlysnichenko)
Date Wed, 20 Aug 2014 14:18:24 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 82fdc6957 -> 53ec9ed43


AMBARI-6934. Broken ambari-server setup on sles11sp1 (dlysnichenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/53ec9ed4
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/53ec9ed4
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/53ec9ed4

Branch: refs/heads/trunk
Commit: 53ec9ed432deb53aed64db8120db283a2235ad8c
Parents: 82fdc69
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Wed Aug 20 17:16:57 2014 +0300
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Wed Aug 20 17:18:02 2014 +0300

----------------------------------------------------------------------
 .../src/main/python/ambari_commons/firewall.py  | 15 +++------
 .../src/test/python/TestAmbariServer.py         | 35 ++++++++++++++------
 2 files changed, 28 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/53ec9ed4/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 1cf69ee..b73cc0c 100644
--- a/ambari-common/src/main/python/ambari_commons/firewall.py
+++ b/ambari-common/src/main/python/ambari_commons/firewall.py
@@ -101,19 +101,12 @@ class UbuntuFirewallChecks(FirewallChecks):
         result = True
     return result
 
-  def get_running_result(self):
-    # To support test code.  Expected ouput from run_os_command.
-    return (0, "ufw start/running", "")
-
-  def get_stopped_result(self):
-    # To support test code.  Expected output from run_os_command.
-    return (0, "ufw stop/waiting", "")
-
-
 class Fedora18FirewallChecks(FirewallChecks):
+  def __init__(self):
+    super(Fedora18FirewallChecks, self).__init__()
 
   def get_command(self):
-    return "systemctl is-active iptables"
+    return "systemctl is-active %s" % (self.FIREWALL_SERVICE_NAME)
 
   def check_result(self, retcode, out, err):
     result = False
@@ -124,8 +117,8 @@ class Fedora18FirewallChecks(FirewallChecks):
 
 class SuseFirewallChecks(FirewallChecks):
   def __init__(self):
+    super(SuseFirewallChecks, self).__init__()
     self.FIREWALL_SERVICE_NAME = "SuSEfirewall2"
-    self.SERVICE_SUBCMD = "status"
 
   def get_command(self):
     return "%s %s" % (self.FIREWALL_SERVICE_NAME, self.SERVICE_SUBCMD)

http://git-wip-us.apache.org/repos/asf/ambari/blob/53ec9ed4/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 46078ac..ad80b1e 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -1005,54 +1005,67 @@ class TestAmbariServer(TestCase):
     ambari_server.store_password_file("password", "passfile")
     self.assertTrue(set_file_permissions_mock.called)
 
-
-  @patch.object(FirewallChecks, "run_os_command")
+  @patch("subprocess.Popen")
   @patch.object(OSCheck, "get_os_family")
   @patch.object(OSCheck, "get_os_type")
   @patch.object(OSCheck, "get_os_major_version")
-  def test_check_iptables_is_running(self, get_os_major_version_mock, get_os_type_mock, get_os_family_mock,
run_os_command_mock):
+  def test_check_iptables_is_running(self, get_os_major_version_mock, get_os_type_mock, get_os_family_mock,
popen_mock):
 
     get_os_major_version_mock.return_value = 18
     get_os_type_mock.return_value = OSConst.OS_FEDORA
     get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
 
     firewall_obj = Firewall().getFirewallObject()
-    run_os_command_mock.return_value = 0, "active", ""
+    p = MagicMock()
+    p.communicate.return_value = ("active", "err")
+    p.returncode = 0
+    popen_mock.return_value = p
     self.assertEqual("Fedora18FirewallChecks", firewall_obj.__class__.__name__)
     self.assertTrue(firewall_obj.check_iptables())
-    run_os_command_mock.return_value = 3, "", ""
+    p.communicate.return_value = ("", "err")
+    p.returncode = 3
     self.assertFalse(firewall_obj.check_iptables())
+    self.assertEqual("err", firewall_obj.stderrdata)
 
 
     get_os_type_mock.return_value = OSConst.OS_UBUNTU
     get_os_family_mock.return_value = OSConst.DEBIAN_FAMILY
 
     firewall_obj = Firewall().getFirewallObject()
-    run_os_command_mock.return_value = 0, "Status: active", ""
+    p.communicate.return_value = ("Status: active", "err")
+    p.returncode = 0
     self.assertEqual("UbuntuFirewallChecks", firewall_obj.__class__.__name__)
     self.assertTrue(firewall_obj.check_iptables())
-    run_os_command_mock.return_value = 0, "Status: inactive", ""
+    p.communicate.return_value = ("Status: inactive", "err")
+    p.returncode = 0
     self.assertFalse(firewall_obj.check_iptables())
+    self.assertEqual("err", firewall_obj.stderrdata)
 
     get_os_type_mock.return_value = ""
     get_os_family_mock.return_value = OSConst.SUSE_FAMILY
 
     firewall_obj = Firewall().getFirewallObject()
-    run_os_command_mock.return_value = 0, "### iptables", ""
+    p.communicate.return_value = ("### iptables", "err")
+    p.returncode = 0
     self.assertEqual("SuseFirewallChecks", firewall_obj.__class__.__name__)
     self.assertTrue(firewall_obj.check_iptables())
-    run_os_command_mock.return_value = 0, "SuSEfirewall2 not active", ""
+    p.communicate.return_value = ("SuSEfirewall2 not active", "err")
+    p.returncode = 0
     self.assertFalse(firewall_obj.check_iptables())
+    self.assertEqual("err", firewall_obj.stderrdata)
 
     get_os_type_mock.return_value = ""
     get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
 
     firewall_obj = Firewall().getFirewallObject()
-    run_os_command_mock.return_value = 0, "Table: filter", ""
+    p.communicate.return_value = ("Table: filter", "err")
+    p.returncode = 0
     self.assertEqual("FirewallChecks", firewall_obj.__class__.__name__)
     self.assertTrue(firewall_obj.check_iptables())
-    run_os_command_mock.return_value = 3, "", ""
+    p.communicate.return_value = ("", "err")
+    p.returncode = 3
     self.assertFalse(firewall_obj.check_iptables())
+    self.assertEqual("err", firewall_obj.stderrdata)
 
 
   def test_dlprogress(self):


Mime
View raw message