← Back to team overview

apport-hackers team mailing list archive

[Merge] lp:~barry/apport/lp1566975 into lp:~ubuntu-core-dev/ubuntu/xenial/apport/ubuntu

 

Barry Warsaw has proposed merging lp:~barry/apport/lp1566975 into lp:~ubuntu-core-dev/ubuntu/xenial/apport/ubuntu.

Requested reviews:
  Apport upstream developers (apport-hackers)
Related bugs:
  Bug #1566975 in Apport: "AssertionError on .proc.driver.nvidia.gpus.0000:01:00.0"
  https://bugs.launchpad.net/apport/+bug/1566975

For more details, see:
https://code.launchpad.net/~barry/apport/lp1566975/+merge/291144

This fixes the AssertionError by using a regular expression and adding : to the list of acceptable characters.  It adds a test and prints the failing value when the assertion triggers.
-- 
Your team Apport upstream developers is requested to review the proposed merge of lp:~barry/apport/lp1566975 into lp:~ubuntu-core-dev/ubuntu/xenial/apport/ubuntu.
=== modified file 'problem_report.py'
--- problem_report.py	2015-12-04 11:18:26 +0000
+++ problem_report.py	2016-04-06 16:44:02 +0000
@@ -11,7 +11,7 @@
 # option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
 # the full text of the license.
 
-import zlib, base64, time, sys, gzip, struct, os
+import zlib, base64, time, sys, gzip, struct, os, re
 from email.encoders import encode_base64
 from email.mime.multipart import MIMEMultipart
 from email.mime.base import MIMEBase
@@ -640,8 +640,7 @@
         file.write(b'\n')
 
     def __setitem__(self, k, v):
-        assert hasattr(k, 'isalnum')
-        assert k.replace('.', '').replace('-', '').replace('_', '').isalnum()
+        assert re.match('^[-\w._:]+$', k, re.ASCII), k
         # value must be a string or a CompressedValue or a file reference
         # (tuple (string|file [, bool]))
         assert (isinstance(v, CompressedValue) or hasattr(v, 'isalnum') or

=== modified file 'test/test_problem_report.py'
--- test/test_problem_report.py	2015-12-04 11:18:26 +0000
+++ test/test_problem_report.py	2016-04-06 16:44:02 +0000
@@ -3,6 +3,7 @@
 
 from io import BytesIO
 import problem_report
+import apport.hookutils
 
 bin_data = b'ABABABABAB\0\0\0Z\x01\x02'
 
@@ -1057,5 +1058,14 @@
         self.assertEqual(pr['GoodFile'], bin_data)
         self.assertEqual(sorted(pr.keys()), ['DataYes', 'GoodFile'])
 
+    def test_attach_gpu_file(self):
+        r = problem_report.ProblemReport()
+        key = '.proc.driver.nvidia.gpus.0000:01:00.0'
+        with tempfile.NamedTemporaryFile() as f:
+            f.write(b'gpu goodness\n')
+            f.flush()
+            apport.hookutils.attach_file_if_exists(r, f.name, key)
+        self.assertEqual(r[key], 'gpu goodness')
+
 if __name__ == '__main__':
     unittest.main()


Follow ups