Exemplo n.º 1
0
    def test_start(self):
        lw = LogWatcher('workdir/test.log', _reactor=self.reactor)
        lw._start = mock.Mock()

        lw.start()
        self.reactor.spawnProcess.assert_called()
        self.assertTrue(os.path.exists('workdir/test.log'))
        self.assertTrue(lw.running)
Exemplo n.º 2
0
    def test_start(self):
        lw = LogWatcher('workdir/test.log', _reactor=self.reactor)
        lw._start = mock.Mock()

        lw.start()
        self.reactor.spawnProcess.assert_called()
        self.assertTrue(os.path.exists('workdir/test.log'))
        self.assertTrue(lw.running)
Exemplo n.º 3
0
    def test_matches_lines(self):
        lines_and_expected = [
            (b'reconfig aborted without making any changes', ReconfigError()),
            (b'WARNING: reconfig partially applied; master may malfunction',
             ReconfigError()),
            (b'Server Shut Down', ReconfigError()),
            (b'BuildMaster startup failed', BuildmasterStartupError()),
            (b'message from master: attached', 'worker'),
            (b'configuration update complete', 'buildmaster'),
            (b'BuildMaster is running', 'buildmaster'),
        ]

        for line, expected in lines_and_expected:
            lw = LogWatcher('workdir/test.log',
                            timeout=5,
                            _reactor=self.reactor)
            d = lw.start()
            lw.lineReceived(line)

            if isinstance(expected, Exception):
                with self.assertRaises(type(expected)):
                    yield d
            else:
                res = yield d
                self.assertEqual(res, expected)
Exemplo n.º 4
0
 def test_failure_after_timeout(self):
     lw = LogWatcher('workdir/test.log', timeout=5, _reactor=self.reactor)
     d = lw.start()
     self.reactor.advance(5.1)
     lw.lineReceived(b'BuildMaster is running')
     with self.assertRaises(BuildmasterTimeoutError):
         yield d
Exemplo n.º 5
0
 def test_success_before_timeout(self):
     lw = LogWatcher('workdir/test.log', timeout=5, _reactor=self.reactor)
     d = lw.start()
     self.reactor.advance(4.9)
     lw.lineReceived(b'BuildMaster is running')
     res = yield d
     self.assertEqual(res, 'buildmaster')
Exemplo n.º 6
0
    def run(self, basedir, quiet):
        # Returns "Microsoft" for Vista and "Windows" for other versions
        if platform.system() in ("Windows", "Microsoft"):
            print "Reconfig (through SIGHUP) is not supported on Windows."
            print "The 'buildbot debugclient' tool can trigger a reconfig"
            print "remotely, but requires Gtk+ libraries to run."
            return

        with open(os.path.join(basedir, "twistd.pid"), "rt") as f:
            self.pid = int(f.read().strip())
        if quiet:
            os.kill(self.pid, signal.SIGHUP)
            return

        # keep reading twistd.log. Display all messages between "loading
        # configuration from ..." and "configuration update complete" or
        # "I will keep using the previous config file instead.", or until
        # 10 seconds have elapsed.

        self.sent_signal = False
        reactor.callLater(0.2, self.sighup)

        lw = LogWatcher(os.path.join(basedir, "twistd.log"))
        d = lw.start()
        d.addCallbacks(self.success, self.failure)
        d.addBoth(lambda _: self.rc)
        return d
Exemplo n.º 7
0
    def run(self, basedir, quiet):
        # Returns "Microsoft" for Vista and "Windows" for other versions
        if platform.system() in ("Windows", "Microsoft"):
            print "Reconfig (through SIGHUP) is not supported on Windows."
            print "The 'buildbot debugclient' tool can trigger a reconfig"
            print "remotely, but requires Gtk+ libraries to run."
            return

        with open(os.path.join(basedir, "twistd.pid"), "rt") as f:
            self.pid = int(f.read().strip())
        if quiet:
            os.kill(self.pid, signal.SIGHUP)
            return

        # keep reading twistd.log. Display all messages between "loading
        # configuration from ..." and "configuration update complete" or
        # "I will keep using the previous config file instead.", or until
        # 10 seconds have elapsed.

        self.sent_signal = False
        reactor.callLater(0.2, self.sighup)

        lw = LogWatcher(os.path.join(basedir, "twistd.log"))
        d = lw.start()
        d.addCallbacks(self.success, self.failure)
        d.addBoth(lambda _ : self.rc)
        return d
Exemplo n.º 8
0
 def test_failure_after_timeout(self):
     lw = LogWatcher('workdir/test.log', timeout=5, _reactor=self.reactor)
     d = lw.start()
     self.reactor.advance(5.1)
     lw.lineReceived(b'BuildMaster is running')
     with self.assertRaises(BuildmasterTimeoutError):
         yield d
Exemplo n.º 9
0
 def test_success_before_timeout(self):
     lw = LogWatcher('workdir/test.log', timeout=5, _reactor=self.reactor)
     d = lw.start()
     self.reactor.advance(4.9)
     lw.lineReceived(b'BuildMaster is running')
     res = yield d
     self.assertEqual(res, 'buildmaster')
Exemplo n.º 10
0
 def follow(self, basedir):
     self.rc = 0
     print "Following twistd.log until startup finished.."
     lw = LogWatcher(os.path.join(basedir, "twistd.log"))
     d = lw.start()
     d.addCallbacks(self._success, self._failure)
     reactor.run()
     return self.rc
Exemplo n.º 11
0
 def follow(self, basedir, timeout=None):
     self.rc = 0
     self._timeout = timeout if timeout else 10.0
     print("Following twistd.log until startup finished..")
     lw = LogWatcher(os.path.join(basedir, "twistd.log"),
                     timeout=self._timeout)
     d = lw.start()
     d.addCallbacks(self._success, self._failure)
     reactor.run()
     return self.rc
Exemplo n.º 12
0
 def follow(self):
     from twisted.internet import reactor
     from buildbot.scripts.logwatcher import LogWatcher
     self.rc = 0
     print "Following twistd.log until startup finished.."
     lw = LogWatcher("twistd.log")
     d = lw.start()
     d.addCallbacks(self._success, self._failure)
     reactor.run()
     return self.rc
Exemplo n.º 13
0
 def follow(self, basedir, timeout=None):
     self.rc = 0
     self._timeout = timeout if timeout else 10.0
     print("Following twistd.log until startup finished..")
     lw = LogWatcher(os.path.join(basedir, "twistd.log"),
                     timeout=self._timeout)
     d = lw.start()
     d.addCallbacks(self._success, self._failure)
     reactor.run()
     return self.rc
Exemplo n.º 14
0
    def run(self, basedir, quiet, timeout=None):
        # Returns "Microsoft" for Vista and "Windows" for other versions
        if platform.system() in ("Windows", "Microsoft"):
            print("Reconfig (through SIGHUP) is not supported on Windows.")
            return None

        with open(os.path.join(basedir, "twistd.pid"), "rt",
                  encoding='utf-8') as f:
            self.pid = int(f.read().strip())
        if quiet:
            os.kill(self.pid, signal.SIGHUP)
            return None

        # keep reading twistd.log. Display all messages between "loading
        # configuration from ..." and "configuration update complete" or
        # "I will keep using the previous config file instead.", or until
        # `timeout` seconds have elapsed.

        self.sent_signal = False
        reactor.callLater(0.2, self.sighup)

        lw = LogWatcher(os.path.join(basedir, "twistd.log"), timeout=timeout)

        try:
            yield lw.start()
            print("Reconfiguration appears to have completed successfully")
            return 0
        except BuildmasterTimeoutError:
            print("Never saw reconfiguration finish.")
        except ReconfigError:
            print(
                rewrap("""\
                Reconfiguration failed. Please inspect the master.cfg file for
                errors, correct them, then try 'buildbot reconfig' again.
                """))
        except IOError:
            # we were probably unable to open the file in the first place
            self.sighup()
        except Exception as e:
            print(f"Error while following twistd.log: {e}")

        return 1
Exemplo n.º 15
0
    def test_matches_lines(self):
        lines_and_expected = [
            (b'reconfig aborted without making any changes', ReconfigError()),
            (b'WARNING: reconfig partially applied; master may malfunction',
             ReconfigError()),
            (b'Server Shut Down', ReconfigError()),
            (b'BuildMaster startup failed', BuildmasterStartupError()),
            (b'message from master: attached', 'worker'),
            (b'configuration update complete', 'buildmaster'),
            (b'BuildMaster is running', 'buildmaster'),
        ]

        for line, expected in lines_and_expected:
            lw = LogWatcher('workdir/test.log', timeout=5,
                            _reactor=self.reactor)
            d = lw.start()
            lw.lineReceived(line)

            if isinstance(expected, Exception):
                with self.assertRaises(type(expected)):
                    yield d
            else:
                res = yield d
                self.assertEqual(res, expected)