incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject git commit: AMBARI-2653. Add umask checks for host checks - we should alert if umask is not 022. (Dmytro Shkvyra via smohanty)
Date Wed, 17 Jul 2013 16:53:28 GMT
Updated Branches:
  refs/heads/trunk 896165e49 -> 227560211


AMBARI-2653. Add umask checks for host checks - we should alert if umask is not 022. (Dmytro
Shkvyra via smohanty)


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

Branch: refs/heads/trunk
Commit: 2275602111d90f972df63a3d8c74a46aa0e6d65f
Parents: 896165e
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Wed Jul 17 09:53:06 2013 -0700
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Wed Jul 17 09:53:06 2013 -0700

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/HostInfo.py    | 13 ++++++
 ambari-agent/src/test/python/TestHostInfo.py    |  5 ++-
 .../src/test/python/TestRegistration.py         |  2 +
 .../apache/ambari/server/agent/AgentEnv.java    | 10 +++++
 .../ambari/server/agent/AgentResourceTest.java  | 46 ++++++++++++++------
 5 files changed, 62 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/22756021/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 ac35b72..df1f802 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostInfo.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
@@ -87,6 +87,8 @@ class HostInfo:
   TIMEOUT_SECONDS = 60
   RESULT_UNAVAILABLE = "unable_to_determine"
   event = threading.Event()
+  
+  current_umask = -1
 
   def __init__(self, config=None):
     self.packages = PackagesAnalyzer()
@@ -250,6 +252,15 @@ class HostInfo:
         reposToRemove.append(repo)
     return reposToRemove
 
+  def getUMask(self):
+    if (self.current_umask == -1):
+     self.current_umask = os.umask(self.current_umask)
+     os.umask(self.current_umask)
+     return self.current_umask
+    else:
+     return self.current_umask
+ 
+ 
   """ Return various details about the host
   componentsMapped: indicates if any components are mapped to this host
   commandsInProgress: indicates if any commands are in progress
@@ -270,6 +281,8 @@ class HostInfo:
     liveSvcs = []
     self.checkLiveServices(self.DEFAULT_LIVE_SERVICES, liveSvcs)
     dict['hostHealth']['liveServices'] = liveSvcs
+    
+    dict['umask'] = str(self.getUMask())
 
     # If commands are in progress or components are already mapped to this host
     # Then do not perform certain expensive host checks

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/22756021/ambari-agent/src/test/python/TestHostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/TestHostInfo.py b/ambari-agent/src/test/python/TestHostInfo.py
index 75eefd7..8839ff3 100644
--- a/ambari-agent/src/test/python/TestHostInfo.py
+++ b/ambari-agent/src/test/python/TestHostInfo.py
@@ -229,6 +229,7 @@ class TestHostInfo(TestCase):
     self.assertTrue(newlist[1]['status'], "Invalid home directory")
 
 
+  @patch('os.umask')
   @patch.object(HostInfo, 'osdiskAvailableSpace')
   @patch.object(HostCheckReportFileHandler, 'writeHostCheckFile')
   @patch.object(PackagesAnalyzer, 'allAvailablePackages')
@@ -246,7 +247,8 @@ class TestHostInfo(TestCase):
   @patch.object(HostInfo, 'hadoopVarLogCount')
   def test_hostinfo_register(self, hvlc_mock, hvrc_mock, eac_mock, cf_mock, jp_mock,
                              cls_mock, cu_mock, gir_mock, gipbr_mock, gipbn_mock,
-                             gpd_mock, aip_mock, aap_mock, whcf_mock, odas_mock):
+                             gpd_mock, aip_mock, aap_mock, whcf_mock, odas_mock,
+                             os_umask_mock):
     hvlc_mock.return_value = 1
     hvrc_mock.return_value = 1
     gipbr_mock.return_value = ["pkg1"]
@@ -264,6 +266,7 @@ class TestHostInfo(TestCase):
 
     hostInfo.register(dict, False, True)
     self.verifyReturnedValues(dict)
+    self.assertTrue(os_umask_mock.call_count == 2)
 
     hostInfo = HostInfo()
     dict = {}

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/22756021/ambari-agent/src/test/python/TestRegistration.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/TestRegistration.py b/ambari-agent/src/test/python/TestRegistration.py
index 4ac8d3d..18d08ca 100644
--- a/ambari-agent/src/test/python/TestRegistration.py
+++ b/ambari-agent/src/test/python/TestRegistration.py
@@ -47,6 +47,8 @@ class TestRegistration(TestCase):
     self.assertEquals(data['timestamp'] > 1353678475465L, True, "timestamp should not
be empty")
     self.assertEquals(len(data['agentEnv']) > 0, True, "agentEnv should not be empty")
     self.assertEquals(data['agentVersion'], '1.3.0', "agentVersion should not be empty")
+    print data['agentEnv']['umask']
+    self.assertEquals(not data['agentEnv']['umask']== "", True, "agents umask should not
be empty")
     self.assertEquals(len(data), 7)
 
     os.remove(ver_file)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/22756021/ambari-server/src/main/java/org/apache/ambari/server/agent/AgentEnv.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/AgentEnv.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/AgentEnv.java
index 22e0bd9..97b1f82 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/AgentEnv.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/AgentEnv.java
@@ -60,6 +60,16 @@ public class AgentEnv {
    * The host health report
    */
   private HostHealth hostHealth = new HostHealth();
+  
+  private Integer umask;
+
+  public Integer getUmask() {
+    return umask;
+  }
+
+  public void setUmask(Integer umask) {
+    this.umask = umask;
+  }
 
   public Directory[] getStackFoldersAndFiles() {
       return stackFoldersAndFiles;

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/22756021/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
index b5ce66d..4a14389 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
@@ -162,44 +162,64 @@ public class AgentResourceTest extends JerseyTest {
 
   @Test
   public void deserializeClasses() {
+    String DirectoryJSON = "[{name:'/var/lib', type:'directory'},{name:'b', type:'directory'}]";
+    String PackageDetailJSON = "[{name:'abc', version:'2.3', repoName:'HDP'},{name:'abc',
version:'3.3', repoName:'HDP-epel'}]";
+    String ExistingUserJSON = "[{name:'hdfs', homeDir:'/var/lib/hadoop', status:''}, " +
+            "{name:'ambari_qa', homeDir:'/var/home/ambari_qa',status:'None'}]";
+    String JavaProcJSON = "[{user:'root', pid:'355', hadoop:'True', command:'cmd'}, " +
+            "{user:'hdfs', pid:'325', hadoop:'False', command:'cmd = 2'}]";
+    String AlternativeJSON = "[{name:'/etc/alternatives/hdfs-conf', target:'/etc/hadoop/conf.dist'},
" +
+            "{name:'abc', target:'def'}]";
+    String AgentEnvJSON = "{\"alternatives\": " + AlternativeJSON + 
+            ", \"existingUsers\": "+ ExistingUserJSON +
+            ", \"umask\": \"18\", \"installedPackages\": "+
+            PackageDetailJSON +", \"stackFoldersAndFiles\": "+ DirectoryJSON +"}";
     AgentEnv.Directory[] dirs = getJsonFormString(
-        "[{name:'/var/lib', type:'directory'},{name:'b', type:'directory'}]",
-        AgentEnv.Directory[].class);
+            DirectoryJSON, AgentEnv.Directory[].class);
     Assert.assertEquals("/var/lib", dirs[0].getName());
     Assert.assertEquals("directory", dirs[1].getType());
 
     AgentEnv.PackageDetail[] pkgs = getJsonFormString(
-        "[{name:'abc', version:'2.3', repoName:'HDP'},{name:'abc', version:'3.3', repoName:'HDP-epel'}]",
-        AgentEnv.PackageDetail[].class);
+        PackageDetailJSON, AgentEnv.PackageDetail[].class);
     Assert.assertEquals("abc", pkgs[0].getName());
     Assert.assertEquals("HDP", pkgs[0].getRepoName());
     Assert.assertEquals("3.3", pkgs[1].getVersion());
 
     AgentEnv.ExistingUser[] users = getJsonFormString(
-        "[{name:'hdfs', homeDir:'/var/lib/hadoop', status:''}, " +
-            "{name:'ambari_qa', homeDir:'/var/home/ambari_qa',status:'None'}]",
-        AgentEnv.ExistingUser[].class);
+        ExistingUserJSON, AgentEnv.ExistingUser[].class);
     Assert.assertEquals("hdfs", users[0].getUserName());
     Assert.assertEquals("/var/lib/hadoop", users[0].getUserHomeDir());
     Assert.assertEquals("None", users[1].getUserStatus());
 
     AgentEnv.JavaProc[] procs = getJsonFormString(
-        "[{user:'root', pid:'355', hadoop:'True', command:'cmd'}, " +
-            "{user:'hdfs', pid:'325', hadoop:'False', command:'cmd = 2'}]",
-        AgentEnv.JavaProc[].class);
+        JavaProcJSON, AgentEnv.JavaProc[].class);
     Assert.assertEquals("root", procs[0].getUser());
     Assert.assertEquals(355, procs[0].getPid());
     Assert.assertEquals("cmd = 2", procs[1].getCommand());
     Assert.assertEquals(false, procs[1].isHadoop());
 
     AgentEnv.Alternative[] alternatives = getJsonFormString(
-        "[{name:'/etc/alternatives/hdfs-conf', target:'/etc/hadoop/conf.dist'}, " +
-            "{name:'abc', target:'def'}]",
-        AgentEnv.Alternative[].class);
+        AlternativeJSON, AgentEnv.Alternative[].class);
     Assert.assertEquals("/etc/alternatives/hdfs-conf", alternatives[0].getName());
     Assert.assertEquals("/etc/hadoop/conf.dist", alternatives[0].getTarget());
     Assert.assertEquals("abc", alternatives[1].getName());
     Assert.assertEquals("def", alternatives[1].getTarget());
+    
+    AgentEnv agentEnv = getJsonFormString(
+            AgentEnvJSON, AgentEnv.class);
+    Assert.assertTrue(18 == agentEnv.getUmask());
+    Assert.assertEquals("/etc/alternatives/hdfs-conf", agentEnv.getAlternatives()[0].getName());
+    Assert.assertEquals("/etc/hadoop/conf.dist", agentEnv.getAlternatives()[0].getTarget());
+    Assert.assertEquals("abc", agentEnv.getAlternatives()[1].getName());
+    Assert.assertEquals("def", agentEnv.getAlternatives()[1].getTarget());
+    Assert.assertEquals("abc", agentEnv.getInstalledPackages()[0].getName());
+    Assert.assertEquals("HDP", agentEnv.getInstalledPackages()[0].getRepoName());
+    Assert.assertEquals("3.3", agentEnv.getInstalledPackages()[1].getVersion());
+    Assert.assertEquals("hdfs", agentEnv.getExistingUsers()[0].getUserName());
+    Assert.assertEquals("/var/lib/hadoop", agentEnv.getExistingUsers()[0].getUserHomeDir());
+    Assert.assertEquals("None", agentEnv.getExistingUsers()[1].getUserStatus());
+    Assert.assertEquals("/var/lib", agentEnv.getStackFoldersAndFiles()[0].getName());
+    Assert.assertEquals("directory", agentEnv.getStackFoldersAndFiles()[1].getType());  
 
   }
 
   public class MockModule extends AbstractModule {


Mime
View raw message