Exemplo n.º 1
0
    def testRunCommandWithRetries_firstTrySucceeds_commandNotRetried(
            self, unused_mock_sleep):
        mock_command_runner = test_lib.GetMockCommandRunner()
        # Return empty strings for stdout and stderr and 0 (success) for the
        # exit code.
        mock_command_runner.run.return_value = (str(), str(), 0)
        test_workflow = workflow.BaseWorkflow(
            label='unused', settings_path=None,
            command_runner=mock_command_runner)

        test_workflow.run_command_with_retries('test_command')

        self.assertEqual(mock_command_runner.run.call_count, 1)
Exemplo n.º 2
0
    def testRunCommand_returnsStdoutAndStdErr(self):
        mock_command_runner = test_lib.GetMockCommandRunner()
        # Return fake strings for stdout and stderr and 0 for the exit code.
        mock_command_runner.run.return_value = ('fake_stdout', 'fake_stderr',
                                                0)
        test_workflow = workflow.BaseWorkflow(
            label='unused', settings_path=None,
            command_runner=mock_command_runner)

        stdout, stderr = test_workflow.run_command('test_command')

        self.assertEqual(stdout, 'fake_stdout')
        self.assertEqual(stderr, 'fake_stderr')
Exemplo n.º 3
0
    def testRunCommandWithRetries_maxRetriesReached_raisesException(
            self, unused_mock_sleep):
        FLAGS.max_retries = 1
        mock_command_runner = test_lib.GetMockCommandRunner()
        return1 = (str(), str(), 1)  # command failed
        return2 = (str(), str(), 1)  # command failed
        return3 = (str(), str(), 0)  # command succeeded
        mock_command_runner.run.side_effect = [return1, return2, return3]
        test_workflow = workflow.BaseWorkflow(
            label='unused', settings_path=None,
            command_runner=mock_command_runner)

        with self.assertRaises(workflow.NonZeroExitCode):
            test_workflow.run_command_with_retries('test_command')
Exemplo n.º 4
0
    def testRunCommandWithRetries_firstTryFails_commandRetried(
            self, unused_mock_sleep):
        FLAGS.max_retries = 1
        mock_command_runner = test_lib.GetMockCommandRunner()
        return1 = (str(), str(), 1)  # command failed
        return2 = (str(), str(), 0)  # command succeeded
        mock_command_runner.run.side_effect = [return1, return2]
        test_workflow = workflow.BaseWorkflow(
            label='unused', settings_path=None,
            command_runner=mock_command_runner)

        test_workflow.run_command_with_retries('test_command')

        self.assertEqual(mock_command_runner.run.call_count, 2)
Exemplo n.º 5
0
    def testInsertPostHook_functionWithOutKwargs_addsHookWithEmptyKwargs(self):
        def test_func1(x):
            return x

        def test_func2(x):
            return x

        test_workflow = workflow.BaseWorkflow(label='unused',
                                              settings_path=None)

        test_workflow.add_post_hook(test_func1)
        test_workflow.insert_post_hook(0, test_func2)

        self.assertEqual(test_workflow._post_job_hooks[0], (test_func2, {}))
Exemplo n.º 6
0
    def testRunCommandWithRetries_firstTryFails_sleepsBetweenRetries(
            self, mock_sleep):
        FLAGS.max_retries = 1
        FLAGS.retry_interval = 7
        mock_command_runner = test_lib.GetMockCommandRunner()
        return1 = (str(), str(), 1)  # command failed
        return2 = (str(), str(), 0)  # command succeeded
        mock_command_runner.run.side_effect = [return1, return2]
        test_workflow = workflow.BaseWorkflow(
            label='unused', settings_path=None,
            command_runner=mock_command_runner)

        test_workflow.run_command_with_retries('test_command')

        mock_sleep.assert_called_once_with(7)
Exemplo n.º 7
0
    def testRunCommand_hostIsNotLocalhost_sshArgumentsAdded(self):
        FLAGS.remote_user = '******'
        FLAGS.ssh_path = '/fake/ssh'
        FLAGS.ssh_port = 1234
        mock_command_runner = test_lib.GetMockCommandRunner()
        test_workflow = workflow.BaseWorkflow(
            label='unused', settings_path=None,
            command_runner=mock_command_runner)

        test_workflow.run_command(
            'test_command --test_flag test_arg', host='fake_host')

        mock_command_runner.run.assert_called_once_with(
            ['/fake/ssh', '-p', '1234', 'test_user@fake_host', 'test_command',
             '--test_flag', 'test_arg'], False)
Exemplo n.º 8
0
    def testDeletePostHook(self):
        def test_func1(x):
            return x

        def test_func2(x):
            return x

        test_workflow = workflow.BaseWorkflow(label='unused',
                                              settings_path=None)

        test_workflow.add_post_hook(test_func1)
        test_workflow.add_post_hook(test_func2)
        test_workflow.delete_post_hook(0)

        self.assertEqual(test_workflow._post_job_hooks, [(test_func2, {})])
Exemplo n.º 9
0
    def testInsertPostHook_functionWithKwargs_insertsHook(self):
        def test_func1(x):
            return x

        def test_func2(x):
            return x

        test_workflow = workflow.BaseWorkflow(label='unused',
                                              settings_path=None)

        test_workflow.add_pre_hook(test_func1)
        test_workflow.insert_pre_hook(0, test_func2, {'kwarg': 'kwarg_value'})

        self.assertEqual(test_workflow._pre_job_hooks[0],
                         (test_func2, {'kwarg': 'kwarg_value'}))