Merge ~mitchburton/ubuntu/+source/landscape-client:2087852-fix-apt-source-file-management-oracular into ubuntu/+source/landscape-client:ubuntu/oracular-devel

Proposed by Mitch Burton
Status: Needs review
Proposed branch: ~mitchburton/ubuntu/+source/landscape-client:2087852-fix-apt-source-file-management-oracular
Merge into: ubuntu/+source/landscape-client:ubuntu/oracular-devel
Diff against target: 233 lines (+212/-0)
3 files modified
debian/changelog (+7/-0)
debian/patches/fix-apt-source-file-management.patch (+204/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
Julian Andres Klode (community) Needs Fixing
git-ubuntu import Pending
Review via email: mp+486879@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Julian Andres Klode (juliank) wrote :

I'm going to reject all the further landscape-client SRU merges. Please sort out the situation with the SRU and the proposed changes for the next SRU with a dedicated sponsor before coming back to the general sponsorship queue, as the situation is too complex to unravel here.

review: Disapprove
Revision history for this message
Mitch Burton (mitchburton) wrote :

Hi juliank (and other sponsors).

I'm Sorry for clogging up the queue.

After chatting with ahasenack about it, I think approving this MP will begin to unclog things. It's a change on top of the change for #2087852 that failed verification for oracular, which is what is blocking our other SRU MPs.

Similarly, there's another MP for noble, which is in the same situation: https://code.launchpad.net/~mitchburton/ubuntu/+source/landscape-client/+git/landscape-client/+merge/486291

If it's easier, ahasenack has offered to remove the failed packages from proposed.

Revision history for this message
Julian Andres Klode (juliank) :
review: Approve
Revision history for this message
Julian Andres Klode (juliank) wrote :

Oof I did not notice earlier but

Mitch Burton <mitch@mitch-ThinkPad-T14-Gen-5>

please use a real email!

And update the bug to explain what went wrong the first time and how it's being fixed now. Ta!

review: Needs Fixing
4bbbae0... by Mitch Burton

release for oracular

Revision history for this message
Mitch Burton (mitchburton) wrote :

Fixed the email. I'll do the same for the other MPs and sort out the bug description.

Unmerged commits

4bbbae0... by Mitch Burton

release for oracular

b3c2cc2... by Mitch Burton

d/p/fix-apt-source-file-management.patch: restore .list and .sources
files when a repo profile is disassociated (LP: #2087852)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 7fa9a76..5b98f7b 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+landscape-client (24.08-0ubuntu2.3) oracular; urgency=medium
7+
8+ * d/p/fix-apt-source-file-management.patch: restore .list and .sources files
9+ when a repo profile is disassociated (LP: #2087852)
10+
11+ -- Mitch Burton <mitch.burton@canonical.com> Fri, 13 Jun 2025 09:37:09 -0700
12+
13 landscape-client (24.08-0ubuntu2.2) oracular; urgency=medium
14
15 * d/p/2087852-feat-manage-ubuntu-sources-glob.patch: include DEB822
16diff --git a/debian/patches/fix-apt-source-file-management.patch b/debian/patches/fix-apt-source-file-management.patch
17new file mode 100644
18index 0000000..271d47c
19--- /dev/null
20+++ b/debian/patches/fix-apt-source-file-management.patch
21@@ -0,0 +1,204 @@
22+Description: restore .list and .sources files when a repo profile is disassociated.
23+Author: Mitch Burton <mitch.burton@canonical.com>
24+Origin: backport, https://github.com/canonical/landscape-client/commit/c9900d7a31eb6d5822bd2a66d0a6bfa3e926a7a6
25+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/landscape-client/+bug/2087852
26+Applied-Upstream: 25.04
27+Last-Update: 2025-06-10
28+---
29+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
30+Index: landscape-client/landscape/client/manager/aptsources.py
31+===================================================================
32+--- landscape-client.orig/landscape/client/manager/aptsources.py 2025-06-10 16:24:19.394390602 -0700
33++++ landscape-client/landscape/client/manager/aptsources.py 2025-06-10 16:26:16.701119913 -0700
34+@@ -114,6 +114,12 @@
35+
36+ saved_sources = f"{self.SOURCES_LIST}.save"
37+
38++ manage_sources_list_d = getattr(
39++ self.registry.config,
40++ "manage_sources_list_d",
41++ True,
42++ )
43++
44+ if sources:
45+ fd, path = tempfile.mkstemp()
46+ os.close(fd)
47+@@ -135,24 +141,34 @@
48+ original_stat.st_uid,
49+ original_stat.st_gid,
50+ )
51++
52++ if manage_sources_list_d not in FALSE_VALUES:
53++ for pattern in self.SOURCES_LIST_D_FILE_PATTERNS:
54++ filenames = glob.glob(
55++ os.path.join(self.SOURCES_LIST_D, pattern)
56++ )
57++ for filename in filenames:
58++ shutil.move(filename, f"{filename}.save")
59+ else:
60+ # Re-instate original sources
61+ if os.path.isfile(saved_sources):
62+ shutil.move(saved_sources, self.SOURCES_LIST)
63+
64+- manage_sources_list_d = getattr(
65+- self.registry.config,
66+- "manage_sources_list_d",
67+- True,
68+- )
69++ if manage_sources_list_d not in FALSE_VALUES:
70++ for pattern in self.SOURCES_LIST_D_FILE_PATTERNS:
71++ filenames = glob.glob(
72++ os.path.join(self.SOURCES_LIST_D, f"{pattern}.save")
73++ )
74++ for filename in filenames:
75++ restored_filename = filename.removesuffix(".save")
76++ shutil.move(filename, restored_filename)
77++ # Delete Landscape source files prefixed with `landscape-`
78++ landscape_source_filenames = glob.glob(
79++ os.path.join(self.SOURCES_LIST_D, "landscape-*.list")
80++ )
81+
82+- if manage_sources_list_d not in FALSE_VALUES:
83+- for pattern in self.SOURCES_LIST_D_FILE_PATTERNS:
84+- filenames = glob.glob(
85+- os.path.join(self.SOURCES_LIST_D, pattern)
86+- )
87+- for filename in filenames:
88+- shutil.move(filename, f"{filename}.save")
89++ for source_filename in landscape_source_filenames:
90++ os.remove(source_filename)
91+
92+ for source in sources:
93+ filename = os.path.join(
94+Index: landscape-client/landscape/client/manager/tests/test_aptsources.py
95+===================================================================
96+--- landscape-client.orig/landscape/client/manager/tests/test_aptsources.py 2025-06-10 16:24:19.394390602 -0700
97++++ landscape-client/landscape/client/manager/tests/test_aptsources.py 2025-06-10 16:27:21.474385821 -0700
98+@@ -165,6 +165,109 @@
99+ with open(self.sourceslist.SOURCES_LIST) as sources:
100+ self.assertEqual("original content\n", sources.read())
101+
102++ def test_restore_sources_list_d(self):
103++ """
104++ When getting a repository message without sources, AptSources
105++ restores the previous files in sources.list.d.
106++ """
107++ FILE_1_LIST = os.path.join(
108++ self.sourceslist.SOURCES_LIST_D, "file1.list"
109++ )
110++ FILE_2_SOURCES = os.path.join(
111++ self.sourceslist.SOURCES_LIST_D, "file2.sources"
112++ )
113++ with open(
114++ FILE_1_LIST,
115++ "w",
116++ ) as source1:
117++ source1.write("ok\n")
118++ with open(
119++ FILE_2_SOURCES,
120++ "w",
121++ ) as source2:
122++ source2.write("ok\n")
123++ self.manager.dispatch_message(
124++ {
125++ "type": "apt-sources-replace",
126++ "sources": [{"name": "bla", "content": b""}],
127++ "gpg-keys": [],
128++ "operation-id": 1,
129++ },
130++ )
131++ self.assertFalse(
132++ os.path.exists(FILE_1_LIST),
133++ )
134++ self.assertFalse(os.path.exists(FILE_2_SOURCES))
135++ self.assertTrue(
136++ os.path.exists(f"{FILE_1_LIST}.save"),
137++ )
138++ self.assertTrue(
139++ os.path.exists(f"{FILE_2_SOURCES}.save"),
140++ )
141++ self.manager.dispatch_message(
142++ {
143++ "type": "apt-sources-replace",
144++ "sources": [],
145++ "gpg-keys": [],
146++ "operation-id": 2,
147++ },
148++ )
149++ self.assertTrue(
150++ os.path.exists(FILE_1_LIST),
151++ )
152++ self.assertTrue(os.path.exists(FILE_2_SOURCES))
153++ self.assertFalse(
154++ os.path.exists(f"{FILE_1_LIST}.save"),
155++ )
156++ self.assertFalse(
157++ os.path.exists(f"{FILE_2_SOURCES}.save"),
158++ )
159++ def test_restore_sources_list_d_removes_old_profile_files(self):
160++ """
161++ When getting a repository message without sources, old
162++ source files in `/etc/apt/sources.list.d` prefixed with
163++ `landscape-` will be removed.
164++ """
165++ first_source_name = "ginger"
166++ self.manager.dispatch_message(
167++ {
168++ "type": "apt-sources-replace",
169++ "sources": [{"name": first_source_name, "content": b""}],
170++ "gpg-keys": [],
171++ "operation-id": 1,
172++ },
173++ )
174++ first_sources_path = os.path.join(
175++ self.sourceslist.SOURCES_LIST_D,
176++ f"landscape-{first_source_name}.list",
177++ )
178++ self.assertTrue(os.path.exists(first_sources_path))
179++ second_source_name = "ace rothstein"
180++ self.manager.dispatch_message(
181++ {
182++ "type": "apt-sources-replace",
183++ "sources": [{"name": second_source_name, "content": b""}],
184++ "gpg-keys": [],
185++ "operation-id": 2,
186++ },
187++ )
188++ second_sources_path = os.path.join(
189++ self.sourceslist.SOURCES_LIST_D,
190++ f"landscape-{second_source_name}.list",
191++ )
192++ self.assertTrue(os.path.exists(f"{first_sources_path}.save"))
193++ self.assertTrue(os.path.exists(second_sources_path))
194++ self.manager.dispatch_message(
195++ {
196++ "type": "apt-sources-replace",
197++ "sources": [],
198++ "gpg-keys": [],
199++ "operation-id": 3,
200++ },
201++ )
202++ self.assertFalse(os.path.exists(first_sources_path))
203++ self.assertFalse(os.path.exists(second_sources_path))
204++
205+ def test_sources_list_permissions(self):
206+ """
207+ When getting a repository message, L{AptSources} keeps sources.list
208+@@ -286,12 +389,16 @@
209+ self.manager.dispatch_message(
210+ {
211+ "type": "apt-sources-replace",
212+- "sources": [],
213++ "sources": [{"name": "bla", "content": b""}],
214+ "gpg-keys": [],
215+ "operation-id": 1,
216+ },
217+ )
218+
219++ self.assertTrue(
220++ os.path.exists(self.sourceslist.SOURCES_LIST),
221++ )
222++
223+ self.assertFalse(
224+ os.path.exists(FILE_1_LIST),
225+ )
226diff --git a/debian/patches/series b/debian/patches/series
227index ac651f9..8383cb0 100644
228--- a/debian/patches/series
229+++ b/debian/patches/series
230@@ -1,2 +1,3 @@
231 fix-landscape-client-manpage.patch
232 2087852-feat-manage-ubuntu-sources-glob.patch
233+fix-apt-source-file-management.patch

Subscribers

People subscribed via source and target branches