Pārlūkot izejas kodu

AMBARI-4918. Entering valid directory but not a java home is not validated.(vbrodetskyi)

Vitaly Brodetskyi 11 gadi atpakaļ
vecāks
revīzija
c97c276ae6

+ 2 - 2
ambari-server/src/main/python/ambari-server.py

@@ -1670,8 +1670,8 @@ def download_jdk(args):
   jcePolicyWarn = "JCE Policy files are required for configuring Kerberos security. If you plan to use Kerberos," \
          "please make sure JCE Unlimited Strength Jurisdiction Policy Files are valid on all hosts."
   if args.java_home:
-    if not os.path.exists(args.java_home):
-      err = "Path to java home " + args.java_home + " does not exists"
+    if not os.path.exists(args.java_home) or not os.path.isfile(os.path.join(args.java_home,"bin","java")):
+      err = "Path to java home " + args.java_home + " or java binary file does not exists"
       raise FatalException(1, err)
 
     print_warning_msg("JAVA_HOME " + args.java_home + " must be valid on ALL hosts")

+ 2 - 1
ambari-server/src/test/python/TestAmbariServer.py

@@ -1937,6 +1937,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     args.java_home = "somewhere"
     path_existsMock.side_effect = [True,False,False]
     get_JAVA_HOME_mock.return_value = True
+    path_isfileMock.return_value = True
     ambari_server.download_jdk(args)
     self.assertTrue(write_property_mock.call_count == 1)
     self.assertTrue(remove_property_mock.call_count == 2)
@@ -1986,7 +1987,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       ambari_server.download_jdk(args)
       self.fail("Should throw exception")
     except FatalException as fe:
-      self.assertTrue("Path to java home somewhere does not exists" in fe.reason)
+      self.assertTrue("Path to java home somewhere or java binary file does not exists" in fe.reason)
     #Test case: Setup ambari-server with jdk location passed. Path to JDK doesn't not exists
     args.java_home = None
     args.jdk_location = "/existing/jdk/file"