Merge ~renanrodrigo/ubuntu/+source/update-notifier:no-esm-motd-bionic into ubuntu/+source/update-notifier:ubuntu/bionic-updates

Proposed by Renan Rodrigo
Status: Needs review
Proposed branch: ~renanrodrigo/ubuntu/+source/update-notifier:no-esm-motd-bionic
Merge into: ubuntu/+source/update-notifier:ubuntu/bionic-updates
Diff against target: 485 lines (+173/-48)
4 files modified
data/apt_check.py (+34/-16)
data/update-motd-updates-available (+19/-7)
debian/changelog (+7/-0)
tests/test_motd.py (+113/-25)
Reviewer Review Type Date Requested Status
Nick Rosbrook (community) Approve
Julian Andres Klode Pending
git-ubuntu import Pending
Review via email: mp+459798@code.launchpad.net

Description of the change

This fixes #2015420 by adding a flag that hides esm-related messages from the human readable output of data/apt_check.py

To post a comment you must log in.
Revision history for this message
Nick Rosbrook (enr0n) wrote :

I merged this, but into https://git.launchpad.net/update-notifier/log/?h=bionic, and uploaded to the bionic unapproved queue.

review: Approve

Unmerged commits

4e30f81... by Renan Rodrigo

update changelog entry for version 3.192.1.20

Signed-off-by: Renan Rodrigo <email address hidden>

15e63f7... by Renan Rodrigo

apt_check: add option to hide esm messages from human-readable output

Users want to be able to see the regular updates + security updates on
MOTDs, but without mentions to ESM.

LP: #2015420

Signed-off-by: Renan Rodrigo <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/data/apt_check.py b/data/apt_check.py
2index 164b2f9..7a35ba8 100755
3--- a/data/apt_check.py
4+++ b/data/apt_check.py
5@@ -242,21 +242,23 @@ def write_human_readable_summary(outstream, upgrades, security_updates,
6 esm_infra_updates, esm_apps_updates,
7 have_esm_infra, have_esm_apps,
8 disabled_esm_infra_updates,
9- disabled_esm_apps_updates):
10+ disabled_esm_apps_updates,
11+ hide_esm_messages=False):
12
13 " write out human summary to outstream "
14 esm_distro = is_esm_distro()
15 lts_distro = is_lts_distro()
16
17- if have_esm_infra is not None and esm_distro:
18- _output_esm_service_status(
19- outstream, have_esm_infra, service_type="Infrastructure"
20- )
21+ if not hide_esm_messages:
22+ if have_esm_infra is not None and esm_distro:
23+ _output_esm_service_status(
24+ outstream, have_esm_infra, service_type="Infrastructure"
25+ )
26
27- if have_esm_apps is not None and lts_distro and not esm_distro:
28- _output_esm_service_status(
29- outstream, have_esm_apps, service_type="Applications"
30- )
31+ if have_esm_apps is not None and lts_distro and not esm_distro:
32+ _output_esm_service_status(
33+ outstream, have_esm_apps, service_type="Applications"
34+ )
35
36 outstream.write(
37 gettext.dngettext("update-notifier",
38@@ -265,10 +267,11 @@ def write_human_readable_summary(outstream, upgrades, security_updates,
39 upgrades) % upgrades
40 )
41
42- _output_esm_package_count(
43- outstream, service_type="Infra", esm_pkg_count=esm_infra_updates)
44- _output_esm_package_count(
45- outstream, service_type="Apps", esm_pkg_count=esm_apps_updates)
46+ if not hide_esm_messages:
47+ _output_esm_package_count(
48+ outstream, service_type="Infra", esm_pkg_count=esm_infra_updates)
49+ _output_esm_package_count(
50+ outstream, service_type="Apps", esm_pkg_count=esm_apps_updates)
51
52 if security_updates > 0:
53 outstream.write("\n")
54@@ -291,14 +294,22 @@ def write_human_readable_summary(outstream, upgrades, security_updates,
55 have_esm_apps is not None,
56 not have_esm_apps,
57 lts_distro,
58- not esm_distro
59+ not esm_distro,
60+ not hide_esm_messages,
61 ]
62 ):
63 _output_esm_package_alert(
64 outstream, service_type="Apps",
65 disabled_pkg_count=disabled_esm_apps_updates)
66
67- if have_esm_infra is not None and not have_esm_infra and esm_distro:
68+ if all(
69+ [
70+ have_esm_infra is not None,
71+ not have_esm_infra,
72+ esm_distro,
73+ not hide_esm_messages,
74+ ]
75+ ):
76 _output_esm_package_alert(
77 outstream, service_type="Infra",
78 disabled_pkg_count=disabled_esm_infra_updates,
79@@ -493,7 +504,8 @@ def run(options=None):
80 esm_infra_updates, esm_apps_updates,
81 have_esm_infra, have_esm_apps,
82 disabled_esm_infra_updates,
83- disabled_esm_apps_updates)
84+ disabled_esm_apps_updates,
85+ options.hide_esm_messages)
86 else:
87 # print the number of regular upgrades and the number of
88 # security upgrades
89@@ -528,6 +540,12 @@ if __name__ == "__main__":
90 dest="readable_output",
91 help=_("Show human readable output on stdout"))
92 parser.add_option("",
93+ "--no-esm-messages",
94+ action="store_true",
95+ dest="hide_esm_messages",
96+ help=_("Do not show esm related messages in human "
97+ "readable output"))
98+ parser.add_option("",
99 "--security-updates-unattended",
100 action="store_true",
101 help=_("Return the time in days when security updates "
102diff --git a/data/update-motd-updates-available b/data/update-motd-updates-available
103index 7528b50..095dac5 100755
104--- a/data/update-motd-updates-available
105+++ b/data/update-motd-updates-available
106@@ -2,13 +2,25 @@
107 #
108 # helper for update-motd
109
110+NEED_UPDATE_CHECK="no"
111+NO_ESM_MESSAGES=""
112
113-# poor mans force
114-if [ "$1" = "--force" ]; then
115- NEED_UPDATE_CHECK=yes
116-else
117- NEED_UPDATE_CHECK=no
118-fi
119+while [[ $# -gt 0 ]]; do
120+ case $1 in
121+ # poor mans force
122+ --force)
123+ NEED_UPDATE_CHECK="yes"
124+ shift
125+ ;;
126+ --no-esm-messages)
127+ NO_ESM_MESSAGES="--no-esm-messages"
128+ shift
129+ ;;
130+ *)
131+ shift
132+ ;;
133+ esac
134+done
135
136 # check time when we did the last update check
137 stamp="/var/lib/update-notifier/updates-available"
138@@ -52,7 +64,7 @@ if [ "$NEED_UPDATE_CHECK" = "yes" ]; then
139 {
140
141 echo ""
142- /usr/lib/update-notifier/apt-check --human-readable
143+ /usr/lib/update-notifier/apt-check --human-readable "$NO_ESM_MESSAGES"
144 echo ""
145 } > "$tmpfile"
146 mv "$tmpfile" "$stamp"
147diff --git a/debian/changelog b/debian/changelog
148index 5732c80..9c0b2bc 100644
149--- a/debian/changelog
150+++ b/debian/changelog
151@@ -1,3 +1,10 @@
152+update-notifier (3.192.1.20) bionic; urgency=medium
153+
154+ * apt-check: add option to hide ESM messages from the human readable output.
155+ (LP: #2015420)
156+
157+ -- Renan Rodrigo Barbosa <renanrodrigo@canonical.com> Wed, 31 Jan 2024 11:40:02 -0300
158+
159 update-notifier (3.192.1.19) bionic; urgency=medium
160
161 * Isolate creation of the esm apt cache in apt-check (LP: #2008212)
162diff --git a/tests/test_motd.py b/tests/test_motd.py
163index db62c99..59a080c 100755
164--- a/tests/test_motd.py
165+++ b/tests/test_motd.py
166@@ -29,7 +29,7 @@ class TestMotd(unittest.TestCase):
167 esm_infra_updates=0, esm_apps_updates=0,
168 have_esm_infra=False, have_esm_apps=False,
169 disabled_esm_infra_updates=1,
170- disabled_esm_apps_updates=0),
171+ disabled_esm_apps_updates=0, hide_esm_messages=False),
172 textwrap.dedent(
173 """\
174 Expanded Security Maintenance for Infrastructure is not enabled.
175@@ -52,7 +52,7 @@ class TestMotd(unittest.TestCase):
176 esm_infra_updates=0, esm_apps_updates=0,
177 have_esm_infra=False, have_esm_apps=False,
178 disabled_esm_infra_updates=23,
179- disabled_esm_apps_updates=0),
180+ disabled_esm_apps_updates=0, hide_esm_messages=False),
181 textwrap.dedent(
182 """\
183 Expanded Security Maintenance for Infrastructure is not enabled.
184@@ -76,7 +76,7 @@ class TestMotd(unittest.TestCase):
185 esm_infra_updates=0, esm_apps_updates=0,
186 have_esm_infra=False, have_esm_apps=False,
187 disabled_esm_infra_updates=0,
188- disabled_esm_apps_updates=0),
189+ disabled_esm_apps_updates=0, hide_esm_messages=False),
190 textwrap.dedent(
191 """\
192 Expanded Security Maintenance for Infrastructure is not enabled.
193@@ -99,7 +99,7 @@ class TestMotd(unittest.TestCase):
194 esm_infra_updates=0, esm_apps_updates=0,
195 have_esm_infra=False, have_esm_apps=False,
196 disabled_esm_infra_updates=0,
197- disabled_esm_apps_updates=0),
198+ disabled_esm_apps_updates=0, hide_esm_messages=False),
199 textwrap.dedent(
200 """\
201 Expanded Security Maintenance for Infrastructure is not enabled.
202@@ -121,7 +121,7 @@ class TestMotd(unittest.TestCase):
203 esm_infra_updates=0, esm_apps_updates=0,
204 have_esm_infra=False, have_esm_apps=False,
205 disabled_esm_infra_updates=0,
206- disabled_esm_apps_updates=0),
207+ disabled_esm_apps_updates=0, hide_esm_messages=False),
208 textwrap.dedent(
209 """\
210 Expanded Security Maintenance for Infrastructure is not enabled.
211@@ -142,7 +142,7 @@ class TestMotd(unittest.TestCase):
212 esm_infra_updates=13, esm_apps_updates=0,
213 have_esm_infra=True, have_esm_apps=False,
214 disabled_esm_infra_updates=0,
215- disabled_esm_apps_updates=0),
216+ disabled_esm_apps_updates=0, hide_esm_messages=False),
217 textwrap.dedent(
218 """\
219 Expanded Security Maintenance for Infrastructure is enabled.
220@@ -162,7 +162,7 @@ class TestMotd(unittest.TestCase):
221 esm_infra_updates=13, esm_apps_updates=0,
222 have_esm_infra=True, have_esm_apps=False,
223 disabled_esm_infra_updates=0,
224- disabled_esm_apps_updates=0),
225+ disabled_esm_apps_updates=0, hide_esm_messages=False),
226 textwrap.dedent(
227 """\
228 Expanded Security Maintenance for Infrastructure is enabled.
229@@ -183,7 +183,7 @@ class TestMotd(unittest.TestCase):
230 esm_infra_updates=0, esm_apps_updates=0,
231 have_esm_infra=True, have_esm_apps=False,
232 disabled_esm_infra_updates=0,
233- disabled_esm_apps_updates=10),
234+ disabled_esm_apps_updates=10, hide_esm_messages=False),
235 textwrap.dedent(
236 """\
237 Expanded Security Maintenance for Infrastructure is enabled.
238@@ -201,7 +201,7 @@ class TestMotd(unittest.TestCase):
239 esm_infra_updates=15, esm_apps_updates=15,
240 have_esm_infra=True, have_esm_apps=True,
241 disabled_esm_infra_updates=0,
242- disabled_esm_apps_updates=0),
243+ disabled_esm_apps_updates=0, hide_esm_messages=False),
244 textwrap.dedent(
245 """
246 Expanded Security Maintenance for Infrastructure is enabled.
247@@ -222,7 +222,7 @@ class TestMotd(unittest.TestCase):
248 esm_infra_updates=0, esm_apps_updates=15,
249 have_esm_infra=False, have_esm_apps=True,
250 disabled_esm_infra_updates=0,
251- disabled_esm_apps_updates=0),
252+ disabled_esm_apps_updates=0, hide_esm_messages=False),
253 textwrap.dedent(
254 """
255 Expanded Security Maintenance for Infrastructure is not enabled.
256@@ -247,7 +247,7 @@ class TestMotd(unittest.TestCase):
257 esm_infra_updates=0, esm_apps_updates=1,
258 have_esm_infra=False, have_esm_apps=True,
259 disabled_esm_infra_updates=40,
260- disabled_esm_apps_updates=0),
261+ disabled_esm_apps_updates=0, hide_esm_messages=False),
262 textwrap.dedent(
263 """
264 Expanded Security Maintenance for Infrastructure is not enabled.
265@@ -272,7 +272,7 @@ class TestMotd(unittest.TestCase):
266 esm_infra_updates=0, esm_apps_updates=1,
267 have_esm_infra=False, have_esm_apps=True,
268 disabled_esm_infra_updates=40,
269- disabled_esm_apps_updates=0),
270+ disabled_esm_apps_updates=0, hide_esm_messages=False),
271 textwrap.dedent(
272 """
273 Expanded Security Maintenance for Applications is enabled.
274@@ -293,7 +293,7 @@ class TestMotd(unittest.TestCase):
275 esm_infra_updates=0, esm_apps_updates=0,
276 have_esm_infra=False, have_esm_apps=False,
277 disabled_esm_infra_updates=0,
278- disabled_esm_apps_updates=40),
279+ disabled_esm_apps_updates=40, hide_esm_messages=False),
280 textwrap.dedent(
281 """\
282 Expanded Security Maintenance for Infrastructure is not enabled.
283@@ -316,7 +316,7 @@ class TestMotd(unittest.TestCase):
284 esm_infra_updates=0, esm_apps_updates=0,
285 have_esm_infra=None, have_esm_apps=None,
286 disabled_esm_infra_updates=0,
287- disabled_esm_apps_updates=0),
288+ disabled_esm_apps_updates=0, hide_esm_messages=False),
289 textwrap.dedent(
290 """\
291 30 updates can be applied immediately.
292@@ -334,7 +334,7 @@ class TestMotd(unittest.TestCase):
293 esm_infra_updates=0, esm_apps_updates=0,
294 have_esm_infra=None, have_esm_apps=None,
295 disabled_esm_infra_updates=0,
296- disabled_esm_apps_updates=0),
297+ disabled_esm_apps_updates=0, hide_esm_messages=False),
298 textwrap.dedent(
299 """\
300 30 updates can be applied immediately.
301@@ -352,7 +352,7 @@ class TestMotd(unittest.TestCase):
302 esm_infra_updates=0, esm_apps_updates=0,
303 have_esm_infra=False, have_esm_apps=False,
304 disabled_esm_infra_updates=0,
305- disabled_esm_apps_updates=40),
306+ disabled_esm_apps_updates=40, hide_esm_messages=False),
307 textwrap.dedent(
308 """\
309 30 updates can be applied immediately.
310@@ -375,7 +375,7 @@ class TestMotd(unittest.TestCase):
311 esm_infra_updates=0, esm_apps_updates=0,
312 have_esm_infra=False, have_esm_apps=False,
313 disabled_esm_infra_updates=0,
314- disabled_esm_apps_updates=40),
315+ disabled_esm_apps_updates=40, hide_esm_messages=False),
316 textwrap.dedent(
317 """\
318 30 updates can be applied immediately.
319@@ -393,7 +393,7 @@ class TestMotd(unittest.TestCase):
320 esm_infra_updates=0, esm_apps_updates=0,
321 have_esm_infra=False, have_esm_apps=False,
322 disabled_esm_infra_updates=10,
323- disabled_esm_apps_updates=40),
324+ disabled_esm_apps_updates=40, hide_esm_messages=False),
325 textwrap.dedent(
326 """\
327 Expanded Security Maintenance for Applications is not enabled.
328@@ -416,7 +416,7 @@ class TestMotd(unittest.TestCase):
329 esm_infra_updates=0, esm_apps_updates=0,
330 have_esm_infra=None, have_esm_apps=None,
331 disabled_esm_infra_updates=0,
332- disabled_esm_apps_updates=0),
333+ disabled_esm_apps_updates=0, hide_esm_messages=False),
334 textwrap.dedent(
335 """\
336 0 updates can be applied immediately.
337@@ -432,7 +432,7 @@ class TestMotd(unittest.TestCase):
338 esm_infra_updates=0, esm_apps_updates=0,
339 have_esm_infra=None, have_esm_apps=None,
340 disabled_esm_infra_updates=0,
341- disabled_esm_apps_updates=0),
342+ disabled_esm_apps_updates=0, hide_esm_messages=False),
343 textwrap.dedent(
344 """\
345 1 update can be applied immediately.
346@@ -449,7 +449,7 @@ class TestMotd(unittest.TestCase):
347 esm_infra_updates=0, esm_apps_updates=0,
348 have_esm_infra=None, have_esm_apps=None,
349 disabled_esm_infra_updates=0,
350- disabled_esm_apps_updates=0),
351+ disabled_esm_apps_updates=0, hide_esm_messages=False),
352 textwrap.dedent(
353 """\
354 1 update can be applied immediately.
355@@ -467,7 +467,7 @@ class TestMotd(unittest.TestCase):
356 esm_infra_updates=0, esm_apps_updates=0,
357 have_esm_infra=None, have_esm_apps=None,
358 disabled_esm_infra_updates=0,
359- disabled_esm_apps_updates=0),
360+ disabled_esm_apps_updates=0, hide_esm_messages=False),
361 textwrap.dedent(
362 """\
363 0 updates can be applied immediately.
364@@ -483,7 +483,7 @@ class TestMotd(unittest.TestCase):
365 esm_infra_updates=0, esm_apps_updates=0,
366 have_esm_infra=False, have_esm_apps=False,
367 disabled_esm_infra_updates=0,
368- disabled_esm_apps_updates=0),
369+ disabled_esm_apps_updates=0, hide_esm_messages=False),
370 textwrap.dedent(
371 """\
372 Expanded Security Maintenance for Applications is not enabled.
373@@ -504,7 +504,7 @@ class TestMotd(unittest.TestCase):
374 esm_infra_updates=0, esm_apps_updates=0,
375 have_esm_infra=None, have_esm_apps=None,
376 disabled_esm_infra_updates=0,
377- disabled_esm_apps_updates=0),
378+ disabled_esm_apps_updates=0, hide_esm_messages=False),
379 textwrap.dedent(
380 """\
381 1 update can be applied immediately.
382@@ -521,7 +521,7 @@ class TestMotd(unittest.TestCase):
383 esm_infra_updates=0, esm_apps_updates=0,
384 have_esm_infra=None, have_esm_apps=None,
385 disabled_esm_infra_updates=0,
386- disabled_esm_apps_updates=0),
387+ disabled_esm_apps_updates=0, hide_esm_messages=False),
388 textwrap.dedent(
389 """\
390 1 update can be applied immediately.
391@@ -529,6 +529,94 @@ class TestMotd(unittest.TestCase):
392 To see these additional updates run: apt list --upgradable
393 """))
394
395+ @mock.patch("apt_check.is_lts_distro", return_value=True)
396+ @mock.patch("apt_check.is_esm_distro", return_value=False)
397+ def test_message_no_upgrades_lts_distro_with_esm_sources_hide_esm(
398+ self, _m_is_esm, _m_is_lts
399+ ):
400+ self.assertEqual(
401+ get_message(upgrades=0, security_updates=0,
402+ esm_infra_updates=0, esm_apps_updates=0,
403+ have_esm_infra=False, have_esm_apps=False,
404+ disabled_esm_infra_updates=0,
405+ disabled_esm_apps_updates=0, hide_esm_messages=True),
406+ textwrap.dedent(
407+ """\
408+ 0 updates can be applied immediately.
409+ """))
410+
411+ @mock.patch("apt_check.is_lts_distro", return_value=True)
412+ @mock.patch("apt_check.is_esm_distro", return_value=False)
413+ def test_message_for_lts_distro_not_in_esm_mode_yet_hide_esm(
414+ self, _m_is_esm, _m_is_lts
415+ ):
416+ self.assertEqual(
417+ get_message(upgrades=30, security_updates=18,
418+ esm_infra_updates=0, esm_apps_updates=0,
419+ have_esm_infra=False, have_esm_apps=False,
420+ disabled_esm_infra_updates=10,
421+ disabled_esm_apps_updates=40, hide_esm_messages=True),
422+ textwrap.dedent(
423+ """\
424+ 30 updates can be applied immediately.
425+ 18 of these updates are standard security updates.
426+ To see these additional updates run: apt list --upgradable
427+ """))
428+
429+ @mock.patch("apt_check.is_lts_distro", return_value=True)
430+ @mock.patch("apt_check.is_esm_distro", return_value=False)
431+ def test_esm_infra_disabled_wih_pkgs_and_esm_apps_on_lts_distro_hide_esm(
432+ self, _m_esm_distro, _m_is_lts
433+ ):
434+ self.assertEqual(
435+ get_message(upgrades=30, security_updates=15,
436+ esm_infra_updates=0, esm_apps_updates=1,
437+ have_esm_infra=False, have_esm_apps=True,
438+ disabled_esm_infra_updates=40,
439+ disabled_esm_apps_updates=0, hide_esm_messages=True),
440+ textwrap.dedent(
441+ """
442+ 30 updates can be applied immediately.
443+ 15 of these updates are standard security updates.
444+ To see these additional updates run: apt list --upgradable
445+ """).lstrip())
446+
447+ @mock.patch("apt_check.get_distro_version", return_value="16.04")
448+ @mock.patch("apt_check.is_lts_distro", return_value=True)
449+ @mock.patch("apt_check.is_esm_distro", return_value=True)
450+ def test_esm_infra_disabled_wih_pkgs_and_esm_apps_enabled_hide_esm(
451+ self, _m_esm_distro, _m_is_lts, _m_distro_version
452+ ):
453+ self.assertEqual(
454+ get_message(upgrades=30, security_updates=15,
455+ esm_infra_updates=0, esm_apps_updates=1,
456+ have_esm_infra=False, have_esm_apps=True,
457+ disabled_esm_infra_updates=40,
458+ disabled_esm_apps_updates=0, hide_esm_messages=True),
459+ textwrap.dedent(
460+ """
461+ 30 updates can be applied immediately.
462+ 15 of these updates are standard security updates.
463+ To see these additional updates run: apt list --upgradable
464+ """).lstrip())
465+
466+ @mock.patch("apt_check.is_lts_distro", return_value=True)
467+ @mock.patch("apt_check.is_esm_distro", return_value=True)
468+ def test_esm_infra_and_esm_apps_enabled_hide_esm(
469+ self, _m_esm_distro, _m_is_lts
470+ ):
471+ self.assertEqual(
472+ get_message(upgrades=30, security_updates=0,
473+ esm_infra_updates=15, esm_apps_updates=15,
474+ have_esm_infra=True, have_esm_apps=True,
475+ disabled_esm_infra_updates=0,
476+ disabled_esm_apps_updates=0, hide_esm_messages=True),
477+ textwrap.dedent(
478+ """
479+ 30 updates can be applied immediately.
480+ To see these additional updates run: apt list --upgradable
481+ """).lstrip())
482+
483
484 class TestGetDistro(unittest.TestCase):
485 @mock.patch("os.path.exists", return_value=True)

Subscribers

People subscribed via source and target branches