def test_run_command_with_timeout_error(self): cmd = ['sleep', '20'] ping_server = mock.Mock(return_value=False) executor = Executor(callback=ping_server) executor.LOG_FILENAME = self.fdout_fn executor.MAX_RUNNING_TIME = 4 executor.MIN_RUNNING_TIME = 2 executor.DEFAULT_TAIL_LINES = 1 executor.MAX_RETRY = 3 executor.PROCESS_POLL_INTERVAL = 2 executor.BACK_OFF = 2 executor.MAX_SLEEP_INTERVAL = 60 executor.MAX_TAIL_BYTES = 10240 deploy_report = executor.run_cmd(cmd=cmd) self.assertTrue(ping_server.called) self.assertEqual(deploy_report.status_code, AgentStatus.SCRIPT_TIMEOUT)
def test_run_command_with_max_retry(self): cmd = ['ls', '-ltr', '/abc'] ping_server = mock.Mock(return_value=False) executor = Executor(callback=ping_server) executor.LOG_FILENAME = self.fdout_fn executor.MAX_RUNNING_TIME = 5 executor.MIN_RUNNING_TIME = 2 executor.MAX_RETRY = 3 executor.DEFAULT_TAIL_LINES = 1 executor.PROCESS_POLL_INTERVAL = 2 executor.BACK_OFF = 2 executor.MAX_SLEEP_INTERVAL = 60 executor.MAX_TAIL_BYTES = 10240 deploy_report = executor.run_cmd(cmd=cmd) self.assertEqual(deploy_report.status_code, AgentStatus.TOO_MANY_RETRY) # in ubuntu: error message is 'ls: cannot access /abc: No such file or directory' # in mac osx: error message is 'ls: /abc: No such file or directory' self.assertEqual(deploy_report.retry_times, 3)