You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2017/09/12 14:21:33 UTC
ambari git commit: AMBARI-21634. Make sure Ambari also considers NIS
users (Aman Poonia via ncole)
Repository: ambari
Updated Branches:
refs/heads/trunk 02bea547c -> f89dcd7d0
AMBARI-21634. Make sure Ambari also considers NIS users (Aman Poonia via ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f89dcd7d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f89dcd7d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f89dcd7d
Branch: refs/heads/trunk
Commit: f89dcd7d03d18a57543f2a86653345ad3ab00095
Parents: 02bea54
Author: Nate Cole <nc...@hortonworks.com>
Authored: Tue Sep 12 10:19:41 2017 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Tue Sep 12 10:19:41 2017 -0400
----------------------------------------------------------------------
.../src/main/python/ambari_agent/HostInfo.py | 29 +++++++++++---------
.../test/python/ambari_agent/TestHostInfo.py | 21 ++++----------
2 files changed, 21 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/f89dcd7d/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 5f96df5..b8545cc 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostInfo.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
@@ -21,6 +21,7 @@ limitations under the License.
import glob
import logging
import os
+import pwd
import re
import shlex
import socket
@@ -170,13 +171,13 @@ class HostInfoLinux(HostInfo):
"hue", "yarn", "tez", "storm", "falcon", "kafka", "knox", "ams",
"hadoop", "spark", "accumulo", "atlas", "mahout", "ranger", "kms", "zeppelin"
]
-
+
# Default set of directories that are checked for existence of files and folders
DEFAULT_BASEDIRS = [
"/etc", "/var/run", "/var/log", "/usr/lib", "/var/lib", "/var/tmp", "/tmp", "/var",
"/hadoop", "/usr/hdp"
]
-
+
# Exact directories names which are checked for existance
EXACT_DIRECTORIES = [
"/kafka-logs"
@@ -193,15 +194,17 @@ class HostInfoLinux(HostInfo):
super(HostInfoLinux, self).__init__(config)
def checkUsers(self, users, results):
- f = open('/etc/passwd', 'r')
- for userLine in f:
- fields = userLine.split(":")
- if fields[0] in users:
- result = {}
- result['name'] = fields[0]
- result['homeDir'] = fields[5]
- result['status'] = "Available"
- results.append(result)
+ for user in users:
+ try:
+ pw = pwd.getpwnam(user)
+ result = {}
+ result['name'] = pw.pw_name
+ result['homeDir'] = pw.pw_dir
+ result['status'] = "Available"
+ results.append(result)
+ except Exception as e:
+ #User doesnot exist, so skip it
+ pass
def checkFolders(self, basePaths, projectNames, exactDirectories, existingUsers, dirs):
foldersToIgnore = []
@@ -216,13 +219,13 @@ class HostInfoLinux(HostInfo):
obj['type'] = self.dirType(path)
obj['name'] = path
dirs.append(obj)
-
+
for path in exactDirectories:
if os.path.exists(path):
obj = {}
obj['type'] = self.dirType(path)
obj['name'] = path
- dirs.append(obj)
+ dirs.append(obj)
except:
logger.exception("Checking folders failed")
http://git-wip-us.apache.org/repos/asf/ambari/blob/f89dcd7d/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 cb20f4e..3c46268 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
@@ -59,26 +59,15 @@ class TestHostInfo(TestCase):
self.assertTrue(item in names)
- @patch('os.path.exists')
- @patch('__builtin__.open')
- def test_checkUsers(self, builtins_open_mock, path_mock):
- builtins_open_mock.return_value = [
- "hdfs:x:493:502:Hadoop HDFS:/usr/lib/hadoop:/bin/bash",
- "zookeeper:x:492:502:ZooKeeper:/var/run/zookeeper:/bin/bash"]
- path_mock.side_effect = [False, True, False]
-
+ def test_checkUsers(self):
hostInfo = HostInfoLinux()
results = []
- hostInfo.checkUsers(["zookeeper", "hdfs"], results)
- self.assertEqual(2, len(results))
+ hostInfo.checkUsers(["root", "zxlmnap12341234"], results)
+ self.assertEqual(1, len(results))
newlist = sorted(results, key=lambda k: k['name'])
- self.assertTrue(newlist[0]['name'], "hdfs")
- self.assertTrue(newlist[1]['name'], "zookeeper")
- self.assertTrue(newlist[0]['homeDir'], "/usr/lib/hadoop")
- self.assertTrue(newlist[1]['homeDir'], "/var/run/zookeeper")
+ self.assertTrue(newlist[0]['name'], "root")
+ self.assertTrue(newlist[0]['homeDir'], "/root")
self.assertTrue(newlist[0]['status'], "Available")
- self.assertTrue(newlist[1]['status'], "Invalid home directory")
- print(path_mock.mock_calls)
@patch.object(OSCheck, "get_os_type")
@patch('os.umask')