Esempio n. 1
0
    def test_report_not_matched_worker(self):
        g = WorkerMissingGenerator(workers=['other'])

        report = yield g.generate(self.master, None, 'worker.98.complete',
                                  self._get_worker_dict('myworker'))

        self.assertIsNone(report)
Esempio n. 2
0
    def test_report_matched_worker(self, worker_filter):
        g = WorkerMissingGenerator(workers=worker_filter)

        report = yield g.generate(self.master, None, 'worker.98.complete',
                                  self._get_worker_dict('myworker'))

        self.assertEqual(report['users'], ['*****@*****.**'])
        self.assertIn(b"worker named myworker went away", report['body'])
Esempio n. 3
0
def masterConfig(build_set_summary):
    c = {}
    from buildbot.config import BuilderConfig
    from buildbot.process.factory import BuildFactory
    from buildbot.plugins import steps, schedulers, reporters
    c['schedulers'] = [
        schedulers.AnyBranchScheduler(
            name="sched",
            builderNames=["testy"])
    ]
    f = BuildFactory()
    f.addStep(steps.ShellCommand(command='echo hello'))
    c['builders'] = [
        BuilderConfig(name="testy",
                      workernames=["local1"],
                      factory=f)
    ]

    formatter = MessageFormatter(template='This is a message.')
    formatter_worker = MessageFormatterMissingWorker(template='No worker.')

    if build_set_summary:
        generators_mail = [
            BuildSetStatusGenerator(mode='all'),
            WorkerMissingGenerator(workers='all'),
        ]
        generators_pushover = [
            BuildSetStatusGenerator(mode='all', message_formatter=formatter),
            WorkerMissingGenerator(workers=['local1'], message_formatter=formatter_worker),
        ]
    else:
        generators_mail = [
            BuildStatusGenerator(mode='all'),
            WorkerMissingGenerator(workers='all'),
        ]
        generators_pushover = [
            BuildStatusGenerator(mode='all', message_formatter=formatter),
            WorkerMissingGenerator(workers=['local1'], message_formatter=formatter_worker),
        ]

    c['services'] = [
        reporters.MailNotifier("*****@*****.**", generators=generators_mail),
        reporters.PushoverNotifier('1234', 'abcd', generators=generators_pushover)
    ]
    return c
    def test_report(self):

        g = WorkerMissingGenerator(workers=['myworker'])

        worker_dict = {
            'name': 'myworker',
            'notify': ["*****@*****.**"],
            'workerinfo': {
                "admin": "myadmin"
            },
            'last_connection': "yesterday"
        }
        report = yield g.generate(self.master, None, 'worker.98.complete',
                                  worker_dict)

        self.assertEqual(report['users'], ['*****@*****.**'])
        self.assertIn(b"has noticed that the worker named myworker went away",
                      report['body'])
Esempio n. 5
0
 def _create_default_generators(self):
     return [
         BuildStatusGenerator(
             add_patch=True,
             message_formatter=MessageFormatter(template_type='html')),
         WorkerMissingGenerator(
             workers='all',
             message_formatter=MessageFormatterMissingWorker(template_type='html')),
     ]
Esempio n. 6
0
    def test_worker_missing_sends_message(self):
        generator = WorkerMissingGenerator(workers=['myworker'])
        mn = yield self.setupNotifier(generators=[generator])

        worker_dict = {
            'name': 'myworker',
            'notify': ["*****@*****.**"],
            'workerinfo': {"admin": "myadmin"},
            'last_connection': "yesterday"
        }
        yield mn._got_event(('workers', 98, 'missing'), worker_dict)

        self.assertEqual(mn.sendMessage.call_count, 1)
Esempio n. 7
0
    def setupNotifier(self, old_style=False, *args, **kwargs):
        if old_style:
            with assertProducesWarnings(
                    DeprecatedApiWarning,
                    message_pattern='have been deprecated'):
                mn = ReporterBase(*args, **kwargs)
        else:
            if 'generators' not in kwargs:
                if 'watchedWorkers' in kwargs:
                    generator = WorkerMissingGenerator(
                        workers=kwargs.pop('watchedWorkers'))
                    kwargs['generators'] = [generator]

            mn = ReporterBase(*args, **kwargs)

        mn.sendMessage = mock.Mock(spec=mn.sendMessage)
        mn.sendMessage.return_value = "<message>"
        yield mn.setServiceParent(self.master)
        yield mn.startService()
        return mn
Esempio n. 8
0
    def create_generators_from_old_args(self, mode, tags, builders, build_set_summary,
                                        message_formatter, subject, add_logs, add_patch, schedulers,
                                        branches, watched_workers,
                                        message_formatter_missing_worker):
        generators = []
        if build_set_summary:
            generators.append(BuildSetStatusGenerator(mode=mode, tags=tags, builders=builders,
                                                      schedulers=schedulers, branches=branches,
                                                      subject=subject, add_logs=add_logs,
                                                      add_patch=add_patch,
                                                      message_formatter=message_formatter))
        else:
            generators.append(BuildStatusGenerator(mode=mode, tags=tags, builders=builders,
                                                   schedulers=schedulers, branches=branches,
                                                   subject=subject, add_logs=add_logs,
                                                   add_patch=add_patch,
                                                   message_formatter=message_formatter))

        if watched_workers is not None and len(watched_workers) > 0:
            generators.append(
                WorkerMissingGenerator(workers=watched_workers,
                                       message_formatter=message_formatter_missing_worker))

        return generators
Esempio n. 9
0
 def _create_default_generators(self):
     return [
         BuildStatusGenerator(add_patch=True),
         WorkerMissingGenerator(workers='all'),
     ]
Esempio n. 10
0
 def test_unsupported_workers(self):
     g = WorkerMissingGenerator(workers='string worker')
     with self.assertRaisesConfigError(
             "workers must be 'all', or list of worker names"):
         g.check()