Ejemplo n.º 1
0
 def formatException(self, ei):
     from conary.lib import util
     import StringIO
     excType, excValue, tb = ei
     sio = StringIO.StringIO()
     util.formatTrace(excType, excValue, tb, stream=sio, withLocals=False)
     util.formatTrace(excType, excValue, tb, stream=sio, withLocals=True)
     return sio.getvalue().rstrip()
Ejemplo n.º 2
0
def excepthook(e_type, e_value, e_tb):
    if isinstance(e_value, KeyboardInterrupt):
        print >>sys.stderr
        print >>sys.stderr, 'Interrupted by Ctrl-C'
        sys.exit(-1)

    sys.excepthook = sys.__excepthook__
    util.formatTrace(e_type, e_value, e_tb, withLocals=False)
    epdb.post_mortem(e_tb, e_type, e_value)
Ejemplo n.º 3
0
 def formatException(self, ei):
     from conary.lib import util
     import StringIO
     excType, excValue, tb = ei
     sio = StringIO.StringIO()
     util.formatTrace(excType, excValue, tb, stream = sio,
         withLocals = False)
     util.formatTrace(excType, excValue, tb, stream = sio,
         withLocals = True)
     return sio.getvalue().rstrip()
Ejemplo n.º 4
0
    def cancelImageBuild(self, image, job):
        try:
            self._cancelImageBuild(image, job)
        except:
            exc = sys.exc_info()
            stream = util.BoundedStringIO()
            util.formatTrace(*exc, stream=stream, withLocals=False)
            stream.seek(0)

            job.job_state = self.mgr.getJobStateByName(jobsmodels.JobState.FAILED)
            job.status_code = 500
            job.status_text = "Failed"
            job.status_detail = stream.read()
        else:
            job.job_state = self.mgr.getJobStateByName(jobsmodels.JobState.COMPLETED)
            job.status_code = 200
            job.status_text = "Done"
        job.save()
Ejemplo n.º 5
0
Archivo: main.py Proyecto: pombreda/bob
 def excepthook(e_class, e_val, e_tb):
     if not options.debug:
         cny_util.formatTrace(e_class, e_val, e_tb, withLocals=False)
     return cny_hook(e_class, e_val, e_tb)
Ejemplo n.º 6
0
def logErrorAndEmail(cfg, e_type, e_value, e_tb, location, info_dict,
  prefix='mint-error-', smallStream=None, doEmail=True):
    timeStamp = time.ctime(time.time())
    realHostName = socket.getfqdn()

    if 'mint.authToken' in info_dict:
        info_dict['mint.authToken'] = repr(info_dict['mint.authToken'])
    if 'HTTP_AUTHORIZATION' in info_dict:
        info_dict['HTTP_AUTHORIZATION'] = info_dict['HTTP_AUTHORIZATION'].split()[0] + ' ******'

    # Format large traceback to file
    (tbFd, tbPath) = tempfile.mkstemp('.txt', prefix)
    large = os.fdopen(tbFd, 'w+')
    print >> large, ('Unhandled exception from %s on %s:'
        % (location, realHostName))
    print >> large, 'Time of occurrence: %s' % timeStamp
    print >> large, 'See also: %s' % tbPath
    print >> large
    conary_util.formatTrace(e_type, e_value, e_tb, stream=large,
        withLocals=False)
    print >> large
    print >> large, 'Full stack:'
    print >> large
    try:
        conary_util.formatTrace(e_type, e_value, e_tb, stream=large,
            withLocals=True)
    except:
        # The extended traceback formatter can crash when uncooperative
        # objects do something special when marshalled. For example,
        # derivatives of Thread may abort before Thread itself is
        # initialized, which causes __repr__ to crash, and
        # ServerProxy derivatives may crash when __safe_str__ is
        # improperly sent as a remote procedure call instead of
        # throwing an AttributeError.
        #
        # None of these conditions should prevent the original
        # exception from being logged and emailed, if only in their
        # short form.

        handlerErrorType, handlerErrorValue, handlerErrorTB = sys.exc_info()
        print >> large
        print >> large, '*** Traceback formatter crashed! ***'
        print >> large, 'Formatter crash follows:'
        conary_util.formatTrace(handlerErrorType, handlerErrorValue,
            handlerErrorTB, stream=large, withLocals=False)
        print >> large, '*** End formatter crash log ***'
    print >> large
    print >> large, 'Environment:'
    for key, val in sorted(info_dict.items()):
        try:
            print >> large, '%s: %s' % (key, val)
        except:
            pass

    # Format small traceback
    small = conary_util.BoundedStringIO()
    print >> small, ('Unhandled exception from %s on %s:'
        % (location, realHostName))
    conary_util.formatTrace(e_type, e_value, e_tb, stream=small,
        withLocals=False)
    print >> small, 'Extended traceback at %s' % tbPath

    if cfg and cfg.sentryDSN:
        from raven import Client
        from raven.utils import wsgi
        client = Client(cfg.sentryDSN)
        data = {}
        extra = {
                'environ': info_dict,
                'reference': '%s:%s' % (realHostName, tbPath),
                }
        if 'REQUEST_METHOD' in info_dict:
            # Looks like WSGI
            environ = info_dict
            data['sentry.interfaces.Http'] = {
                'method': environ.get('REQUEST_METHOD'),
                'url': wsgi.get_current_url(environ, strip_querystring=True),
                'query_string': environ.get('QUERY_STRING'),
                'headers': dict(wsgi.get_headers(environ)),
                'env': dict(wsgi.get_environ(environ)),
                }
        sentry_id = client.captureException(exc_info=(e_type, e_value, e_tb),
                data=data, extra=extra)
        print >> large, "Sentry event ID: ", sentry_id[0]
        print >> small, "Sentry event ID: ", sentry_id[0]

    small.seek(0)
    log.error(small.read())

    # send email
    if cfg and doEmail:
        base_exception = traceback.format_exception_only(
            e_type, e_value)[-1].strip()
        if cfg.rBuilderOnline:
            subject = '%s: %s' % (realHostName, base_exception)
        else:
            extra = {'hostname': realHostName}
            subject = cfg.bugsEmailSubject % extra

        if cfg.bugsEmail:
            large.seek(0)
            maillib.sendMailWithChecks(cfg.bugsEmail, cfg.bugsEmailName,
                                     cfg.bugsEmail, subject, large.read())
        if cfg.smallBugsEmail:
            small.seek(0)
            maillib.sendMailWithChecks(cfg.bugsEmail, cfg.bugsEmailName,
                cfg.smallBugsEmail, subject, small.read())

    large.close()
Ejemplo n.º 7
0
                netmask = ip.netmask,
                dns_name=ip.dns_name, active=active,
                required = (requiredIp in [ ip.ipv4, ip.dns_name ] or None),
                device_name=ip.device)
            networks.add_network(network)

        try:
            logger.info("Running system scan...")
            survey = scan.scanner.SurveyScanner(origin="registration").toxml()
        except Exception, e:
            logger.info("System scan failed: %s", str(e))
            # Save the exception
            excInfo = sys.exc_info()
            try:
                sio = StringIO.StringIO()
                util.formatTrace(*excInfo, stream=sio, withLocals=False)
                logger.info("Details: %s", sio.getvalue())

                survey = scan.etree.Element("survey")
                error = scan.etree.SubElement(survey, "error")
                scan.etree.SubElement(error, "text").text = str(e)
                scan.etree.SubElement(error, "details").text = sio.getvalue()
            except Exception, e:
                logger.info("Error reporting failed: %s", str(e))
                survey = None

        current_state = CurrentState(name=state)
        management_interface = ManagementInterface(name='cim')
        system = System(hostname=hostname,
                        generated_uuid=registration.generatedUuid,
                        local_uuid=registration.localUuid,
Ejemplo n.º 8
0
                dns_name=ip.dns_name,
                active=active,
                required=(requiredIp in [ip.ipv4, ip.dns_name] or None),
                device_name=ip.device)
            networks.add_network(network)

        try:
            logger.info("Running system scan...")
            survey = scan.scanner.SurveyScanner(origin="registration").toxml()
        except Exception, e:
            logger.info("System scan failed: %s", str(e))
            # Save the exception
            excInfo = sys.exc_info()
            try:
                sio = StringIO.StringIO()
                util.formatTrace(*excInfo, stream=sio, withLocals=False)
                logger.info("Details: %s", sio.getvalue())

                survey = scan.etree.Element("survey")
                error = scan.etree.SubElement(survey, "error")
                scan.etree.SubElement(error, "text").text = str(e)
                scan.etree.SubElement(error, "details").text = sio.getvalue()
            except Exception, e:
                logger.info("Error reporting failed: %s", str(e))
                survey = None

        current_state = CurrentState(name=state)
        management_interface = ManagementInterface(name='cim')
        system = System(hostname=hostname,
                        generated_uuid=registration.generatedUuid,
                        local_uuid=registration.localUuid,