You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by od...@apache.org on 2013/09/25 19:05:05 UTC
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)
Updated Branches:
refs/heads/trunk 81e842325 -> bf7972bcc
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/bf7972bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/bf7972bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/bf7972bc
Branch: refs/heads/trunk
Commit: bf7972bcc7f6cf0fef300f840191c1d4b07ecc6e
Parents: 81e8423
Author: Oleksandr Diachenko <od...@hortonworks.com>
Authored: Wed Sep 25 20:01:14 2013 +0300
Committer: Oleksandr Diachenko <od...@hortonworks.com>
Committed: Wed Sep 25 20:04:53 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/bf7972bc/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/bf7972bc/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)