You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2013/06/14 19:33:53 UTC

svn commit: r1493177 - in /incubator/ambari/trunk/ambari-server/src: main/python/ambari-server.py test/python/TestAmbaryServer.py

Author: swagle
Date: Fri Jun 14 17:33:52 2013
New Revision: 1493177

URL: http://svn.apache.org/r1493177
Log:
AMBARI-2343. Download of JCE during Ambari Server setup must support local repo install. (Dmitry Lysnichenko via swagle)

Modified:
    incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
    incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py

Modified: incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py?rev=1493177&r1=1493176&r2=1493177&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py (original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py Fri Jun 14 17:33:52 2013
@@ -1273,21 +1273,30 @@ def track_jdk(base_name, url, local_name
   fp.flush()
   fp.close()
 
-
+def install_jce_manualy(args):
+  properties = get_ambari_properties()
+  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
+  else:
+    err = "Error getting ambari properties"
+    print_error_msg( err )
+    raise FatalException(-1, err)
 
 #
 # Downloads the JDK
 #
 def download_jdk(args):
+  install_jce_manualy(args)
   if get_JAVA_HOME():
     return 0
   if args.java_home and os.path.exists(args.java_home):
     print_warning_msg("JAVA_HOME " + args.java_home
                     + " must be valid on ALL hosts")
-    print_warning_msg("Please make sure the JCE Unlimited Strength "
-                      "Jurisdiction Policy Files 6, "
-                      "are downloaded on all "
-                      "hosts")
     write_property(JAVA_HOME_PROPERTY, args.java_home)
     return 0
 
@@ -2418,6 +2427,8 @@ def main():
                       help="File with stack upgrade script")
   parser.add_option('-j', '--java-home', default=None,
                   help="Use specified java_home.  Must be valid on all hosts")
+  parser.add_option('-c', '--jce-policy', default=None,
+                  help="Use specified jce_policy.  Must be valid on all hosts", dest="jce_policy") 
   parser.add_option("-v", "--verbose",
                   action="store_true", dest="verbose", default=False,
                   help="Print verbose status messages")

Modified: incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py?rev=1493177&r1=1493176&r2=1493177&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py (original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py Fri Jun 14 17:33:52 2013
@@ -798,7 +798,35 @@ class TestAmbariServer(TestCase):
     self.assertEqual(2, len(dlprogress_mock.call_args_list))
 
 
+  @patch("shutil.copy")
+  @patch("os.path.join")
+  @patch("os.path.exists")
+  @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, shutil_copy_mock):
+    args = MagicMock()
+    args.jce_policy = "somewhere"
+    p = MagicMock()
+    get_ambari_properties_mock.return_value = p
+    p.__getitem__.side_effect = None
+    p.__getitem__.return_value = "somewhere"
+    os_path_exists_mock.return_value = True
+    os_path_join_mock.return_value = "/var/lib/ambari-server/resources/jce_policy-6.zip" 
+    ambari_server.install_jce_manualy(args)	
+    self.assertTrue(shutil_copy_mock.called)
+
+    os_path_exists_mock.return_value = False
+    args.jce_policy = None
+
+    try:
+      ambari_server.install_jce_manualy(args)
+      self.fail("Should throw exception because of not found jce_policy-6.zip")
+    except FatalException:
+      # Expected
+      self.assertTrue(shutil_copy_mock.called)
+      pass  	
+
 
+  @patch.object(ambari_server, "install_jce_manualy")
   @patch("os.stat")
   @patch("os.path.isfile")
   @patch("os.path.exists")
@@ -812,7 +840,7 @@ class TestAmbariServer(TestCase):
   def test_download_jdk(self, get_ambari_properties_mock, get_JAVA_HOME_mock, print_info_msg_mock,
                         write_property_mock, run_os_command_mock, get_YN_input_mock, track_jdk_mock,
                         path_existsMock,
-                        path_isfileMock, statMock):
+                        path_isfileMock, statMock, install_jce_manualy_mock):
     args = MagicMock()
     args.java_home = "somewhere"
     path_existsMock.return_value = False