aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_process_debug.py
blob: 1170ca667ba64c7714483fd8a3567ba420282b56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# This file is part of Buildbot.  Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

import mock
from twisted.trial import unittest
from twisted.internet import defer
from twisted.application import service
from buildbot.process import debug
from buildbot import config

class FakeManhole(service.Service):
    pass

class TestDebugServices(unittest.TestCase):

    def setUp(self):
        self.master = mock.Mock(name='master')
        self.config = config.MasterConfig()

    @defer.inlineCallbacks
    def test_reconfigService_debug(self):
        # mock out PBManager
        self.master.pbmanager = pbmanager = mock.Mock()
        registration = mock.Mock(name='registration')
        registration.unregister = mock.Mock(name='unregister',
                    side_effect=lambda : defer.succeed(None))
        pbmanager.register.return_value = registration

        ds = debug.DebugServices(self.master)
        ds.startService()

        # start off with no debug password
        self.config.slavePortnum = '9824'
        self.config.debugPassword = None
        yield ds.reconfigService(self.config)

        self.assertFalse(pbmanager.register.called)

        # set the password, and see it register
        self.config.debugPassword = 'seeeekrit'
        yield ds.reconfigService(self.config)

        self.assertTrue(pbmanager.register.called)
        self.assertEqual(pbmanager.register.call_args[0][:3],
                ('9824', 'debug', 'seeeekrit'))
        factory = pbmanager.register.call_args[0][3]
        self.assertIsInstance(factory(mock.Mock(), mock.Mock()),
                debug.DebugPerspective)

        # change the password, and see it re-register
        self.config.debugPassword = 'lies'
        pbmanager.register.reset_mock()
        yield ds.reconfigService(self.config)

        self.assertTrue(registration.unregister.called)
        self.assertTrue(pbmanager.register.called)
        self.assertEqual(pbmanager.register.call_args[0][:3],
                ('9824', 'debug', 'lies'))

        # remove the password, and see it unregister
        self.config.debugPassword = None
        pbmanager.register.reset_mock()
        registration.unregister.reset_mock()
        yield ds.reconfigService(self.config)

        self.assertTrue(registration.unregister.called)
        self.assertFalse(pbmanager.register.called)

        # re-register to test stopService
        self.config.debugPassword = 'confusion'
        pbmanager.register.reset_mock()
        yield ds.reconfigService(self.config)

        # stop the service, and see that it unregisters
        pbmanager.register.reset_mock()
        registration.unregister.reset_mock()
        yield ds.stopService()

        self.assertTrue(registration.unregister.called)

    @defer.inlineCallbacks
    def test_reconfigService_manhole(self):
        master = mock.Mock(name='master')
        ds = debug.DebugServices(master)
        ds.startService()

        # start off with no manhole
        yield ds.reconfigService(self.config)

        # set a manhole, fire it up
        self.config.manhole = manhole = FakeManhole()
        yield ds.reconfigService(self.config)

        self.assertTrue(manhole.running)
        self.assertIdentical(manhole.master, master)

        # unset it, see it stop
        self.config.manhole = None
        yield ds.reconfigService(self.config)

        self.assertFalse(manhole.running)
        self.assertIdentical(manhole.master, None)

        # re-start to test stopService
        self.config.manhole = manhole
        yield ds.reconfigService(self.config)

        # stop the service, and see that it unregisters
        yield ds.stopService()

        self.assertFalse(manhole.running)
        self.assertIdentical(manhole.master, None)


class TestDebugPerspective(unittest.TestCase):

    def setUp(self):
        self.master = mock.Mock()
        self.persp = debug.DebugPerspective(self.master)

    def test_attached(self):
        self.assertIdentical(self.persp.attached(mock.Mock()), self.persp)

    def test_detached(self):
        self.persp.detached(mock.Mock()) # just shouldn't crash

    def test_perspective_reload(self):
        d = defer.maybeDeferred(lambda : self.persp.perspective_reload())
        def check(_):
            self.master.reconfig.assert_called_with()
        d.addCallback(check)
        return d

    # remaining methods require IControl adapters or other weird stuff.. TODO