def main():
    parser = optparse.OptionParser()
    parser.add_option('--pulse-cfg',
                      dest='pulse_cfg',
                      default='',
                      help='Pulse config')
    parser.add_option('--pulse-cfg-section',
                      dest='pulse_cfg_section',
                      default='pulse',
                      help='Pulse config section')
    options, args = parser.parse_args()

    pulse = NormalizedBuildConsumer(applabel='translator_test_consumer_%s' %
                                    uuid.uuid4(),
                                    connect=False)
    pulse.configure(topic=['build.#', 'unittest.#', 'talos.#'],
                    callback=on_pulse_message,
                    durable=False)
    if options.pulse_cfg:
        if not os.path.exists(options.pulse_cfg):
            print 'Config file does not exist!'
            return
        cfg = ConfigParser.ConfigParser()
        cfg.read(options.pulse_cfg)
        pulse.config = PulseConfiguration.read_from_config(
            cfg, options.pulse_cfg_section)

    pulse.listen()
Example #2
1
    def __init__(self,
                 configfile,
                 pulse_authfile,
                 debug,
                 log_folder,
                 logger,
                 message=None,
                 display_only=False):

        self.config = JSONFile(configfile).read()
        self.debug = debug
        self.log_folder = log_folder
        self.logger = logger
        self.display_only = display_only
        self.test_message = message

        self.jenkins = jenkins.Jenkins(self.config['jenkins']['url'],
                                       self.config['jenkins']['username'],
                                       self.config['jenkins']['password'])

        # When a local pulse message is used, return immediately
        if self.test_message:
            data = JSONFile(self.test_message).read()
            self.on_build(data)
            return

        # Load Pulse Guardian authentication from config file
        if not os.path.exists(pulse_authfile):
            print 'Config file for Mozilla Pulse does not exist!'
            return

        pulse_cfgfile = ConfigParser.ConfigParser()
        pulse_cfgfile.read(pulse_authfile)
        pulse_cfg = PulseConfiguration.read_from_config(pulse_cfgfile)

        label = '%s/%s' % (socket.getfqdn(), self.config['pulse']['applabel'])
        self.monitor = start_pulse_monitor(
            buildCallback=self.on_build,
            testCallback=None,
            pulseCallback=self.on_debug if self.debug else None,
            label=label,
            trees=self.config['pulse']['branches'],
            platforms=self.config['pulse']['platforms'],
            products=self.config['pulse']['products'],
            buildtypes=None,
            tests=None,
            buildtags=self.config['pulse']['tags'],
            logger=self.logger,
            pulse_cfg=pulse_cfg)

        try:
            while self.monitor.is_alive():
                self.monitor.join(1.0)
        except (KeyboardInterrupt, SystemExit):
            self.logger.info('Shutting down Pulse listener')
Example #3
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('--pidfile', dest='pidfile',
                      default='translator.pid',
                      help='path to file for logging pid')
    parser.add_option('--logfile', dest='logfile',
                      default='stdout.log',
                      help='path to file for stdout logging')
    parser.add_option('--logdir', dest='logdir',
                      default='logs',
                      help='directory to store other log files')
    parser.add_option('--daemon', dest='daemon', action='store_true',
                      help='run as daemon (posix only)')
    parser.add_option('--durable',
                      dest='durable',
                      action='store_true',
                      default=False,
                      help='register a durable queue')
    parser.add_option('--display-only',
                      dest='display_only',
                      action='store_true',
                      default=False,
                      help='only display build properties and don\'t add '
                      'jobs to the queue')
    parser.add_option('--pulse-cfg',
                      dest='pulse_cfg',
                      default='',
                      help='optional config file containing optional sections '
                      '[consumer] and [publisher] for nondefault Pulse '
                      'configs')
    options, args = parser.parse_args()

    pulse_cfgs = {'consumer': None, 'publisher': None}
    if options.pulse_cfg:
        if not os.path.exists(options.pulse_cfg):
            print 'Config file does not exist!'
            return
        pulse_cfgfile = ConfigParser.ConfigParser()
        pulse_cfgfile.read(options.pulse_cfg)
        for section in pulse_cfgs.keys():
            pulse_cfgs[section] = PulseConfiguration.read_from_config(
                pulse_cfgfile, section)

    if options.daemon:
        if os.access(options.logfile, os.F_OK):
            os.remove(options.logfile)
        createDaemon(options.pidfile, options.logfile)

        f = open(options.pidfile, 'w')
        f.write("%d\n" % os.getpid())
        f.close()

    service = PulseBuildbotTranslator(durable=options.durable,
                                      logdir=options.logdir,
                                      display_only=options.display_only,
                                      consumer_cfg=pulse_cfgs['consumer'],
                                      publisher_cfg=pulse_cfgs['publisher'])
    service.start()
 def test_config(self):
     cfg = configparser.ConfigParser()
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.verify_defaults(pulse_cfg)
     cfg.add_section('pulse')
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.verify_defaults(pulse_cfg)
     cfg.set('pulse', 'user', 'foo')
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.assertEqual(pulse_cfg.user, 'foo')
     self.assertEqual(pulse_cfg.port, DEFAULT_SSL_PORT)
     self.verify_defaults(pulse_cfg, ['user'])
     cfg.set('pulse', 'ssl', 'off')
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.assertEqual(pulse_cfg.ssl, False)
     self.assertEqual(pulse_cfg.port, DEFAULT_PORT)
     self.verify_defaults(pulse_cfg, ['user', 'ssl', 'port'])
     cfg.set('pulse', 'port', '5555')
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.assertEqual(pulse_cfg.port, 5555)
     self.verify_defaults(pulse_cfg, ['user', 'ssl', 'port'])
Example #5
0
 def test_config(self):
     cfg = ConfigParser.ConfigParser()
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.verify_defaults(pulse_cfg)
     cfg.add_section('pulse')
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.verify_defaults(pulse_cfg)
     cfg.set('pulse', 'user', 'foo')
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.assertEqual(pulse_cfg.user, 'foo')
     self.assertEqual(pulse_cfg.port, DEFAULT_SSL_PORT)
     self.verify_defaults(pulse_cfg, ['user'])
     cfg.set('pulse', 'ssl', 'off')
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.assertEqual(pulse_cfg.ssl, False)
     self.assertEqual(pulse_cfg.port, DEFAULT_PORT)
     self.verify_defaults(pulse_cfg, ['user', 'ssl', 'port'])
     cfg.set('pulse', 'port', '5555')
     pulse_cfg = PulseConfiguration.read_from_config(cfg)
     self.assertEqual(pulse_cfg.port, 5555)
     self.verify_defaults(pulse_cfg, ['user', 'ssl', 'port'])
Example #6
0
    def __init__(self, configfile, pulse_authfile, debug, log_folder, logger,
                 message=None, display_only=False):

        self.config = JSONFile(configfile).read()
        self.debug = debug
        self.log_folder = log_folder
        self.logger = logger
        self.display_only = display_only
        self.test_message = message

        self.jenkins = jenkins.Jenkins(self.config['jenkins']['url'],
                                       self.config['jenkins']['username'],
                                       self.config['jenkins']['password'])

        # When a local pulse message is used, return immediately
        if self.test_message:
            data = JSONFile(self.test_message).read()
            self.on_build(data)
            return

        # Load Pulse Guardian authentication from config file
        if not os.path.exists(pulse_authfile):
            print 'Config file for Mozilla Pulse does not exist!'
            return

        pulse_cfgfile = ConfigParser.ConfigParser()
        pulse_cfgfile.read(pulse_authfile)
        pulse_cfg = PulseConfiguration.read_from_config(pulse_cfgfile)

        label = '%s/%s' % (socket.getfqdn(), self.config['pulse']['applabel'])
        self.monitor = start_pulse_monitor(buildCallback=self.on_build,
                                           testCallback=None,
                                           pulseCallback=self.on_debug if self.debug else None,
                                           label=label,
                                           trees=self.config['pulse']['branches'],
                                           platforms=self.config['pulse']['platforms'],
                                           products=self.config['pulse']['products'],
                                           buildtypes=None,
                                           tests=None,
                                           buildtags=self.config['pulse']['tags'],
                                           logger=self.logger,
                                           pulse_cfg=pulse_cfg)

        try:
            while self.monitor.is_alive():
                self.monitor.join(1.0)
        except (KeyboardInterrupt, SystemExit):
            self.logger.info('Shutting down Pulse listener')
Example #7
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('--pulse-cfg', dest='pulse_cfg', default='',
                      help='Pulse config')
    parser.add_option('--pulse-cfg-section', dest='pulse_cfg_section',
                      default='pulse', help='Pulse config section')
    options, args = parser.parse_args()

    pulse = NormalizedBuildConsumer(applabel='translator_test_consumer_%s'
                                    % uuid.uuid4(), connect=False)
    pulse.configure(topic=['build.#', 'unittest.#', 'talos.#'],
                    callback=on_pulse_message,
                    durable=False)
    if options.pulse_cfg:
        if not os.path.exists(options.pulse_cfg):
            print 'Config file does not exist!'
            return
        cfg = ConfigParser.ConfigParser()
        cfg.read(options.pulse_cfg)
        pulse.config = PulseConfiguration.read_from_config(
            cfg, options.pulse_cfg_section)

    pulse.listen()
def main():
    parser = optparse.OptionParser()
    parser.add_option('--pidfile',
                      dest='pidfile',
                      default='translator.pid',
                      help='path to file for logging pid')
    parser.add_option('--logfile',
                      dest='logfile',
                      default='stdout.log',
                      help='path to file for stdout logging')
    parser.add_option('--logdir',
                      dest='logdir',
                      default='logs',
                      help='directory to store other log files')
    parser.add_option('--daemon',
                      dest='daemon',
                      action='store_true',
                      help='run as daemon (posix only)')
    parser.add_option('--durable',
                      dest='durable',
                      action='store_true',
                      default=False,
                      help='register a durable queue')
    parser.add_option('--display-only',
                      dest='display_only',
                      action='store_true',
                      default=False,
                      help='only display build properties and don\'t add '
                      'jobs to the queue')
    parser.add_option('--pulse-cfg',
                      dest='pulse_cfg',
                      default='',
                      help='optional config file containing optional sections '
                      '[consumer] and [publisher] for nondefault Pulse '
                      'configs')
    parser.add_option('--push-message',
                      dest='message',
                      help='path to file of a Pulse message to process')
    parser.add_option('--label',
                      dest='label',
                      help='label to use for pulse queue')

    options, args = parser.parse_args()

    pulse_cfgs = {'consumer': None, 'publisher': None}
    if options.pulse_cfg:
        if not os.path.exists(options.pulse_cfg):
            print 'Config file does not exist!'
            return
        pulse_cfgfile = ConfigParser.ConfigParser()
        pulse_cfgfile.read(options.pulse_cfg)
        for section in pulse_cfgs.keys():
            pulse_cfgs[section] = PulseConfiguration.read_from_config(
                pulse_cfgfile, section)
        if os.environ.get('pulseuser'):
            setattr(pulse_cfgs['consumer'], 'user', os.environ['pulseuser'])
            setattr(pulse_cfgs['publisher'], 'user', os.environ['pulseuser'])
        if os.environ.get('pulsepassword'):
            setattr(pulse_cfgs['consumer'], 'password',
                    os.environ['pulsepassword'])
            setattr(pulse_cfgs['publisher'], 'password',
                    os.environ['pulsepassword'])

    if options.daemon:
        if os.access(options.logfile, os.F_OK):
            os.remove(options.logfile)
        createDaemon(options.pidfile, options.logfile)

        f = open(options.pidfile, 'w')
        f.write("%d\n" % os.getpid())
        f.close()

    service = PulseBuildbotTranslator(durable=options.durable,
                                      logdir=options.logdir,
                                      message=options.message,
                                      label=options.label,
                                      display_only=options.display_only,
                                      consumer_cfg=pulse_cfgs['consumer'],
                                      publisher_cfg=pulse_cfgs['publisher'])
    service.start()