def setUp(self): if os.access(test_dir, os.F_OK): shutil.rmtree(test_dir) os.mkdir(test_dir) os.chdir(test_dir) os.mkdir('work_dir') hgpusher.config['hg_base_url'] = test_dir hgpusher.MQ = mq_utils.mq_util() hgpusher.config['work_dir'] = os.path.join(test_dir, 'work_dir')
def testSendRec(self): class RECEIVED(Exception): print "RECEIVED" pass def message_handler_topic1(message): print "Handling message %s of topic 1" % message raise RECEIVED def message_handler_topic2(message): print "Handling message %s of topic 2" % message raise RECEIVED raised = False # rabbitmq must be running j = {'msg':'TEST'} self.mq.send_message(message=j, routing_key='autoland.db', durable=False) listener = mq_utils.mq_util() listener.set_host('localhost') listener.set_exchange('autoland-new') listener.connect() try: # For some reason assertRaises won't work here listener.listen(queue='test-new', callback=message_handler_topic1, routing_key='autoland.db', durable=False) except RECEIVED: raised = True self.assertFalse(raised) # Now try a different routing key raised = False self.mq.send_message(message=j, routing_key='hgpusher.pushes', durable=False) listener2 = mq_utils.mq_util() listener2.set_host('localhost') listener2.set_exchange('autoland-new') listener2.connect() try: # For some reason assertRaises won't work here listener2.listen(queue='test-new', callback=message_handler_topic2, routing_key='hgpusher.pushes', durable=False) except RECEIVED: raised = True self.assertFalse(raised)
def main(): mq = mq_utils.mq_util(host=config['mq_host'], vhost=config['mq_vhost'], username=config['mq_username'], password=config['mq_password'], exchange=config['mq_exchange']) mq.connect() mq.declare_and_bind(config['mq_autoland_queue'], 'db') log.setLevel(logging.INFO) LOGHANDLER.setFormatter(LOGFORMAT) log.addHandler(LOGHANDLER) PLOGHANDLER.setLevel(logging.INFO) PLOGHANDLER.setFormatter(LOGFORMAT) plog.addHandler(PLOGHANDLER) # XXX: use argparse if len(sys.argv) > 1: for arg in sys.argv[1:]: if arg == '--purge-queue': # purge the autoland queue mq.purge_queue(config['mq_autoland_queue'], prompt=True) exit(0) elif arg == '--debug' or arg == '-d': log.setLevel(logging.DEBUG) while True: # search bugzilla for any relevant bugs bz_search_handler() next_poll = time.time() + int(config['bz_poll_frequency']) # take care of any comments that couldn't previously be posted handle_comments() while time.time() < next_poll: patchset = db.PatchSetGetNext() if patchset != None: handle_patchset(mq, patchset) # loop while we've got incoming messages while mq.get_message(config['mq_autoland_queue'], message_handler): continue time.sleep(5)
def __init__(self, branch, cache_dir, configs, user=None, password=None, dry_run=False, verbose=False, messages=True): self.config = ConfigParser.ConfigParser() self.config.read(configs) self.branch = branch self.cache_dir = cache_dir self.dry_run = dry_run self.verbose = verbose self.messages = messages self.posted_bugs = self.config.get('log', 'posted_bugs') # Set up the message queue if self.messages: self.mq = mq_utils.mq_util(host=self.config.get('mq', 'host'), vhost=self.config.get('mq', 'vhost'), username=self.config.get('mq', 'username'), password=self.config.get('mq', 'password'), exchange=self.config.get('mq', 'exchange')) self.mq.connect() # Set up bugzilla api connection self.bz_url = self.config.get('bz', 'url') self.bz = bz_utils.bz_util(self.config.get('bz', 'api_url'), self.config.get('bz', 'url'), None, self.config.get('bz', 'username'), self.config.get('bz', 'password')) # Set up Self-Serve API self.self_serve_api_url = self.config.get('self_serve', 'url') self.user = self.config.get('self_serve', 'user') self.password = self.config.get('self_serve', 'password') # Set up database handler self.scheduler_db = DBHandler( self.config.get('databases', 'scheduler_db_url'))
import shutil from tempfile import mkdtemp from mercurial import error, lock # For lockfile on working dirs from util.hg import mercurial, apply_and_push, cleanOutgoingRevs, out, \ remove_path, HgUtilError, update, get_revision from util.retry import retry from utils import bz_utils, mq_utils, common, ldap_utils base_dir = common.get_base_dir(__file__) LOGFORMAT = '%(asctime)s\t%(module)s\t%(funcName)s\t%(message)s' LOGFILE = os.path.join(base_dir, 'hgpusher.log') LOGHANDLER = log.handlers.RotatingFileHandler(LOGFILE, maxBytes=50000, backupCount=5) mq = mq_utils.mq_util() config = common.get_configuration(os.path.join(base_dir, 'config.ini')) config.update(common.get_configuration(os.path.join(base_dir, 'auth.ini'))) bz = bz_utils.bz_util(api_url=config['bz_api_url'], url=config['bz_url'], attachment_url=config['bz_attachment_url'], username=config['bz_username'], password=config['bz_password']) ldap = ldap_utils.ldap_util(config['ldap_host'], int(config['ldap_port']), config['ldap_bind_dn'], config['ldap_password']) def run_hg(hg_args): """ Run hg with given args, returning a tuple containing stdout, stderr and return code. """ cmd = ['hg']
# permissions logs are put into hgpusher.%d/permissions.log plog = logging.getLogger('permissions') log = logging.getLogger() LOGFORMAT = logging.Formatter(config['log_format']) LOGHANDLER = logging.StreamHandler() # log to stdout bz = bz_utils.bz_util(api_url=config['bz_api_url'], attachment_url=config['bz_attachment_url'], username=config['bz_username'], password=config['bz_password']) ldap = ldap_utils.ldap_util(config['ldap_host'], int(config['ldap_port']), config['ldap_branch_api'], config['ldap_bind_dn'], config['ldap_password']) mq = mq_utils.mq_util(host=config['mq_host'], vhost=config['mq_vhost'], username=config['mq_username'], password=config['mq_password'], exchange=config['mq_exchange']) ## # Pre-compile some oft-used regexes ## # Match the user line, starts with "User" and then a name # ends with an email address in <> RE_USERLINE = re.compile(r'# User [\w\s]+ ' '<[\w\d._%+-]+@[\w\d.-]+\.\w{2,6}>$') RE_PUSER = re.compile(r'# User ') # commit message is always first line not prefixed with # RE_COMMITLINE = re.compile(r'^[^#$]+') ##
plog = logging.getLogger('permissions') log = logging.getLogger() LOGFORMAT = logging.Formatter(config['log_format']) LOGHANDLER = logging.StreamHandler() # log to stdout bz = bz_utils.bz_util(api_url=config['bz_api_url'], attachment_url=config['bz_attachment_url'], username=config['bz_username'], password=config['bz_password']) ldap = ldap_utils.ldap_util(config['ldap_host'], int(config['ldap_port']), config['ldap_branch_api'], config['ldap_bind_dn'], config['ldap_password']) mq = mq_utils.mq_util(host=config['mq_host'], vhost=config['mq_vhost'], username=config['mq_username'], password=config['mq_password'], exchange=config['mq_exchange']) ## # Pre-compile some oft-used regexes ## # Match the user line, starts with "User" and then a name # ends with an email address in <> RE_USERLINE = re.compile(r'# User [\w\s]+ ' '<[\w\d._%+-]+@[\w\d.-]+\.\w{2,6}>$') RE_PUSER = re.compile(r'# User ') # commit message is always first line not prefixed with # RE_COMMITLINE = re.compile(r'^[^#$]+') ##
def setUp(self): self.mq = mq_utils.mq_util() self.mq.set_host('localhost') self.mq.set_exchange('autoland-new') self.mq.connect()