コード例 #1
0
ファイル: test_bot.py プロジェクト: zjtheone/buildbot
    def test_startCommand_interruptCommand(self):
        # set up a fake step to receive updates
        st = FakeStep()

        # patch runprocess to pretend to sleep (it will really just hang forever,
        # except that we interrupt it)
        self.patch_runprocess(
            Expect(['sleep', '10'], os.path.join(
                self.basedir, 'sb', 'workdir')) + {'hdr': 'headers'} +
            {'wait': True})

        d = defer.succeed(None)

        def do_start(_):
            return self.sb.callRemote(
                "startCommand", FakeRemote(st), "13", "shell",
                dict(command=['sleep', '10'], workdir='workdir'))

        d.addCallback(do_start)

        # wait a jiffy..
        def do_wait(_):
            d = defer.Deferred()
            reactor.callLater(0.01, d.callback, None)
            return d

        d.addCallback(do_wait)

        # and then interrupt the step
        def do_interrupt(_):
            return self.sb.callRemote("interruptCommand", "13", "tl/dr")

        d.addCallback(do_interrupt)

        d.addCallback(lambda _: st.wait_for_finish())

        def check(_):
            self.assertEqual(st.actions, [
                ['update', [[{
                    'hdr': 'headers'
                }, 0]]],
                ['update', [[{
                    'hdr': 'killing'
                }, 0]]],
                ['update', [[{
                    'rc': -1
                }, 0]]],
                ['complete', None],
            ])

        d.addCallback(check)
        return d
コード例 #2
0
ファイル: test_msgpack.py プロジェクト: ffdybuster/buildbot
    def test_call_start_command_shell_success(self):
        self.setup_with_worker_for_builder()

        # patch runprocess to handle the 'echo', below
        workdir = os.path.join('basedir', 'test_basedir')
        self.patch_runprocess(
            Expect(['echo'], workdir) +
            {'hdr': 'headers'} +
            {'stdout': 'hello\n'} +
            {'rc': 0} +
            0,)

        yield self.send_message({
            'op': 'start_command',
            'seq_number': 1,
            'command_id': '123',
            'command_name': 'shell',
            'args': {'command': ['echo'], 'workdir': workdir}
        })

        self.assert_sent_messages([
            {
                'op': 'update',
                'args': [[{'hdr': 'headers'}, 0]],
                'command_id': '123',
                'seq_number': 0
            }, {
                'op': 'update',
                'args': [[{'stdout': 'hello\n'}, 0]],
                'command_id': '123',
                'seq_number': 1
            }, {
                'op': 'update',
                'args': [[{'rc': 0}, 0]],
                'command_id': '123',
                'seq_number': 2
            }, {
                'op': 'update',
                'args': [[{'elapsed': 0}, 0]],
                'command_id': '123',
                'seq_number': 3
            }, {
                'op': 'complete',
                'args': None,
                'command_id': '123',
                'seq_number': 4
            }, {
                'op': 'response', 'seq_number': 1, 'result': None
            }
        ])
コード例 #3
0
    def test_simple_posix(self):
        file_path = os.path.join(self.basedir, 'remove')
        self.make_command(fs.RemoveDirectory, {'paths': [file_path]}, True)

        self.patch_runprocess(
            Expect(["rm", "-rf", file_path], self.basedir, sendRC=0, timeout=120)
            + {'hdr': 'headers'} + {'stdout': ''} + {'rc': 0}
            + 0,
        )

        yield self.run_command()

        self.assertEqual(self.get_updates()[-2], {'rc': 0})
        self.assertIn('elapsed', self.get_updates()[-1])
コード例 #4
0
    def test_rm_after_failed(self):
        dir = os.path.join(self.basedir, 'remove')
        self.make_command(fs.RemoveDirectory, {'paths': [dir]}, True)

        self.patch_runprocess(
            Expect(["rm", "-rf", dir], self.basedir, sendRC=0,
                   timeout=120)
            + {'hdr': 'headers'} + {'stderr': 'permission denied'} + {'rc': 1}
            + 1,
            Expect(['chmod', '-Rf', 'u+rwx', dir], self.basedir,
                   sendRC=0, timeout=120)
            + {'hdr': 'headers'} + {'stdout': ''} + {'rc': 0}
            + 0,
            Expect(["rm", "-rf", dir], self.basedir, sendRC=0,
                   timeout=120)
            + {'hdr': 'headers'} + {'stdout': ''} + {'rc': 1}
            + 1,
        )

        yield self.run_command()

        self.assertEqual(self.get_updates()[-2], {'rc': 1})
        self.assertIn('elapsed', self.get_updates()[-1])
コード例 #5
0
    def test_simple(self):
        self.make_command(shell.WorkerShellCommand, dict(
            command=['echo', 'hello'],
            workdir='workdir',
        ))

        self.patch_runprocess(
            Expect(['echo', 'hello'], self.basedir_workdir)
            + {'hdr': 'headers'} + {'stdout': 'hello\n'} + {'rc': 0}
            + 0,
        )

        yield self.run_command()

        # note that WorkerShellCommand does not add any extra updates of it own
        self.assertUpdates(
            [{'hdr': 'headers'}, {'stdout': 'hello\n'}, {'rc': 0}],
            self.builder.show())
コード例 #6
0
    def test_simple(self):
        workdir = os.path.join(self.basedir, 'workdir')
        self.make_command(shell.WorkerShellCommand, {
            'command': ['echo', 'hello'],
            'workdir': workdir
        })

        self.patch_runprocess(
            Expect(['echo', 'hello'], self.basedir_workdir) +
            {'hdr': 'headers'} + {'stdout': 'hello\n'} + {'rc': 0} + 0, )

        yield self.run_command()

        # note that WorkerShellCommand does not add any extra updates of it own
        self.assertUpdates([{
            'hdr': 'headers'
        }, {
            'stdout': 'hello\n'
        }, {
            'rc': 0
        }], self.protocol_command.show())
コード例 #7
0
    def test_startCommand_failure(self):
        # set up a fake step to receive updates
        st = FakeStep()

        # patch runprocess to generate a failure
        self.patch_runprocess(
            Expect(['sleep', '10'], os.path.join(self.basedir, 'wfb',
                                                 'workdir')) +
            failure.Failure(Exception("Oops")))
        # patch the log.err, otherwise trial will think something *actually*
        # failed
        self.patch(log, "err", lambda f: None)

        yield self.wfb.callRemote(
            "startCommand", FakeRemote(st), "13", "shell",
            dict(command=['sleep', '10'], workdir='workdir'))

        yield st.wait_for_finish()

        self.assertEqual(st.actions[1][0], 'complete')
        self.assertTrue(isinstance(st.actions[1][1], failure.Failure))
コード例 #8
0
    def test_startCommand(self):
        # set up a fake step to receive updates
        st = FakeStep()

        # patch runprocess to handle the 'echo', below
        self.patch_runprocess(
            Expect(['echo', 'hello'],
                   os.path.join(self.basedir, 'wfb', 'workdir')) +
            {'hdr': 'headers'} + {'stdout': 'hello\n'} + {'rc': 0} + 0, )

        d = defer.succeed(None)

        def do_start(_):
            return self.wfb.callRemote(
                "startCommand", FakeRemote(st), "13", "shell",
                dict(command=['echo', 'hello'], workdir='workdir'))

        d.addCallback(do_start)
        d.addCallback(lambda _: st.wait_for_finish())

        def check(_):
            self.assertEqual(st.actions, [
                ['update', [[{
                    'hdr': 'headers'
                }, 0]]],
                ['update', [[{
                    'stdout': 'hello\n'
                }, 0]]],
                ['update', [[{
                    'rc': 0
                }, 0]]],
                ['update', [[{
                    'elapsed': 1
                }, 0]]],
                ['complete', None],
            ])

        d.addCallback(check)
        return d
コード例 #9
0
    def test_startCommand_interruptCommand(self):
        # set up a fake step to receive updates
        st = FakeStep()

        # patch runprocess to pretend to sleep (it will really just hang forever,
        # except that we interrupt it)
        self.patch_runprocess(
            Expect(['sleep', '10'], os.path.join(
                self.basedir, 'wfb', 'workdir')) + {'hdr': 'headers'} +
            {'wait': True})

        yield self.wfb.callRemote(
            "startCommand", FakeRemote(st), "13", "shell",
            dict(command=['sleep', '10'], workdir='workdir'))

        # wait a jiffy..
        d = defer.Deferred()
        reactor.callLater(0.01, d.callback, None)
        yield d

        # and then interrupt the step
        yield self.wfb.callRemote("interruptCommand", "13", "tl/dr")

        yield st.wait_for_finish()

        self.assertEqual(st.actions, [
            ['update', [[{
                'hdr': 'headers'
            }, 0]]],
            ['update', [[{
                'hdr': 'killing'
            }, 0]]],
            ['update', [[{
                'rc': -1
            }, 0]]],
            ['complete', None],
        ])
コード例 #10
0
ファイル: test_msgpack.py プロジェクト: ffdybuster/buildbot
    def test_call_interrupt_command_success(self):
        self.setup_with_worker_for_builder()
        self.protocol.factory.command.doInterrupt = mock.Mock()

        # patch runprocess to pretend to sleep (it will really just hang forever,
        # except that we interrupt it)
        workdir = os.path.join('basedir', 'test_basedir')
        self.patch_runprocess(
            Expect(['sleep', '10'], workdir) +
            {'hdr': 'headers'} +
            {'wait': True}
        )

        yield self.send_message({
            'op': 'start_command',
            'seq_number': 1,
            'command_id': '123',
            'command_name': 'shell',
            'args': {'command': ['sleep', '10'], 'workdir': workdir}
        })

        # wait a jiffy..
        d = defer.Deferred()
        reactor.callLater(0.01, d.callback, None)
        yield d

        self.assert_sent_messages([
            {
                'op': 'update',
                'seq_number': 0,
                'command_id': '123',
                'args': [[{'hdr': 'headers'}, 0]]
            }, {
                'op': 'response',
                'seq_number': 1,
                'result': None
            }
        ])

        yield self.send_message({
            'op': 'interrupt_command',
            'seq_number': 1,
            'command_id': '123',
            'why': 'test_reason'
        })

        self.assert_sent_messages([
            {
                'op': 'update',
                'seq_number': 1,
                'command_id': '123',
                'args': [[{'hdr': 'killing'}, 0]],
            }, {
                'op': 'update',
                'seq_number': 2,
                'command_id': '123',
                'args': [[{'rc': -1}, 0]]
            }, {
                'op': 'complete', 'seq_number': 3, 'command_id': '123', 'args': None
            }, {
                'op': 'response', 'seq_number': 1, 'result': None
            }
    ])