Merge lp:~louis/ubuntu/raring/apport/apport_kdump_blueprint into lp:ubuntu/raring/apport

Proposed by Louis Bouchard
Status: Merged
Approved by: Martin Pitt
Approved revision: 356
Merge reported by: Martin Pitt
Merged at revision: not available
Proposed branch: lp:~louis/ubuntu/raring/apport/apport_kdump_blueprint
Merge into: lp:ubuntu/raring/apport
Diff against target: 163 lines (+77/-24)
4 files modified
data/kernel_crashdump (+37/-21)
debian/apport.upstart (+1/-1)
etc/cron.daily/apport (+1/-0)
test/test_hooks.py (+38/-2)
To merge this branch: bzr merge lp:~louis/ubuntu/raring/apport/apport_kdump_blueprint
Reviewer Review Type Date Requested Status
Martin Pitt Approve
Louis Bouchard Needs Resubmitting
Review via email: mp+149499@code.launchpad.net

Description of the change

Modified kernel_crashdump to pick up dmesg output from timestamped directory created by kdump-tools which replaces the kexec-tools mechanism to handle kernel crash dump

https://blueprints.launchpad.net/ubuntu/+spec/servercloud-r-kdump-tool

Includes upstart script modification

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

On hold until the question/problem in the upstream MP is sorted out:

https://code.launchpad.net/~louis-bouchard/apport/apport_kdump-tools-blueprint/+merge/149498

351. By Louis Bouchard

Avoid touching the report's package name

352. By Louis Bouchard

Fix changelog test entry

Revision history for this message
Louis Bouchard (louis) wrote :

Updated according to modification in trunk

review: Needs Resubmitting
353. By Louis Bouchard

Add cleanup for new kdump-tools timestampted directories

354. By Louis Bouchard

Add test hook for new kdump-tools report format

355. By Louis Bouchard

Modify test for robustness

356. By Louis Bouchard

Fix find syntax to avoid file not found error

Revision history for this message
Louis Bouchard (louis) wrote :

Modified according to review in trunk :

 * added -n to /etc/init/apport.conf
 * added a test to ./test/test_hooks.py
 * added clean up instructions in /etc/cron.daily/apport

Old behavior has been kept to allow for previous method to work if kdump-tools is not installed

review: Needs Resubmitting
Revision history for this message
Martin Pitt (pitti) wrote :

The upstream bits landed in trunk now, so I'll use this MP to update the upstart job on the packaging side. Thanks!

review: Approve
Revision history for this message
Martin Pitt (pitti) wrote :

You used the wrong packaging branch (it's the one in Vcs-Bzr:, not lp:ubuntu/apport), so I cannot formally merge this. But I committed the remainder of this MP, i. e. the upstart job change:

http://bazaar.launchpad.net/~ubuntu-core-dev/ubuntu/raring/apport/ubuntu/revision/2166

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/kernel_crashdump'
2--- data/kernel_crashdump 2012-05-18 16:33:53 +0000
3+++ data/kernel_crashdump 2013-02-27 16:09:19 +0000
4@@ -11,35 +11,51 @@
5 # option) any later version. See http://www.gnu.org/copyleft/gpl.html for
6 # the full text of the license.
7
8-import os, sys
9+import os, sys, re
10 import apport, apport.fileutils
11
12-vmcore_path = os.path.join(apport.fileutils.report_dir, 'vmcore')
13-
14-if not os.path.exists(vmcore_path):
15- sys.exit(0)
16+vmcore_root = os.path.join(apport.fileutils.report_dir)
17+vmcore_path = os.path.join(vmcore_root, 'vmcore')
18
19 pr = apport.Report('KernelCrash')
20 pr['Package'] = apport.packaging.get_kernel_package()
21
22-pr['VmCore'] = (vmcore_path,)
23 pr.add_os_info()
24 if os.path.exists(vmcore_path + '.log'):
25 pr['VmCoreLog'] = (vmcore_path + '.log',)
26
27-# write report
28-try:
29- with open(apport.fileutils.make_report_path(pr), 'wb') as f:
30- pr.write(f)
31-except IOError as e:
32- apport.fatal('Cannot create report: ' + str(e))
33+if os.path.exists(vmcore_path):
34+ pr['VmCore'] = (vmcore_path,)
35+ try:
36+ with open(apport.fileutils.make_report_path(pr), 'wb') as f:
37+ pr.write(f)
38+ except IOError as e:
39+ apport.fatal('Cannot create report: ' + str(e))
40+else:
41+# kdump-tools has moved vmcore to timestamped dir
42+ for root, dirs, files in os.walk(vmcore_root):
43+ for timedir in dirs:
44+ if re.search('^[0-9]{12}$', timedir):
45+ vmcore_dir = os.path.join(vmcore_root, timedir)
46+ dmesgfile = os.path.join(vmcore_dir, 'dmesg.' + timedir)
47+ report_name = pr['Package'] + '-' + timedir + '.crash'
48+ crash_report = os.path.join(vmcore_root, report_name)
49+ pr['VmCoreDmesg'] = (dmesgfile,)
50+ if not os.path.exists(crash_report):
51+ try:
52+ with open(crash_report, 'wb') as f:
53+ pr.write(f)
54+ except IOError as e:
55+ apport.fatal('Cannot create report: ' + str(e))
56
57-# clean up the core files
58-try:
59- os.unlink(vmcore_path)
60-except OSError:
61- pass # huh, already gone?
62-try:
63- os.unlink(vmcore_path + '.log')
64-except OSError:
65- pass
66+# clean up the core file
67+# if not generated by kdump-tools
68+if os.path.exists(vmcore_path):
69+ try:
70+ os.unlink(vmcore_path)
71+ except OSError:
72+ pass # huh, already gone?
73+ try:
74+ os.unlink(vmcore_path + '.log')
75+ except OSError:
76+ pass
77
78=== modified file 'debian/apport.upstart'
79--- debian/apport.upstart 2011-10-19 09:39:41 +0000
80+++ debian/apport.upstart 2013-02-27 16:09:19 +0000
81@@ -17,7 +17,7 @@
82 mkdir -p -m 1777 /var/crash
83
84 # check for kernel crash dump, convert it to apport report
85- if [ -e /var/crash/vmcore ]
86+ if [ -e /var/crash/vmcore ] || [ -n "`ls /var/crash | egrep ^[0-9]{12}$`" ]
87 then
88 /usr/share/apport/kernel_crashdump || true
89 fi
90
91=== modified file 'etc/cron.daily/apport'
92--- etc/cron.daily/apport 2012-03-22 18:55:17 +0000
93+++ etc/cron.daily/apport 2013-02-27 16:09:19 +0000
94@@ -2,3 +2,4 @@
95 # clean all crash reports which are older than a week.
96 [ -d /var/crash ] || exit 0
97 find /var/crash/. ! -name . -prune -type f \( \( -size 0 -a \! -name '*.upload*' \) -o -mtime +7 \) -exec rm -f -- '{}' \;
98+find /var/crash/. ! -name . -prune -type d -regextype posix-extended -regex '.*/[0-9]{12}$' \( -mtime +7 \) -exec rm -Rf -- '{}' \;
99
100=== modified file 'test/test_hooks.py'
101--- test/test_hooks.py 2012-07-18 12:31:50 +0000
102+++ test/test_hooks.py 2013-02-27 16:09:19 +0000
103@@ -11,6 +11,8 @@
104
105 import unittest, subprocess, tempfile, os, shutil, os.path, sys, optparse
106
107+from datetime import datetime
108+
109 import apport, apport.fileutils
110
111 # parse command line options
112@@ -136,8 +138,8 @@
113
114 self.assertEqual(r['Tags'], 'dist-upgrade verybad')
115
116- def test_kernel_crashdump(self):
117- '''kernel_crashdump.'''
118+ def test_kernel_crashdump_kexec(self):
119+ '''kernel_crashdump using kexec-tools.'''
120
121 f = open(os.path.join(apport.fileutils.report_dir, 'vmcore'), 'wb')
122 f.write(b'\x01' * 100)
123@@ -169,6 +171,40 @@
124 r.add_package_info(r['Package'])
125 self.assertTrue(' ' in r['Package']) # appended version number
126
127+ def test_kernel_crashdump_kdump(self):
128+ '''kernel_crashdump using kdump-tools.'''
129+
130+ timedir = datetime.strftime(datetime.now(),"%Y%m%d%H%M")
131+ vmcore_dir = os.path.join(apport.fileutils.report_dir, timedir)
132+ os.mkdir(vmcore_dir)
133+
134+ dmesgfile = os.path.join(vmcore_dir, 'dmesg.' + timedir)
135+ f = open(dmesgfile, 'wt')
136+ f.write('1' * 100)
137+ f.close()
138+
139+ self.assertEqual(subprocess.call('%s/kernel_crashdump' % datadir), 0,
140+ 'kernel_crashdump finished successfully')
141+
142+ reps = apport.fileutils.get_new_reports()
143+ self.assertEqual(len(reps), 1, 'kernel_crashdump created a report')
144+
145+ r = apport.Report()
146+ with open(reps[0], 'rb') as f:
147+ r.load(f)
148+
149+ self.assertEqual(set(r.keys()), set(['Date', 'Package', 'ProblemType',
150+ 'VmCoreDmesg', 'Uname',
151+ 'Architecture', 'DistroRelease']))
152+ self.assertEqual(r['ProblemType'], 'KernelCrash')
153+ self.assertEqual(r['VmCoreDmesg'], '1' * 100)
154+ self.assertTrue('linux' in r['Package'])
155+
156+ self.assertTrue(os.uname()[2].split('-')[0] in r['Package'])
157+
158+ r.add_package_info(r['Package'])
159+ self.assertTrue(' ' in r['Package']) # appended version number
160+
161 @classmethod
162 def _gcc_version_path(klass):
163 '''Determine a valid version and executable path of gcc and return it

Subscribers

People subscribed via source and target branches