Example #1
0
 def test_run_command_with_timeout(self):
     cmd = ['ls', '-ltr', '/abc']
     ping_server = mock.Mock(return_value=True)
     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.MAX_TAIL_BYTES = 10240
     deploy_report = executor.run_cmd(cmd=cmd)
     self.assertEqual(deploy_report.status_code, AgentStatus.ABORTED_BY_SERVER)
Example #2
0
 def test_run_command_with_timeout(self):
     cmd = ['ls', '-ltr', '/abc']
     ping_server = mock.Mock(return_value=True)
     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.MAX_TAIL_BYTES = 10240
     deploy_report = executor.run_cmd(cmd=cmd)
     self.assertEqual(deploy_report.status_code,
                      AgentStatus.ABORTED_BY_SERVER)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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)
Example #7
0
    def test_run_bad_script(self):
        fdout_fn = tempfile.mkstemp()[1]
        with open(fdout_fn, 'w') as f:
            f.write('echo hello')
        os.chmod(fdout_fn, 0755)

        ping_server = mock.Mock(return_value=True)
        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.PROCESS_POLL_INTERVAL = 2
        executor.MAX_RETRY = 3
        deploy_report = executor.run_cmd(cmd=fdout_fn)
        self.assertTrue(ping_server.called)
        self.assertEqual(deploy_report.status_code, AgentStatus.ABORTED_BY_SERVER)
        os.remove(fdout_fn)
Example #8
0
    def test_run_bad_script(self):
        fdout_fn = tempfile.mkstemp()[1]
        with open(fdout_fn, 'w') as f:
            f.write('echo hello')
        os.chmod(fdout_fn, 0755)

        ping_server = mock.Mock(return_value=True)
        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.PROCESS_POLL_INTERVAL = 2
        executor.MAX_RETRY = 3
        deploy_report = executor.run_cmd(cmd=fdout_fn)
        self.assertTrue(ping_server.called)
        self.assertEqual(deploy_report.status_code,
                         AgentStatus.ABORTED_BY_SERVER)
        os.remove(fdout_fn)