Merge ~pieq/bugit/+git/qabro:fix-1778444-additional-info into bugit:master

Proposed by Pierre Equoy
Status: Merged
Approved by: Pierre Equoy
Approved revision: fb7a0cabfce269df62463f65067e3981a6730881
Merged at revision: e55ab1898ccbe66cb13bbdf30c417db52c64e30a
Proposed branch: ~pieq/bugit/+git/qabro:fix-1778444-additional-info
Merge into: bugit:master
Diff against target: 136 lines (+73/-6)
3 files modified
qabro/__version__.py (+1/-1)
qabro/bug_assistant.py (+69/-4)
snap/snapcraft.yaml (+3/-1)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+348977@code.launchpad.net

Description of the change

This MP gathers standard info (CPU, GPU, BIOS version, etc.) and adds it to the bug description when creating the bug in Launchpad, such as:
=========================================================
Summary: (...)

Steps to reproduce: (...)

Expected result: (...)

Actual result: (...)

Failure rate: (...)

-----

BiosVersion: 1.4.1
GPU: 00:02.0 VGA compatible controller: Intel Corporation Device 5916 (rev 02)
ProductName: Latitude 3580
CPU: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz (4x)
Manufacturer: Dell Inc.
=========================================================

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/qabro/__version__.py b/qabro/__version__.py
2index 72c0657..4d61116 100644
3--- a/qabro/__version__.py
4+++ b/qabro/__version__.py
5@@ -1,5 +1,5 @@
6 __title__ = 'qabro'
7-__version__ = '0.5'
8+__version__ = '0.6dev'
9 __description__ = 'Report bug information with attachments in Launchpad'
10 __author__ = 'Pierre Equoy'
11 __author_email__ = 'pierre.equoy@canonical.com'
12diff --git a/qabro/bug_assistant.py b/qabro/bug_assistant.py
13index ea7c131..c2a3927 100644
14--- a/qabro/bug_assistant.py
15+++ b/qabro/bug_assistant.py
16@@ -1,7 +1,8 @@
17 #!/usr/bin/env python
18 from __future__ import print_function, unicode_literals
19
20-import os, subprocess, sys, tarfile
21+import os, re, subprocess, sys, tarfile
22+from collections import Counter
23 from httplib2 import ServerNotFoundError
24
25 from launchpadlib.launchpad import (
26@@ -64,10 +65,10 @@ class BugAssistant:
27 os.mkdir(directory)
28
29 launchpad = Launchpad.login_with(
30- 'oem-bugreport',
31+ 'qabro',
32 service_root,
33 credentials_file=os.path.join(directory,
34- 'oem-bugreport'),
35+ 'qabro'),
36 allow_access_levels=['WRITE_PRIVATE'])
37
38 # Small trick to force access to launchpad and verify authentication
39@@ -124,8 +125,12 @@ class BugAssistant:
40 raise BugAssistantError(error_message)
41
42 print('Creating Launchpad bug report...')
43+ std_info = AttachmentAssistant.get_standard_info()
44+ std_info_str = '\n'.join(['{}: {}'.format(elt, std_info[elt])
45+ for elt in std_info])
46+ description = self.lp_description + "\n\n-----\n\n" + std_info_str
47 bug = launchpad.bugs.createBug(title=self.lp_title,
48- description=self.lp_description,
49+ description=description,
50 tags=self.lp_tags.split(),
51 target=project)
52 if series:
53@@ -257,3 +262,63 @@ class AttachmentAssistant:
54 self.attachments['checkbox-session.tgz'] = data
55 else:
56 print('There does not seem to be any Checkbox session here...')
57+
58+ @classmethod
59+ def get_standard_info(cls):
60+ """Gather standard information that should be present in all bugs."""
61+ standard_info = {}
62+
63+ buildstamp = '/etc/buildstamp'
64+ if os.path.isfile(buildstamp):
65+ standard_info['Image'] = \
66+ subprocess.check_output(['tail', '-n', '1', buildstamp])
67+
68+ command = "sudo env \"PATH=$PATH\" dmidecode -s system-manufacturer"
69+ standard_info['Manufacturer'] = \
70+ subprocess.check_output(command, shell=True).strip()
71+ command = "sudo env \"PATH=$PATH\" dmidecode -s system-product-name"
72+ standard_info['ProductName'] = \
73+ subprocess.check_output(command, shell=True).strip()
74+ command = "sudo env \"PATH=$PATH\" dmidecode -s bios-version"
75+ standard_info['BiosVersion'] = \
76+ subprocess.check_output(command, shell=True).strip()
77+
78+ standard_info['CPU'] = cls.get_cpu_info()
79+
80+ lspci_output = subprocess.check_output(['lspci']).splitlines()
81+ standard_info['GPU'] = '\n'.join([line for line in lspci_output
82+ if 'VGA' in line])
83+ return standard_info
84+
85+ @classmethod
86+ def get_cpu_info(cls):
87+ """Parse /proc/cpuinfo and return cpu model information."""
88+ cpus = []
89+ cpuinfo = {}
90+ parse_line = re.compile(r'(.*?)\s+:\s+(.*)').match
91+ processor_line = re.compile(r'^(p|P)rocessor')
92+ with open('/proc/cpuinfo') as file:
93+ for line in file:
94+ if processor_line.match(line) and cpuinfo:
95+ cpus.append(cpuinfo)
96+ cpuinfo = {}
97+ match = parse_line(line)
98+ if match:
99+ key, value = match.groups()
100+ cpuinfo[key] = value
101+ cpus.append(cpuinfo)
102+
103+ cpu_names = Counter()
104+ for cpu_number, cpu in enumerate(cpus):
105+ if 'model name' in cpu:
106+ cpu_name = ' '.join(cpu["model name"].split())
107+ cpu_names[cpu_name] += 1
108+ elif 'Processor' in cpu:
109+ cpu_name = ' '.join(cpu["Processor"].split())
110+ cpu_names[cpu_name] += 1
111+
112+ cpu_names_str = ['{} ({}x)'.format(cpu_name, count)
113+ for cpu_name, count in cpu_names.iteritems()]
114+
115+ return '\n'.join(cpu_names_str)
116+
117diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
118index acff5b6..a24e2cd 100644
119--- a/snap/snapcraft.yaml
120+++ b/snap/snapcraft.yaml
121@@ -1,5 +1,5 @@
122 name: qabro
123-version: '0.5'
124+version: '0.6dev'
125 summary: QA OEM bug reporting tool
126 description: |
127 Tool to generate a Launchpad bug report and attach useful logs (using
128@@ -29,6 +29,8 @@ parts:
129 stage-packages:
130 - libc6
131 - dbus-x11
132+ - dmidecode
133+ - pciutils
134
135 sosreport:
136 plugin: nil

Subscribers

People subscribed via source and target branches

to all changes: