Merge ~enr0n/ubuntu-release-upgrader:ubuntu/noble into ubuntu-release-upgrader:ubuntu/noble

Proposed by Nick Rosbrook
Status: Merged
Merged at revision: a9c47aca28bfd7fcc4a76cf92e945a733ffad715
Proposed branch: ~enr0n/ubuntu-release-upgrader:ubuntu/noble
Merge into: ubuntu-release-upgrader:ubuntu/noble
Diff against target: 176 lines (+16/-104)
3 files modified
DistUpgrade/DistUpgradeController.py (+13/-10)
DistUpgrade/DistUpgradeQuirks.py (+3/-45)
tests/test_quirks.py (+0/-49)
Reviewer Review Type Date Requested Status
Julian Andres Klode Approve
Review via email: mp+466881@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Julian Andres Klode (juliank) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/DistUpgrade/DistUpgradeController.py b/DistUpgrade/DistUpgradeController.py
2index eebe281..674a4b8 100644
3--- a/DistUpgrade/DistUpgradeController.py
4+++ b/DistUpgrade/DistUpgradeController.py
5@@ -31,6 +31,7 @@ import locale
6 import logging
7 import shutil
8 import glob
9+import tempfile
10 import time
11 import copy
12 from configparser import NoOptionError
13@@ -1807,18 +1808,20 @@ class DistUpgradeController(object):
14 # here in the simulation as we'd write the simulated end result to the file, so let's
15 # not write the file for the simulation.
16 backups["Dir::State::extended_states"] = [apt_pkg.config["Dir::State::extended_states"]]
17- apt_pkg.config["Dir::State::extended_states"] = "/dev/null"
18
19- for lst in "dpkg::pre-invoke", "dpkg::pre-install-pkgs", "dpkg::post-invoke", "dpkg::post-install-pkgs":
20- backups[lst + "::"] = apt_pkg.config.value_list(lst)
21- apt_pkg.config.clear(lst)
22+ with tempfile.NamedTemporaryFile(prefix='apt_extended_states_') as f:
23+ apt_pkg.config["Dir::State::extended_states"] = f.name
24
25- try:
26- return self.doDistUpgrade()
27- finally:
28- for lst in backups:
29- for item in backups[lst]:
30- apt_pkg.config.set(lst, item)
31+ for lst in "dpkg::pre-invoke", "dpkg::pre-install-pkgs", "dpkg::post-invoke", "dpkg::post-install-pkgs":
32+ backups[lst + "::"] = apt_pkg.config.value_list(lst)
33+ apt_pkg.config.clear(lst)
34+
35+ try:
36+ return self.doDistUpgrade()
37+ finally:
38+ for lst in backups:
39+ for item in backups[lst]:
40+ apt_pkg.config.set(lst, item)
41
42 def doDistUpgrade(self):
43 # add debug code only here
44diff --git a/DistUpgrade/DistUpgradeQuirks.py b/DistUpgrade/DistUpgradeQuirks.py
45index 0ca7285..a549d8c 100644
46--- a/DistUpgrade/DistUpgradeQuirks.py
47+++ b/DistUpgrade/DistUpgradeQuirks.py
48@@ -123,7 +123,6 @@ class DistUpgradeQuirks(object):
49 self._test_and_fail_on_i386()
50 self._test_and_fail_on_aufs()
51 self._test_and_fail_on_power8()
52- self._test_and_fail_on_bios_with_xfs_boot()
53 self._test_and_fail_on_armhf_raspi()
54 self._test_and_fail_on_tpm_fde()
55
56@@ -1680,50 +1679,6 @@ class DistUpgradeQuirks(object):
57 logging.debug(f'Failed to enable {os.path.basename(unit_file)}. '
58 'Font will not be restored on reboot')
59
60- def _test_and_fail_on_bios_with_xfs_boot(self):
61- """
62- If this system is BIOS and has XFS on /boot, do not allow the upgrade
63- to happen (LP: #2039172).
64- """
65- if os.path.isdir('/sys/firmware/efi'):
66- # UEFI boot, nothing to do.
67- return
68-
69- boot_fs = None
70- root_fs = None
71- with open('/proc/mounts') as f:
72- for line in f.readlines():
73- try:
74- (what, where, fs, opts, a, b) = line.strip().split()
75- where = where.lower()
76- fs = fs.lower()
77- except ValueError:
78- logging.debug(
79- f'line \'{line}\' in /proc/mounts not understood'
80- )
81- continue
82-
83- if where == '/':
84- root_fs = fs
85- elif where == '/boot':
86- boot_fs = fs
87-
88- if boot_fs and root_fs:
89- break
90-
91- if boot_fs == 'xfs' or (boot_fs is None and root_fs == 'xfs'):
92- # If we got to this point, then this is a BIOS system, and /boot is
93- # XFS or / is XFS and there is no separate /boot partition. Do not
94- # allow the upgrade to happen.
95- logging.error('Cannot upgrade system with BIOS and XFS /boot')
96- self._view.error(
97- _("Cannot upgrade this system"),
98- _("Due to a bug in grub, this system cannot "
99- "be safely upgraded at this time.\n\n"
100- "See https://launchpad.net/bugs/2039172.")
101- )
102- self.controller.abort()
103-
104 def _maybe_remove_gpg_wks_server(self):
105 """
106 Prevent postfix from being unnecessarily installed, and leading to a
107@@ -1842,6 +1797,9 @@ class DistUpgradeQuirks(object):
108 ver.parent_pkg
109 )
110
111+ if replacement.candidate is None:
112+ continue
113+
114 if replacement.candidate._cand != ver:
115 continue
116
117diff --git a/tests/test_quirks.py b/tests/test_quirks.py
118index a3fabec..10d95f9 100644
119--- a/tests/test_quirks.py
120+++ b/tests/test_quirks.py
121@@ -1053,55 +1053,6 @@ MMU : Hash
122
123 mock_file.assert_called_with("/proc/cpuinfo")
124
125- @mock.patch('os.path.isdir')
126- def test_bios_with_xfs_boot_fail(self, mock_is_dir):
127- proc_mounts = """\
128-sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
129-proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
130-{boot}
131-/dev/mapper/vgubuntu-root / {fs} rw,relatime,errors=remount-ro 0 0
132-securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
133-tmpfs /dev/shm tmpfs rw,nosuid,nodev,inode64 0 0
134-tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k,inode64 0 0
135-cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime 0 0
136-"""
137- boot_line = '/dev/nvme0n1p2 /boot {fs} rw,relatime 0 0'
138-
139- test_table = [
140- # / fs, /boot fs, expected abort calls if BIOS
141- ('xfs', None, 1),
142- ('ext4', None, 0),
143- ('xfs', 'xfs', 1),
144- ('ext4', 'xfs', 1),
145- ('xfs', 'ext4', 0),
146- ('ext4', 'ext4', 0),
147- ]
148-
149- for (root_fs, boot_fs, num_abort_calls) in test_table:
150- boot = boot_line.format(fs=boot_fs) if boot_fs else ''
151- m = mock.mock_open(
152- read_data=proc_mounts.format(fs=root_fs, boot=boot)
153- )
154- with mock.patch('builtins.open', m) as mock_file:
155- controller = mock.Mock()
156- config = mock.Mock()
157- q = DistUpgradeQuirks(controller, config)
158-
159- # UEFI
160- mock_is_dir.return_value = True # /sys/firmware/efi
161- q._test_and_fail_on_bios_with_xfs_boot()
162- self.assertEqual(len(controller.abort.mock_calls), 0)
163-
164- # BIOS
165- mock_is_dir.return_value = False # /sys/firmware/efi
166- q._test_and_fail_on_bios_with_xfs_boot()
167- self.assertEqual(
168- len(controller.abort.mock_calls),
169- num_abort_calls,
170- f'root_fs = {root_fs}, boot_fs = {boot_fs}',
171- )
172- mock_file.assert_called_with('/proc/mounts')
173-
174 def test_raspi_armhf_abort_upgrade(self):
175 for arch in ('armhf', 'arm64'):
176 with mock.patch(

Subscribers

People subscribed via source and target branches