Merge lp:~jawn-smith/update-manager/package-removal-grouping into lp:update-manager

Proposed by William Wilson
Status: Merged
Merged at revision: 2912
Proposed branch: lp:~jawn-smith/update-manager/package-removal-grouping
Merge into: lp:update-manager
Diff against target: 338 lines (+203/-47)
5 files modified
UpdateManager/Core/UpdateList.py (+34/-44)
debian/changelog (+7/-0)
tests/aptroot-grouping-test/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_lucid_main_binary-amd64_Packages (+24/-0)
tests/aptroot-grouping-test/var/lib/dpkg/status (+70/-0)
tests/test_update_list.py (+68/-3)
To merge this branch: bzr merge lp:~jawn-smith/update-manager/package-removal-grouping
Reviewer Review Type Date Requested Status
Brian Murray Approve
Review via email: mp+397190@code.launchpad.net

Commit message

LP: #1912718 disabling ubuntu base grouping for kernel autoremove and duplicate packages

Description of the change

The bug in LP: #1912718 was caused by having the kernel packages grouped under kernel_autoremove->ubuntu_base rather than just kernel_autoremove. With this update the packages will not be grouped under Ubuntu Base if they are staged for removal, but they still will be grouped under Ubuntu Base if they are staged for install/upgrade.

In response to the comment: "I don't know what the right answer for bug 1902025 is but certainly matching all kernel packages when we're trying to find meta packages isn't":
The variable names meta_pkgs and meta_grp were misleading. In the original code before the change for bug 1902025 there was a comment for the included packages that said "Return all binary packages made by the linux-meta source package". While working this we decided to include more than just the packages created by linux-meta. We have expanded the "Ubuntu Base" grouping to include packages created by linux-meta-aws as well as packages such as linux-firmware-raspi2. I have renamed the variable to ubuntu_base_pkgs to make that more clear.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

Thanks for renaming the variables I think that does make it clearer. I've a few in-line comments.

review: Needs Fixing
Revision history for this message
Brian Murray (brian-murray) wrote :

Is there a way that we can setup an automated test for LP: #1912718?

review: Needs Information
2912. By William Wilson

LP: #1902025 change to a regex from a static list for packages to group under Ubuntu Base

Revision history for this message
William Wilson (jawn-smith) wrote :

I added an automated test for LP: #1912718 but it appears I have a merge conflict in changelog, so hold off on reviewing for now.

2913. By William Wilson

Removing commented out debugging line from test

2914. By William Wilson

resolving merge conflict and deleting extra teardown

2915. By William Wilson

Adding tearDown function back in that was deleted to resolve conflict

Revision history for this message
Brian Murray (brian-murray) wrote :

Thanks for adding those additional tests, I've merged and upload this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UpdateManager/Core/UpdateList.py'
2--- UpdateManager/Core/UpdateList.py 2021-01-29 11:39:00 +0000
3+++ UpdateManager/Core/UpdateList.py 2021-02-05 22:13:57 +0000
4@@ -36,6 +36,7 @@
5 import os
6 import random
7 import glob
8+import re
9
10 from gi.repository import Gio
11
12@@ -384,43 +385,6 @@
13 return True
14 return False
15
16- def _get_linux_packages(self):
17- "Return all binary packages made by the linux-meta source package"
18- # Hard code this rather than generate from source info in cache because
19- # that might only be available if we have deb-src lines. I think we
20- # could also generate it by iterating over all the binary package info
21- # we have, but that is costly. These don't change often.
22- return ['linux',
23- 'linux-cloud-tools-generic',
24- 'linux-cloud-tools-lowlatency',
25- 'linux-cloud-tools-virtual',
26- 'linux-crashdump',
27- 'linux-generic',
28- 'linux-generic-lpae',
29- 'linux-headers-generic',
30- 'linux-headers-generic-lpae',
31- 'linux-headers-lowlatency',
32- 'linux-headers-lowlatency-lpae',
33- 'linux-headers-server',
34- 'linux-headers-virtual',
35- 'linux-image',
36- 'linux-image-extra-virtual',
37- 'linux-image-generic',
38- 'linux-image-generic-lpae',
39- 'linux-image-lowlatency',
40- 'linux-image-virtual',
41- 'linux-lowlatency',
42- 'linux-signed-generic',
43- 'linux-signed-image-generic',
44- 'linux-signed-image-lowlatency',
45- 'linux-signed-lowlatency',
46- 'linux-source',
47- 'linux-tools-generic',
48- 'linux-tools-generic-lpae',
49- 'linux-tools-lowlatency',
50- 'linux-tools-virtual',
51- 'linux-virtual']
52-
53 def _make_groups(self, cache, pkgs, eventloop_callback, to_remove=False):
54 if not pkgs:
55 return []
56@@ -452,15 +416,41 @@
57 if ungrouped_pkgs:
58 # Separate out system base packages. If we have already found an
59 # application for all updates, don't bother.
60- meta_group = UpdateGroup(None, None, None, to_remove)
61+ linux_names = ("linux$",
62+ "linux-.*-buildinfo.*",
63+ "linux-.*-dev.*",
64+ "linux-.*-generic.*",
65+ "linux-.*-headers.*",
66+ "linux-.*-hwe.*",
67+ "linux-.*-gcp.*",
68+ "linux-.*-kernel.*",
69+ "linux-.*-lowlatency.*",
70+ "linux-.*-modules.*",
71+ "linux-.*-raspi.*",
72+ "linux-.*-tools.*",
73+ "linux-.*-virtual.*",
74+ "linux-base.*",
75+ "linux-crashdump.*",
76+ "linux-doc.*")
77+ linux_regexp = re.compile("(" + "|".join(
78+ ["^" + n for n in linux_names]) + ")")
79+ ubuntu_base_group = UpdateGroup(None, None, None, to_remove)
80 flavor_package = utils.get_ubuntu_flavor_package(cache=cache)
81- meta_pkgs = [flavor_package, "ubuntu-standard", "ubuntu-minimal"]
82- meta_pkgs.extend(self._get_linux_packages())
83- for pkg in meta_pkgs:
84- if pkg in cache:
85- meta_group.add(cache[pkg])
86+ ubuntu_base_pkgs = [flavor_package,
87+ "ubuntu-standard",
88+ "ubuntu-minimal"]
89+ for pkg in cache:
90+ if linux_regexp.match(pkg.name):
91+ ubuntu_base_pkgs.append(pkg.name)
92+ for pkg in ubuntu_base_pkgs:
93+ if pkg in cache and not to_remove:
94+ # the check for to_remove avoids creating groups in
95+ # kernel_autoremove and duplicate package sections
96+ # which fixes LP: #1912718
97+ ubuntu_base_group.add(cache[pkg])
98 for pkg in ungrouped_pkgs:
99- if meta_group.is_dependency(pkg, cache, eventloop_callback):
100+ if ubuntu_base_group.is_dependency(pkg, cache,
101+ eventloop_callback):
102 if system_group is None:
103 system_group = UpdateSystemGroup(cache, to_remove)
104 system_group.add(pkg)
105
106=== modified file 'debian/changelog'
107--- debian/changelog 2021-02-04 18:44:07 +0000
108+++ debian/changelog 2021-02-05 22:13:57 +0000
109@@ -1,7 +1,14 @@
110 update-manager (1:21.04.8) UNRELEASED; urgency=medium
111
112+ [ Brian Murray ]
113 * Clean up apt cache binary files created by the unit tests thanks to
114 William Wilson for the patch.
115+
116+ [ William Wilson ]
117+ * Changing to a regex from a static list of packages to be included under
118+ "Ubuntu Base". This regex exands the list of packages under "Ubuntu Base"
119+ to include all kernel packages as well as binary packages built by
120+ linux-meta source packages (LP: #1902025)
121
122 -- Brian Murray <brian@ubuntu.com> Thu, 04 Feb 2021 10:42:55 -0800
123
124
125=== modified file 'tests/aptroot-grouping-test/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_lucid_main_binary-amd64_Packages'
126--- tests/aptroot-grouping-test/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_lucid_main_binary-amd64_Packages 2021-01-29 11:39:00 +0000
127+++ tests/aptroot-grouping-test/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_lucid_main_binary-amd64_Packages 2021-02-05 22:13:57 +0000
128@@ -78,3 +78,27 @@
129 Recommends: base-pkg
130 Description: meta package
131 Origin: Ubuntu
132+
133+Package: linux-test-hwe
134+Priority: optional
135+Section: admin
136+Installed-Size: 1
137+Maintainer: Foo <foo@bar.com>
138+Architecture: all
139+Version: 1
140+Size: 1
141+Recommends: base-pkg
142+Description: positive test for linux package names
143+Origin: Ubuntu
144+
145+Package: linux-show-player
146+Priority: optional
147+Section: admin
148+Installed-Size: 1
149+Maintainer: Foo <foo@bar.com>
150+Architecture: all
151+Version: 1
152+Size: 1
153+Recommends: base-pkg
154+Description: negative test for linux package names
155+Origin: Ubuntu
156
157=== modified file 'tests/aptroot-grouping-test/var/lib/dpkg/status'
158--- tests/aptroot-grouping-test/var/lib/dpkg/status 2021-01-29 11:39:00 +0000
159+++ tests/aptroot-grouping-test/var/lib/dpkg/status 2021-02-05 22:13:57 +0000
160@@ -80,3 +80,73 @@
161 Architecture: all
162 Version: 0.1
163 Description: an installed package that only one app depends on
164+
165+Package: ubuntu-minimal
166+Status: install ok installed
167+Priority: optional
168+Section: admin
169+Installed-Size: 1
170+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
171+Architecture: all
172+Version: 0.1
173+Description: meta package
174+
175+Package: linux-test-hwe
176+Status: install ok installed
177+Priority: optional
178+Section: admin
179+Installed-Size: 1
180+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
181+Architecture: all
182+Version: 0.1
183+Description: positive test for linux package names
184+
185+Package: linux-show-player
186+Status: install ok installed
187+Priority: optional
188+Section: admin
189+Installed-Size: 1
190+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
191+Architecture: all
192+Version: 0.1
193+Description: negative test for linux package names
194+
195+Package: linux-generic-to-remove
196+Status: install ok installed
197+Priority: optional
198+Section: kernel
199+Installed-Size: 1
200+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
201+Architecture: all
202+Version: 0.1
203+Description: linux kernel autoremove packages that should not be grouped
204+
205+Package: linux-headers-to-remove
206+Status: install ok installed
207+Priority: optional
208+Section: kernel
209+Installed-Size: 1
210+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
211+Architecture: all
212+Version: 0.1
213+Description: linux kernel autoremove packages that should not be grouped
214+
215+Package: linux-generic-dup1
216+Status: install ok installed
217+Priority: optional
218+Section: admin
219+Installed-Size: 1
220+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
221+Architecture: all
222+Version: 0.1
223+Description: duplicate package that should not be grouped
224+
225+Package: linux-generic-dup2
226+Status: install ok installed
227+Priority: optional
228+Section: admin
229+Installed-Size: 1
230+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
231+Architecture: all
232+Version: 0.1
233+Description: duplicate package that should not be grouped
234
235=== modified file 'tests/test_update_list.py'
236--- tests/test_update_list.py 2021-02-04 18:44:07 +0000
237+++ tests/test_update_list.py 2021-02-05 22:13:57 +0000
238@@ -119,15 +119,28 @@
239 apt.apt_pkg.config.set("APT::Architecture", "amd64")
240 self.addCleanup(
241 lambda: apt.apt_pkg.config.set("APT::Architecture", real_arch))
242+
243+ # override the kernel autoremove regex
244+ real_versioned_kernel_pkgs = apt.apt_pkg.config.value_list(
245+ "APT::VersionedKernelPackages")
246+ apt.apt_pkg.config.set("APT::VersionedKernelPackages", "linux-.*")
247+ self.addCleanup(
248+ lambda: apt.apt_pkg.config.set("APT::VersionedKernelPackages",
249+ str(real_versioned_kernel_pkgs)))
250+
251 self.aptroot = os.path.join(CURDIR,
252 "aptroot-grouping-test")
253 self.cache = MyCache(apt.progress.base.OpProgress(),
254 rootdir=self.aptroot)
255 self.cache.open()
256+ self.cache["linux-generic-to-remove"].mark_auto(True)
257+ self.cache["linux-headers-to-remove"].mark_auto(True)
258 mock_installed.__get__ = self.fake_installed_files
259 mock_desktop.side_effect = self.fake_desktop
260 self.updates_list = UpdateList.UpdateList(parent=None, dist='lucid')
261- self.updates_list.update(self.cache)
262+ self.updates_list.update(self.cache,
263+ duplicate_packages=["linux-generic-dup1",
264+ "linux-generic-dup2"])
265
266 def tearDown(self):
267 try:
268@@ -181,9 +194,18 @@
269 self.assertListEqual([x.pkg.name for x in group.items],
270 ['installed-pkg'])
271
272+ def test_negative_regex_match(self):
273+ self.assertGreater(len(self.updates_list.update_groups), 3)
274+ group = self.updates_list.update_groups[3]
275+ self.assertIsInstance(group, UpdateList.UpdatePackageGroup)
276+ self.assertIsNotNone(group.core_item)
277+ self.assertEqual(group.core_item.pkg.name, 'linux-show-player')
278+ self.assertListEqual([x.pkg.name for x in group.items],
279+ ['linux-show-player'])
280+
281 def test_pkg_multiple_deps(self):
282- self.assertEqual(len(self.updates_list.update_groups), 4)
283- group = self.updates_list.update_groups[3]
284+ self.assertGreater(len(self.updates_list.update_groups), 4)
285+ group = self.updates_list.update_groups[4]
286 self.assertIsInstance(group, UpdateList.UpdatePackageGroup)
287 self.assertIsNotNone(group.core_item)
288 self.assertEqual(group.core_item.pkg.name,
289@@ -198,6 +220,49 @@
290 self.assertIsNone(group.core_item)
291 self.assertListEqual([x.pkg.name for x in group.items], ['base-pkg'])
292
293+ def test_base_grouping(self):
294+ self.assertEqual(len(self.updates_list.update_groups), 6)
295+ group = self.updates_list.update_groups[5]
296+ self.assertIsInstance(group, UpdateList.UpdateSystemGroup)
297+ self.assertIsNone(group.core_item)
298+ self.assertListEqual([x.pkg.name for x in group.items],
299+ ['ubuntu-minimal',
300+ 'linux-test-hwe'])
301+
302+ def test_autoremove_grouping(self):
303+ # test that packages staged for removal aren't grouped if they are
304+ # kernel autoremove packages (LP: #1912718)
305+ self.assertGreater(len(self.updates_list.kernel_autoremove_groups), 0)
306+ group = self.updates_list.kernel_autoremove_groups[0]
307+ self.assertIsInstance(group, UpdateList.UpdatePackageGroup)
308+ self.assertIsNotNone(group.core_item)
309+ self.assertListEqual([x.pkg.name for x in group.items],
310+ ['linux-generic-to-remove'])
311+
312+ self.assertEqual(len(self.updates_list.kernel_autoremove_groups), 2)
313+ group = self.updates_list.kernel_autoremove_groups[1]
314+ self.assertIsInstance(group, UpdateList.UpdatePackageGroup)
315+ self.assertIsNotNone(group.core_item)
316+ self.assertListEqual([x.pkg.name for x in group.items],
317+ ['linux-headers-to-remove'])
318+
319+ def test_duplicate_grouping(self):
320+ # test that packages staged for removal aren't grouped if they are
321+ # duplicate packages (LP: #1912718)
322+ self.assertGreater(len(self.updates_list.duplicate_groups), 0)
323+ group = self.updates_list.duplicate_groups[0]
324+ self.assertIsInstance(group, UpdateList.UpdatePackageGroup)
325+ self.assertIsNotNone(group.core_item)
326+ self.assertListEqual([x.pkg.name for x in group.items],
327+ ['linux-generic-dup1'])
328+
329+ self.assertEqual(len(self.updates_list.duplicate_groups), 2)
330+ group = self.updates_list.duplicate_groups[1]
331+ self.assertIsInstance(group, UpdateList.UpdatePackageGroup)
332+ self.assertIsNotNone(group.core_item)
333+ self.assertListEqual([x.pkg.name for x in group.items],
334+ ['linux-generic-dup2'])
335+
336
337 if __name__ == "__main__":
338 unittest.main()

Subscribers

People subscribed via source and target branches

to status/vote changes: