예제 #1
0
def receive_message(config, data, message):
    buildername = data["payload"]["build"]["builderName"]
    properties = data["payload"]["build"]["properties"]
    results = data["payload"]["results"]

    if not buildername.startswith('release-') or \
            ' test ' in buildername:
        return
    if results != 0:
        log.debug("Non zero results from %s", buildername)
        return
    if not properties:
        log.exception("No properties set by %s", buildername)
        return

    log.info("Processing %s", buildername)
    properties_dict = get_properties_dict(properties)

    payload = {}
    for k, v in properties_dict.iteritems():
        if k in PROPERTIES_KEYS:
            payload[k] = v
    if "event_group" not in payload:
        log.debug("Ignoring message without event_group set")
        return
    # rename event_group to group
    payload["group"] = payload.pop("event_group")
    payload["results"] = results
    payload["event_name"] = buildername
    # Convert sent to UTC
    timestamp = parser.parse(data["_meta"]["sent"]).astimezone(pytz.utc)
    payload["sent"] = timestamp.strftime("%Y-%m-%d %H:%M:%S")

    name = getReleaseName(
        properties_dict["product"], properties_dict["version"],
        properties_dict["build_number"])

    log.info("Adding new release event for %s with event_name %s", name,
             buildername)
    status_api = Status(
        (config.get('api', 'username'), config.get('api', 'password')),
        api_root=config.get('api', 'api_root'))
    status_api.update(name, data=payload)
예제 #2
0
def receive_message(config, data, message):
    try:
        if not data['payload']['build'].get(u'builderName').\
                                        startswith('release-'):
            return
        if ' test ' in data['payload']['build'].get(u'builderName'):
            return
        if not data['payload']['build'].get('properties'):
            log.exception('TypeError: build properties not found - {}'.\
                      format(data['payload']['build'].get('builderName')))
            return
        if data['payload'][u'results'] != 0:
            return

        log.info('msg received - {}'.format(data['payload']['build'].\
                                     get(u'builderName')))

        payload = {}
        payload[u'sent'] = data['_meta'].get(u'sent')
        payload[u'results'] = data['payload'].get(u'results')
        payload[u'event_name'] = data['payload']['build'].get(u'builderName')

        # Convert sent to UTC
        timestamp = parser.parse(payload[u'sent']).astimezone(pytz.utc)
        payload[u'sent'] = unicode(timestamp.strftime('%Y-%m-%d %H:%M:%S'))

        for key in PROPERTIES_KEYS:
            for prop in data['payload']['build'].get('properties'):
                if prop[0] == key:
                    try:
                        payload[key] = prop[1]
                    except IndexError as e:
                        payload[key] = 'None'
                        log.warning('{} not in build properties for {} - {}'.\
                                    format(key, payload['event_name'], e))
        payload[u'group'] = payload.pop(u'event_group')
        if 'postrelease' in payload[u'event_name']:
            payload[u'group'] = 'postrelease'

        name = {}
        for key in NAME_KEYS:
            for prop in data['payload']['build'].get('properties'):
                if prop[0] == key:
                    try:
                        name[key] = prop[1]
                    except IndexError as e:
                        name[key] = 'None'
                        log.warning('{} not in build properties for {} - {}'.\
                                    format(key, payload['event_name'], e))
        name = getReleaseName(name.pop('product'), 
                              name.pop('version'), 
                              name.pop('build_number'))

        log.info('adding new release event for {} with event_name {}'.\
                 format(name, payload['event_name']))
        status_api = Status((config.get('api', 'username'), 
                             config.get('api', 'password')), 
                            api_root=config.get('api', 'api_root'))
        status_api.update(name, data=payload)
        print payload
    except Exception as e:
        log.exception('{} - {}'.format(e, data['payload']['build'].get('builderName')))
    finally:
        message.ack()
예제 #3
0
def receive_message(config, data, message):
    try:
        if not data['payload']['build'].get(u'builderName').\
                                        startswith('release-'):
            return
        if ' test ' in data['payload']['build'].get(u'builderName'):
            return
        if not data['payload']['build'].get('properties'):
            log.exception('TypeError: build properties not found - {}'.\
                      format(data['payload']['build'].get('builderName')))
            return
        if data['payload'][u'results'] != 0:
            return

        log.info('msg received - {}'.format(data['payload']['build'].\
                                     get(u'builderName')))

        payload = {}
        payload[u'sent'] = data['_meta'].get(u'sent')
        payload[u'results'] = data['payload'].get(u'results')
        payload[u'event_name'] = data['payload']['build'].get(u'builderName')

        # Convert sent to UTC
        timestamp = parser.parse(payload[u'sent']).astimezone(pytz.utc)
        payload[u'sent'] = unicode(timestamp.strftime('%Y-%m-%d %H:%M:%S'))

        for key in PROPERTIES_KEYS:
            for prop in data['payload']['build'].get('properties'):
                if prop[0] == key:
                    try:
                        payload[key] = prop[1]
                    except IndexError as e:
                        payload[key] = 'None'
                        log.warning('{} not in build properties for {} - {}'.\
                                    format(key, payload['event_name'], e))
        payload[u'group'] = payload.pop(u'event_group')
        if 'postrelease' in payload[u'event_name']:
            payload[u'group'] = 'postrelease'

        name = {}
        for key in NAME_KEYS:
            for prop in data['payload']['build'].get('properties'):
                if prop[0] == key:
                    try:
                        name[key] = prop[1]
                    except IndexError as e:
                        name[key] = 'None'
                        log.warning('{} not in build properties for {} - {}'.\
                                    format(key, payload['event_name'], e))
        name = getReleaseName(name.pop('product'), name.pop('version'),
                              name.pop('build_number'))

        log.info('adding new release event for {} with event_name {}'.\
                 format(name, payload['event_name']))
        status_api = Status(
            (config.get('api', 'username'), config.get('api', 'password')),
            api_root=config.get('api', 'api_root'))
        status_api.update(name, data=payload)
        print payload
    except Exception as e:
        log.exception('{} - {}'.format(
            e, data['payload']['build'].get('builderName')))
    finally:
        message.ack()