Browse Source

AMBARI-5139 Error while host confirmation (bootstrap.py) (Dmytro Shkvyra via dsen)

Dmitry Sen 11 years ago
parent
commit
17ead15a76

+ 5 - 1
ambari-server/src/main/python/bootstrap.py

@@ -422,7 +422,11 @@ class Bootstrap(threading.Thread):
   def try_to_execute(self, action):
     last_retcode = {"exitstatus": 177, "log":"Try to execute '{0}'".format(str(action)), "errormsg":"Execute of '{0}' failed".format(str(action))}
     try:
-      last_retcode = action()
+      retcode = action()
+      if isinstance(retcode, int):
+        last_retcode["exitstatus"] = retcode
+      else:
+        last_retcode = retcode
     except Exception, e:
       self.host_log.write("Traceback: " + traceback.format_exc())
     return last_retcode

+ 9 - 2
ambari-server/src/test/python/TestBootstrap.py

@@ -620,10 +620,17 @@ class TestBootstrap(TestCase):
                                None, "8440")
     bootstrap_obj = Bootstrap("hostname", shared_state)
     # Normal case
-    ret = bootstrap_obj.try_to_execute(lambda : {"exitstatus": expected})
+    def act_normal_return_int():
+      return 43
+    ret = bootstrap_obj.try_to_execute(act_normal_return_int)
+    self.assertEqual(ret["exitstatus"], expected)
+    self.assertFalse(write_mock.called)
+    write_mock.reset_mock()
+    def act_normal_return():
+        return {"exitstatus": 43}
+    ret = bootstrap_obj.try_to_execute(act_normal_return)
     self.assertEqual(ret["exitstatus"], expected)
     self.assertFalse(write_mock.called)
-
     write_mock.reset_mock()
     # Exception scenario
     def act():