Browse Source

AMBARI-5194. mprove User Experience during install - iptables warning. (Scott Creeley via mahadev)

Mahadev Konar 11 năm trước cách đây
mục cha
commit
02bea739bc

+ 7 - 5
ambari-agent/src/main/python/ambari_agent/HostInfo.py

@@ -126,6 +126,7 @@ class HostInfo:
     self.packages = PackagesAnalyzer()
     self.reportFileHandler = HostCheckReportFileHandler(config)
 
+
   def dirType(self, path):
     if not os.path.exists(path):
       return 'not_exist'
@@ -280,18 +281,19 @@ class HostInfo:
 
 
   def checkIptables(self):
-    iptablesIsRunning = False
+    iptablesIsRunning = True
     try:
-      iptables = subprocess.Popen(self.FIREWALL_STATUS_CMD.split(), stdout=subprocess.PIPE)
-      iptables.communicate()
-      if iptables.returncode == 0:
-        iptablesIsRunning = True
+      iptables = subprocess.Popen(["iptables", "-S"], stdout=subprocess.PIPE)
+      stdout = iptables.communicate()
+      if stdout == ('-P INPUT ACCEPT\n-P FORWARD ACCEPT\n-P OUTPUT ACCEPT\n', None):
+        iptablesIsRunning = False
     except:
       pass
     return iptablesIsRunning
 
 
 
+
   """ Return various details about the host
   componentsMapped: indicates if any components are mapped to this host
   commandsInProgress: indicates if any commands are in progress

+ 4 - 5
ambari-agent/src/test/python/ambari_agent/TestHostInfo.py

@@ -515,16 +515,15 @@ class TestHostInfo(TestCase):
   def test_checkIptables(self, subproc_popen_mock):
     hostInfo = HostInfo()
     p = MagicMock()
-    p.returncode = 0
+
     subproc_popen_mock.return_value = p
+    
     result = hostInfo.checkIptables()
+    self.assertTrue(result == True)
 
-    self.assertTrue(result)
-
-    p.returncode = 1
     result = hostInfo.checkIptables()
+    self.assertFalse(result == False)
 
-    self.assertFalse(result)
 
 
 if __name__ == "__main__":