diff options
| author | Andreea Proca <andreea.b.proca@intel.com> | 2014-02-14 13:58:43 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-02-14 12:30:20 +0000 |
| commit | da0a4c7f8de57624f70ef4c8fabacd089241d91a (patch) | |
| tree | a5228546c5208a3eb96577a90cf97931f4385c93 | |
| parent | 4cc0a43449818ad48203e3a6f2f46a5b28e09a9a (diff) | |
| download | poky-da0a4c7f8de57624f70ef4c8fabacd089241d91a.tar.gz | |
report-error.bbclass: new class to save build information when errors occur
Class is used to save data about errors after every task that failed.
Errors saved as json files in ERROR_REPORT_DIR (defaults to tmp/log/error-report).
To use this class one has to add INHERIT += "report-error" to local.conf.
scripts/send-error-report is a simple script that sends the json file
to a HTTP server that collects data (git://git.yoctoproject.org/error-report-web
is a Django web interface that can be used to receive and visualize
the error reports). The script will give you an URL where you can
find your report.
(From OE-Core rev: f186b4c7c6c975638e60b30a512d669dc6dc390f)
Signed-off-by: Andreea Proca <andreea.b.proca@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/classes/report-error.bbclass | 66 | ||||
| -rwxr-xr-x | scripts/send-error-report | 78 |
2 files changed, 144 insertions, 0 deletions
diff --git a/meta/classes/report-error.bbclass b/meta/classes/report-error.bbclass new file mode 100644 index 0000000000..479b38deb0 --- /dev/null +++ b/meta/classes/report-error.bbclass | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | # | ||
| 2 | # Collects debug information in order to create error report files. | ||
| 3 | # | ||
| 4 | # Copyright (C) 2013 Intel Corporation | ||
| 5 | # Author: Andreea Brandusa Proca <andreea.b.proca@intel.com> | ||
| 6 | # | ||
| 7 | # Licensed under the MIT license, see COPYING.MIT for details | ||
| 8 | |||
| 9 | ERR_REPORT_DIR ?= "${LOG_DIR}/error-report" | ||
| 10 | |||
| 11 | def errorreport_getdata(e): | ||
| 12 | logpath = e.data.getVar('ERR_REPORT_DIR', True) | ||
| 13 | datafile = os.path.join(logpath, "error-report.txt") | ||
| 14 | with open(datafile) as f: | ||
| 15 | data = f.read() | ||
| 16 | return data | ||
| 17 | |||
| 18 | def errorreport_savedata(e, newdata, file): | ||
| 19 | import json | ||
| 20 | logpath = e.data.getVar('ERR_REPORT_DIR', True) | ||
| 21 | bb.utils.mkdirhier(logpath) | ||
| 22 | datafile = os.path.join(logpath, file) | ||
| 23 | with open(datafile, "w") as f: | ||
| 24 | json.dump(newdata, f, indent=4, sort_keys=True) | ||
| 25 | return datafile | ||
| 26 | |||
| 27 | python errorreport_handler () { | ||
| 28 | import json | ||
| 29 | |||
| 30 | if isinstance(e, bb.event.BuildStarted): | ||
| 31 | data = {} | ||
| 32 | machine = e.data.getVar("MACHINE") | ||
| 33 | data['machine'] = machine | ||
| 34 | data['build_sys'] = e.data.getVar("BUILD_SYS", True) | ||
| 35 | data['nativelsb'] = e.data.getVar("NATIVELSBSTRING") | ||
| 36 | data['distro'] = e.data.getVar("DISTRO") | ||
| 37 | data['target_sys'] = e.data.getVar("TARGET_SYS", True) | ||
| 38 | data['failures'] = [] | ||
| 39 | data['component'] = e.getPkgs()[0] | ||
| 40 | data['branch_commit'] = base_detect_branch(e.data) + ": " + base_detect_revision(e.data) | ||
| 41 | errorreport_savedata(e, data, "error-report.txt") | ||
| 42 | |||
| 43 | elif isinstance(e, bb.build.TaskFailed): | ||
| 44 | task = e.task | ||
| 45 | taskdata={} | ||
| 46 | log = e.data.getVar('BB_LOGFILE', True) | ||
| 47 | logFile = open(log, 'r') | ||
| 48 | taskdata['package'] = e.data.expand("${PF}") | ||
| 49 | taskdata['task'] = task | ||
| 50 | taskdata['log'] = logFile.read() | ||
| 51 | logFile.close() | ||
| 52 | jsondata = json.loads(errorreport_getdata(e)) | ||
| 53 | jsondata['failures'].append(taskdata) | ||
| 54 | errorreport_savedata(e, jsondata, "error-report.txt") | ||
| 55 | |||
| 56 | elif isinstance(e, bb.event.BuildCompleted): | ||
| 57 | jsondata = json.loads(errorreport_getdata(e)) | ||
| 58 | failures = jsondata['failures'] | ||
| 59 | if(len(failures) > 0): | ||
| 60 | filename = "error_report_" + e.data.getVar("BUILDNAME")+".txt" | ||
| 61 | datafile = errorreport_savedata(e, jsondata, filename) | ||
| 62 | bb.note("The errors of this build are stored in: %s. You can send the errors to an upstream server by running: send-error-report %s [server]" % (datafile, datafile)) | ||
| 63 | } | ||
| 64 | |||
| 65 | addhandler errorreport_handler | ||
| 66 | errorreport_handler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted bb.build.TaskFailed" | ||
diff --git a/scripts/send-error-report b/scripts/send-error-report new file mode 100755 index 0000000000..0d85776340 --- /dev/null +++ b/scripts/send-error-report | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | |||
| 3 | # Sends an error report (if the report-error class was enabled) to a remote server. | ||
| 4 | # | ||
| 5 | # Copyright (C) 2013 Intel Corporation | ||
| 6 | # Author: Andreea Proca <andreea.b.proca@intel.com> | ||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 | import httplib, urllib, os, sys, json | ||
| 11 | |||
| 12 | |||
| 13 | def sendData(json_file, server): | ||
| 14 | |||
| 15 | if os.path.isfile(json_file): | ||
| 16 | |||
| 17 | home = os.path.expanduser("~") | ||
| 18 | userfile = os.path.join(home, ".oe-send-error") | ||
| 19 | if os.path.isfile(userfile): | ||
| 20 | with open(userfile) as g: | ||
| 21 | username = g.readline() | ||
| 22 | email = g.readline() | ||
| 23 | else: | ||
| 24 | print("Please enter your name and your email (optionally), they'll be saved in the file you send.") | ||
| 25 | username = raw_input("Name: ") | ||
| 26 | email = raw_input("E-mail (not required): ") | ||
| 27 | if len(username) > 0 and len(username) < 50: | ||
| 28 | with open(userfile, "w") as g: | ||
| 29 | g.write(username + "\n") | ||
| 30 | g.write(email + "\n") | ||
| 31 | else: | ||
| 32 | print("Invalid inputs, try again.") | ||
| 33 | return | ||
| 34 | |||
| 35 | with open(json_file) as f: | ||
| 36 | data = f.read() | ||
| 37 | |||
| 38 | try: | ||
| 39 | jsondata = json.loads(data) | ||
| 40 | jsondata['username'] = username.strip() | ||
| 41 | jsondata['email'] = email.strip() | ||
| 42 | data = json.dumps(jsondata, indent=4, sort_keys=True) | ||
| 43 | except: | ||
| 44 | print("Invalid json data") | ||
| 45 | return | ||
| 46 | |||
| 47 | try: | ||
| 48 | params = urllib.urlencode({'data': data}) | ||
| 49 | headers = {"Content-type": "application/json"} | ||
| 50 | conn = httplib.HTTPConnection(server) | ||
| 51 | conn.request("POST", "/ClientPost/", params, headers) | ||
| 52 | response = conn.getresponse() | ||
| 53 | print response.status, response.reason | ||
| 54 | res = response.read() | ||
| 55 | if response.status == 200: | ||
| 56 | print res | ||
| 57 | else: | ||
| 58 | print("There was a problem submiting your data") | ||
| 59 | conn.close() | ||
| 60 | except: | ||
| 61 | print("Server connection failed") | ||
| 62 | |||
| 63 | else: | ||
| 64 | print("No data file found.") | ||
| 65 | |||
| 66 | |||
| 67 | if __name__ == '__main__': | ||
| 68 | print ("\nSends an error report (if the report-error class was enabled) to a remote server.") | ||
| 69 | if len(sys.argv) < 2: | ||
| 70 | print("\nThis scripts sends the contents of a file to an upstream server.") | ||
| 71 | print("\nUsage: send-error-report <error_fileName> [server]") | ||
| 72 | print("\nIf this is the first when sending a report you'll be asked for your name and optionally your email address.") | ||
| 73 | print("They will be associated with your report.\n") | ||
| 74 | |||
| 75 | elif len(sys.argv) == 3: | ||
| 76 | sendData(sys.argv[1], sys.argv[2]) | ||
| 77 | else: | ||
| 78 | sendData(sys.argv[1], "localhost:8000") | ||
