You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2014/05/23 16:26:31 UTC
git commit: AMBARI-5869. Confirm Hosts failed (suse11,
1.6.1) (dlysnichenko)
Repository: ambari
Updated Branches:
refs/heads/trunk 30d91582f -> 2b235e353
AMBARI-5869. Confirm Hosts failed (suse11, 1.6.1) (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2b235e35
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2b235e35
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2b235e35
Branch: refs/heads/trunk
Commit: 2b235e35398069634f066462eacad2968c2c4908
Parents: 30d9158
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri May 23 17:25:27 2014 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri May 23 17:25:27 2014 +0300
----------------------------------------------------------------------
.../src/main/python/ambari_agent/HostInfo.py | 32 +++++++++++---------
.../test/python/ambari_agent/TestHostInfo.py | 28 +++++++++++++++--
2 files changed, 43 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/2b235e35/ambari-agent/src/main/python/ambari_agent/HostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/HostInfo.py b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
index 64e9cb9..1e74dea 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostInfo.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
@@ -122,12 +122,12 @@ class HostInfo:
# default timeout for async invoked processes
TIMEOUT_SECONDS = 60
RESULT_UNAVAILABLE = "unable_to_determine"
-
+
DEFAULT_SERVICE_NAME = "ntpd"
SERVICE_STATUS_CMD = "%s %s status" % (SERVICE_CMD, DEFAULT_SERVICE_NAME)
-
+
event = threading.Event()
-
+
current_umask = -1
def __init__(self, config=None):
@@ -180,10 +180,10 @@ class HostInfo:
serviceName = service[osType]
else:
serviceName = service
-
+
service_check_live = shlex.split(self.SERVICE_STATUS_CMD)
service_check_live[1] = serviceName
-
+
svcCheckResult['name'] = serviceName
svcCheckResult['status'] = "UNKNOWN"
svcCheckResult['desc'] = ""
@@ -321,11 +321,11 @@ class HostInfo:
liveSvcs = []
self.checkLiveServices(self.DEFAULT_LIVE_SERVICES, liveSvcs)
dict['hostHealth']['liveServices'] = liveSvcs
-
+
dict['umask'] = str(self.getUMask())
# detailed host check is not available for Suse
- isSuse = 'suse' == OSCheck.get_os_family()
+ isSuse = 'suse' == OSCheck.get_os_family()
dict['iptablesIsRunning'] = self.checkIptables()
dict['reverseLookup'] = self.checkReverseLookup()
@@ -375,6 +375,7 @@ class HostInfo:
dict['hostHealth']['agentTimeStampAtReporting'] = int(time.time() * 1000)
pass
+
def checkReverseLookup(self):
"""
Check if host fqdn resolves to current host ip
@@ -389,6 +390,7 @@ class HostInfo:
pass
return False
+
class FirewallChecks(object):
def __init__(self):
self.FIREWALL_SERVICE_NAME = "iptables"
@@ -412,16 +414,18 @@ class FirewallChecks(object):
def get_stopped_result(self):
# To support test code. Expected output from run_os_command.
return (3, "", "")
-
+
def run_os_command(self, cmd):
if type(cmd) == str:
cmd = shlex.split(cmd)
-
- process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
- stderr=subprocess.PIPE)
-
- (stdoutdata, stderrdata) = process.communicate()
- return process.returncode, stdoutdata, stderrdata
+
+ try:
+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (stdoutdata, stderrdata) = process.communicate()
+ return process.returncode, stdoutdata, stderrdata
+ except OSError:
+ return self.get_stopped_result()
class UbuntuFirewallChecks(FirewallChecks):
http://git-wip-us.apache.org/repos/asf/ambari/blob/2b235e35/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
index baf95f0..60bdb21 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
@@ -509,11 +509,10 @@ class TestHostInfo(TestCase):
os_path_islink_mock.return_value = True
os_path_realpath_mock.return_value = 'real_path_to_conf'
result = []
- hostInfo.etcAlternativesConf('project',result)
+ hostInfo.etcAlternativesConf('project', result)
self.assertEquals(result[0]['name'], 'config1')
self.assertEquals(result[0]['target'], 'real_path_to_conf')
-
@patch.object(FirewallChecks, "run_os_command")
def test_IpTablesRunning(self, run_os_command_mock):
@@ -523,6 +522,29 @@ class TestHostInfo(TestCase):
run_os_command_mock.return_value = firewall.get_running_result()
self.assertTrue(firewall.check_iptables())
+ @patch("subprocess.Popen")
+ def test_run_os_command_exception(self, popen_mock):
+ def base_test():
+ return "base test"
+
+ def sub_test():
+ return "output 1", "error 1"
+
+ base_test.communicate = sub_test
+ base_test.returncode = 0
+
+ hostInfo = HostInfo()
+ for firewallType in hostInfo.getFirewallObjectTypes():
+ firewall = firewallType()
+
+ popen_mock.side_effect = None
+ popen_mock.return_value = base_test
+ self.assertTrue(firewall.check_iptables())
+
+ popen_mock.side_effect = OSError('File not found')
+ popen_mock.return_value = None
+ self.assertFalse(firewall.check_iptables())
+
@patch.object(socket, "getfqdn")
@patch.object(socket, "gethostbyname")
@patch.object(socket, "gethostname")
@@ -554,6 +576,6 @@ class TestHostInfo(TestCase):
firewall = firewallType()
run_os_command_mock.return_value = firewall.get_stopped_result()
self.assertFalse(firewall.check_iptables())
-
+
if __name__ == "__main__":
unittest.main()