Ejemplo n.º 1
0
    def __init__(self):

        logger.debug(
            "Connecting to %(host)s:%(port)d as " "%(user)s using %(key)s",
            {
                "user": cfg.AccountInfo.gerrit_username,
                "key": cfg.AccountInfo.gerrit_ssh_key,
                "host": cfg.AccountInfo.gerrit_host,
                "port": int(cfg.AccountInfo.gerrit_port),
            },
        )

        self.ssh = paramiko.SSHClient()
        self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        connected = False
        while not connected:
            try:
                self.ssh.connect(
                    cfg.AccountInfo.gerrit_host,
                    int(cfg.AccountInfo.gerrit_port),
                    cfg.AccountInfo.gerrit_username,
                    key_filename=cfg.AccountInfo.gerrit_ssh_key,
                )
                connected = True
            except paramiko.SSHException as e:
                logger.error("%s", e)
                logger.warn("Gerrit may be down, will pause and retry...")
                time.sleep(10)

        self.stdin, self.stdout, self.stderr = self.ssh.exec_command("gerrit stream-events")
Ejemplo n.º 2
0
def parse_json_event(event):
    try:
        event = json.loads(event)
    except Exception as ex:
        logger.error("Failed json.loads on event: %s", event)
        logger.exception(ex)
        return None
    if _is_valid(event):
        _process_event(event)
        logger.info("Parsed valid event: %s", event)
        return event
    return None
Ejemplo n.º 3
0
def get_data(datafile, projects):
    data = []
    with open(datafile) as file_:
        for line in file_:
            try:
                event = json.loads(line)
            except Exception as ex:
                logger.error('Failed json.loads on event: %s', event)
                logger.exception(ex)
                continue
            parsed_event = parse_event(event, projects)
            if parsed_event is not None:
                data.append(parsed_event)
    return data