incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odiache...@apache.org
Subject git commit: AMBARI-3337. When invalid jce policy file path is specified, ambari-server setup silently switches over to downloading the file from public repo.(Artem Baranchuk via odiachenko)
Date Wed, 25 Sep 2013 17:07:35 GMT
Updated Branches:
  refs/heads/branch-1.4.1 f1280471f -> 273e3f9f7


AMBARI-3337. When invalid jce policy file path is specified, ambari-server setup silently
switches over to downloading the file from public repo.(Artem Baranchuk via odiachenko)


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

Branch: refs/heads/branch-1.4.1
Commit: 273e3f9f770fba6bae60003167fa5ac6bc5850b1
Parents: f128047
Author: Oleksandr Diachenko <odiachenko@hortonworks.com>
Authored: Wed Sep 25 20:07:11 2013 +0300
Committer: Oleksandr Diachenko <odiachenko@hortonworks.com>
Committed: Wed Sep 25 20:07:23 2013 +0300

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  | 22 ++++++++++++----
 .../src/test/python/TestAmbariServer.py         | 27 +++++++++++++++++++-
 2 files changed, 43 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/273e3f9f/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index 72943b4..b3be818 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -1594,11 +1594,23 @@ def install_jce_manualy(args):
   if properties == -1:
     err = "Error getting ambari properties"
     raise FatalException(-1, err)
-  if args.jce_policy and os.path.exists(args.jce_policy):
-    jce_destination = os.path.join(properties[RESOURCES_DIR_PROPERTY], JCE_POLICY_FILENAME)
-    shutil.copy(args.jce_policy, jce_destination)
-    print "JCE policy copied from " + args.jce_policy + " to " + jce_destination
-    return 0
+  if args.jce_policy:
+    if os.path.exists(args.jce_policy):
+      if os.path.isdir(args.jce_policy):
+        err = "JCE Policy path is a directory: " + args.jce_policy
+        raise FatalException(-1, err)
+      jce_destination = os.path.join(properties[RESOURCES_DIR_PROPERTY], JCE_POLICY_FILENAME)
+      try:
+        shutil.copy(args.jce_policy, jce_destination)
+      except Exception, e:
+        err = "Can not copy file {0} to {1} due to: {2}. Please check file " \
+              "permissions and free disk space.".format(args.jce_policy, jce_destination,
e.message)
+        raise FatalException(-1, err)
+      print "JCE policy copied from " + args.jce_policy + " to " + jce_destination
+      return 0
+    else:
+      err = "JCE Policy path " + args.jce_policy + " doesn't exists."
+      raise FatalException(-1, err)
   else:
     return 1
 #

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/273e3f9f/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 f744fd8..9700468 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -1042,9 +1042,10 @@ class TestAmbariServer(TestCase):
   @patch("shutil.copy")
   @patch("os.path.join")
   @patch("os.path.exists")
+  @patch("os.path.isdir")
   @patch.object(ambari_server, "get_ambari_properties")
   def test_install_jce_manualy(self, get_ambari_properties_mock, \
-                               os_path_exists_mock, os_path_join_mock, \
+                               os_path_isdir_mock, os_path_exists_mock, os_path_join_mock,
\
                                shutil_copy_mock):
     args = MagicMock()
     args.jce_policy = "somewhere"
@@ -1052,7 +1053,31 @@ class TestAmbariServer(TestCase):
     get_ambari_properties_mock.return_value = p
     p.__getitem__.side_effect = None
     p.__getitem__.return_value = "somewhere"
+
+    # Case when JCE path doesn't exists
+    os_path_exists_mock.return_value = False
+    try:
+      ambari_server.install_jce_manualy(args)
+      self.fail("Should throw exception")
+    except FatalException as fe:
+      # Expected
+      self.assertTrue("JCE Policy path" in fe.reason)
+      pass
+    os_path_exists_mock.reset()
+
+    # Case when JCE is a directory
     os_path_exists_mock.return_value = True
+    os_path_isdir_mock.return_value = True
+    try:
+      ambari_server.install_jce_manualy(args)
+      self.fail("Should throw exception")
+    except FatalException as fe:
+      # Expected
+      self.assertTrue("JCE Policy path is a directory" in fe.reason)
+      pass
+    os_path_isdir_mock.reset()
+
+    os_path_isdir_mock.return_value = False
     os_path_join_mock.return_value = \
       "/var/lib/ambari-server/resources/jce_policy-6.zip"
     ambari_server.install_jce_manualy(args)


Mime
View raw message