Parcourir la source

AMBARI-2460. Running ambari-server upgrade if the upgrade has already been run leads to errors. (Dmitry Sen via smohanty)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1495624 13f79535-47bb-0310-9956-ffa450edef68
Sumit Mohanty il y a 12 ans
Parent
commit
e042472713

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

@@ -333,7 +333,8 @@ def update_ambari_properties():
   prev_conf_file = search_file(AMBARI_PROPERTIES_RPMSAVE_FILE, get_conf_dir())
   conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())
 
-  if not prev_conf_file: # Previous config file does not exist
+  # Previous config file does not exist
+  if (not prev_conf_file) or (prev_conf_file is None):
     print_warning_msg("Can not find ambari.properties.rpmsave file from previous version, skipping import of settings")
     return 0
 

+ 18 - 0
ambari-server/src/test/python/TestAmbaryServer.py

@@ -2157,6 +2157,24 @@ class TestAmbariServer(TestCase):
     result = ambari_server.update_ambari_properties()
     self.assertNotEquals(result, 0)
 
+  @patch.object(ambari_server.Properties, '__init__')
+  @patch.object(ambari_server, 'search_file')
+  def test_update_ambari_properties_negative_case(self, search_file_mock, properties_mock):
+    search_file_mock.return_value = None
+    #Call tested method
+    self.assertEquals(0, ambari_server.update_ambari_properties())
+    self.assertFalse(properties_mock.called)
+
+    search_file_mock.return_value = False
+    #Call tested method
+    self.assertEquals(0, ambari_server.update_ambari_properties())
+    self.assertFalse(properties_mock.called)
+
+    search_file_mock.return_value = ''
+    #Call tested method
+    self.assertEquals(0, ambari_server.update_ambari_properties())
+    self.assertFalse(properties_mock.called)
+
   @patch("sys.exit")
   @patch.object(ambari_server, "get_db_cli_tool")
   @patch.object(ambari_server, "store_remote_properties")