浏览代码

AMBARI-20407. When agent retries commands it needs to handle credential store processing correctly (smohanty)

Sumit Mohanty 8 年之前
父节点
当前提交
f6d1816a57

+ 1 - 0
ambari-agent/src/main/python/ambari_agent/ActionQueue.py

@@ -316,6 +316,7 @@ class ActionQueue(threading.Thread):
         retryDuration -= delay  # allow one last attempt
         commandresult['stderr'] += "\n\nCommand failed. Retrying command execution ...\n\n"
         logger.info("Retrying command with taskId = {cid} after a wait of {delay}".format(cid=taskId, delay=delay))
+        command['commandBeingRetried'] = "true"
         time.sleep(delay)
         continue
       else:

+ 5 - 1
ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py

@@ -370,7 +370,11 @@ class CustomServiceOrchestrator():
         credentialStoreEnabled = (command['credentialStoreEnabled'] == "true")
 
       if credentialStoreEnabled == True:
-        self.generateJceks(command)
+        if 'commandBeingRetried' not in command or command['commandBeingRetried'] != "true":
+          self.generateJceks(command)
+        else:
+          logger.info("Skipping generation of jceks files as this is a retry of the command")
+
 
       json_path = self.dump_command_to_json(command, retry)
       pre_hook_tuple = self.resolve_hook_script_path(hook_dir,

+ 2 - 0
ambari-agent/src/test/python/ambari_agent/TestActionQueue.py

@@ -1274,6 +1274,7 @@ class TestActionQueue(TestCase):
     }
 
     command = copy.deepcopy(self.retryable_command)
+    self.assertFalse('commandBeingRetried' in command)
     with patch.object(CustomServiceOrchestrator, "runCommand") as runCommand_mock:
       runCommand_mock.side_effect = [execution_result_fail_dict, execution_result_succ_dict]
       actionQueue.execute_command(command)
@@ -1282,6 +1283,7 @@ class TestActionQueue(TestCase):
     self.assertTrue(runCommand_mock.called)
     self.assertEqual(2, runCommand_mock.call_count)
     self.assertEqual(1, sleep_mock.call_count)
+    self.assertEqual(command['commandBeingRetried'], "true")
     sleep_mock.assert_any_call(2)
 
   @not_for_platform(PLATFORM_LINUX)