Merge ~chad.smith/ubuntu/+source/update-notifier:ua-motd-bionic into ubuntu/+source/update-notifier:ubuntu/bionic-proposed

Proposed by Chad Smith
Status: Merged
Merge reported by: Chad Smith
Merged at revision: 5e8cdcf82b639c45b9faed6b52af7ecd188087c4
Proposed branch: ~chad.smith/ubuntu/+source/update-notifier:ua-motd-bionic
Merge into: ubuntu/+source/update-notifier:ubuntu/bionic-proposed
Diff against target: 414 lines (+296/-10)
4 files modified
data/apt_check.py (+116/-5)
debian/changelog (+20/-0)
tests/test_motd.py (+151/-0)
tests/test_pep8.py (+9/-5)
Reviewer Review Type Date Requested Status
Brian Murray (community) Approve
Review via email: mp+391843@code.launchpad.net

Description of the change

Cherry picks of upstream commits to support motd information about ESM Apps and ESM Infra for ubuntu-advantage-tools motd package counts and availability.

Not certain which branch should best be targeted for this merge and from whom to request review.

The following is a list of cherrypicks performed and merged:

cherry-pick/backport upstream/master 770c27fb
cherry-pick upstream/master 7a0458f62

cherry-pick/backport upstream/master 4fdf27ab
cherry-pick 4b2fb30fddf93f14c8e4d505a6ce785ad9a06703
cherry-pick e39789ac632585bb11dc6f1e4fad60ec8361725b

cherry-pick ubuntu/devel commit c065e9ebd957ead33c7afc4d570b0ee0433f7601

This constitutes the following debian/changelog entry:

  [ Julian Andres Klode ]
  * Handle missing cases of LP: #1822340, where we told people ESM is not
    enabled, but not how to enable it.
  * Fix multiple disabled ESM repositories being counted as enabled ones.

  [ Brian Murray ]
  * data/apt_check.py: modify wording and output regarding ESM support.
    (LP: #1842508)

  [ Andreas Hasenack ]
  * data/apt_check.py: Update ESM security pockets names (LP: #1881632)
    - the UbuntuESM pocket was renamed from <distro>-security to
      <distro>-infra-security
    - new origin UbuntuESMApps, with a corresponding pocket of
      <distro>-apps-security

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

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 100faac..6bb716f 100755
3--- a/data/apt_check.py
4+++ b/data/apt_check.py
5@@ -16,6 +16,8 @@ DISTRO = subprocess.check_output(
6 ["lsb_release", "-c", "-s"],
7 universal_newlines=True).strip()
8
9+ESM_ORIGINS = ("UbuntuESM", "UbuntuESMApps")
10+
11
12 def _(msg):
13 return gettext.dgettext("update-notifier", msg)
14@@ -45,6 +47,8 @@ def saveDistUpgrade(cache, depcache):
15 def isSecurityUpgrade(ver):
16 " check if the given version is a security update (or masks one) "
17 security_pockets = [("Ubuntu", "%s-security" % DISTRO),
18+ ("UbuntuESM", "%s-infra-security" % DISTRO),
19+ ("UbuntuESMApps", "%s-apps-security" % DISTRO),
20 ("gNewSense", "%s-security" % DISTRO),
21 ("Debian", "%s-updates" % DISTRO)]
22 for (file, index) in ver.file_list:
23@@ -54,6 +58,14 @@ def isSecurityUpgrade(ver):
24 return False
25
26
27+def isESMUpgrade(ver):
28+ " check if the given version is a security update (or masks one) "
29+ for (file, index) in ver.file_list:
30+ if file.origin in ESM_ORIGINS and file.archive.startswith(DISTRO):
31+ return True
32+ return False
33+
34+
35 def write_package_names(outstream, cache, depcache):
36 " write out package names that change to outstream "
37 pkgs = [pkg for pkg in cache.packages if depcache.marked_install(pkg) or
38@@ -61,20 +73,92 @@ def write_package_names(outstream, cache, depcache):
39 outstream.write("\n".join([p.name for p in pkgs]))
40
41
42-def write_human_readable_summary(outstream, upgrades, security_updates):
43+def write_human_readable_summary(outstream, upgrades, security_updates,
44+ esm_updates, have_esm, disabled_esm_updates):
45 " write out human summary summary to outstream "
46+ if have_esm is not None:
47+ if have_esm:
48+ outstream.write(gettext.dgettext("update-notifier",
49+ "UA Infrastructure Extended "
50+ "Security Maintenance (ESM) is "
51+ "enabled."))
52+ else:
53+ outstream.write(gettext.dgettext("update-notifier",
54+ "UA Infrastructure Extended "
55+ "Security Maintenance (ESM) is "
56+ "not enabled."))
57+ outstream.write("\n\n")
58+
59 outstream.write(gettext.dngettext("update-notifier",
60 "%i package can be updated.",
61 "%i packages can be updated.",
62 upgrades) % upgrades)
63 outstream.write("\n")
64+ if esm_updates > 0:
65+ outstream.write(gettext.dngettext("update-notifier",
66+ "%i of these updates is provided "
67+ "through UA Infrastructure ESM.",
68+ "%i of these updates are "
69+ "provided through UA "
70+ "Infrastructure ESM.",
71+ esm_updates) %
72+ esm_updates)
73+ outstream.write("\n")
74 outstream.write(gettext.dngettext("update-notifier",
75- "%i update is a security update.",
76- "%i updates are security updates.",
77- security_updates) % security_updates)
78+ "%i of these updates is a "
79+ "security update.",
80+ "%i of these updates are "
81+ "security updates.",
82+ security_updates) %
83+ security_updates)
84+ if upgrades > 0 or security_updates > 0 or esm_updates > 0:
85+ outstream.write("\n")
86+ outstream.write(gettext.dgettext("update-notifier",
87+ "To see these additional updates "
88+ "run: apt list --upgradable"))
89+ if have_esm is not None and not have_esm:
90+ outstream.write("\n")
91+ if disabled_esm_updates > 0:
92+ outstream.write("\n")
93+ outstream.write(gettext.dngettext("update-notifier",
94+ "Enable UA Infrastructure ESM "
95+ "to receive %i additional "
96+ "security update.",
97+ "Enable UA Infrastructure ESM "
98+ "to receive %i additional "
99+ "security updates.",
100+ disabled_esm_updates) %
101+ disabled_esm_updates)
102+ else:
103+ outstream.write("\n")
104+ outstream.write(gettext.dgettext("update-notifier",
105+ "Enable UA Infrastructure ESM to "
106+ "receive additional future "
107+ "security updates."))
108+ outstream.write("\n")
109+ outstream.write(gettext.dgettext("update-notifier",
110+ "See https://ubuntu.com/esm "
111+ "or run: sudo ua status"))
112 outstream.write("\n")
113
114
115+def has_disabled_esm_security_update(depcache, pkg):
116+ " check if we have a disabled ESM security update "
117+ inst_ver = pkg.current_ver
118+ if not inst_ver:
119+ return False
120+
121+ for ver in pkg.version_list:
122+ if ver == inst_ver:
123+ break
124+
125+ for (file, index) in ver.file_list:
126+ if (file.origin in ESM_ORIGINS and file.archive.startswith(DISTRO)
127+ and depcache.policy.get_priority(file) == -32768):
128+ return True
129+ return False
130+
131+
132 def init():
133 " init the system, be nice "
134 # FIXME: do a ionice here too?
135@@ -115,13 +199,34 @@ def run(options=None):
136 sys.stderr.write("E: " + _("Error: Marking the upgrade (%s)") % e)
137 sys.exit(-1)
138
139+ # Check if we have ESM enabled or disabled; and if it exists in the
140+ # first place.
141+ have_esm = None # None == does not exist
142+ for file in cache.file_list:
143+ if file.origin in ESM_ORIGINS and file.archive.startswith(DISTRO):
144+ # In case of multiple ESM repos, one enabled is sufficient.
145+ if depcache.policy.get_priority(file) == -32768:
146+ # We found a disabled ESM repository, but we'll only count
147+ # ESM as disabled here if we have not found any other ESM
148+ # repo, so one ESM repo being enabled means ESM is enabled.
149+ if have_esm is None:
150+ have_esm = False
151+ else:
152+ have_esm = True
153+ break
154+
155 # analyze the ugprade
156 upgrades = 0
157 security_updates = 0
158+ esm_updates = 0
159+ disabled_esm_updates = 0
160
161 # we need another cache that has more pkg details
162 with apt.Cache() as aptcache:
163 for pkg in cache.packages:
164+ if has_disabled_esm_security_update(depcache, pkg):
165+ disabled_esm_updates += 1
166+
167 # skip packages that are not marked upgraded/installed
168 if not (depcache.marked_install(pkg) or
169 depcache.marked_upgrade(pkg)):
170@@ -134,6 +239,8 @@ def run(options=None):
171 continue
172 # check for security upgrades
173 if isSecurityUpgrade(cand_ver):
174+ if isESMUpgrade(cand_ver):
175+ esm_updates += 1
176 upgrades += 1
177 security_updates += 1
178 continue
179@@ -160,6 +267,8 @@ def run(options=None):
180 0):
181 # print("skipping '%s' " % ver.VerStr)
182 continue
183+ if isESMUpgrade(ver):
184+ esm_updates += 1
185 if isSecurityUpgrade(ver):
186 security_updates += 1
187 break
188@@ -168,7 +277,9 @@ def run(options=None):
189 if options and options.show_package_names:
190 write_package_names(sys.stderr, cache, depcache)
191 elif options and options.readable_output:
192- write_human_readable_summary(sys.stdout, upgrades, security_updates)
193+ write_human_readable_summary(sys.stdout, upgrades, security_updates,
194+ esm_updates, have_esm,
195+ disabled_esm_updates)
196 else:
197 # print the number of regular upgrades and the number of
198 # security upgrades
199diff --git a/debian/changelog b/debian/changelog
200index ce2d89e..b688483 100644
201--- a/debian/changelog
202+++ b/debian/changelog
203@@ -1,3 +1,23 @@
204+update-notifier (3.192.1.8) bionic; urgency=medium
205+
206+ [ Andreas Hasenack ]
207+ * data/apt_check.py: Update ESM security pockets names (LP: #1881632)
208+ - the UbuntuESM pocket was renamed from <distro>-security to
209+ <distro>-infra-security
210+ - new origin UbuntuESMApps, with a corresponding pocket of
211+ <distro>-apps-security
212+
213+ [ Brian Murray ]
214+ * data/apt_check.py: modify wording and output regarding ESM support.
215+ (LP: #1842508)
216+
217+ [ Julian Andres Klode ]
218+ * Handle missing cases of LP: #1822340, where we told people ESM is not
219+ enabled, but not how to enable it.
220+ * Fix multiple disabled ESM repositories being counted as enabled ones.
221+
222+ -- Chad Smith <chad.smith@canonical.com> Tue, 29 Sep 2020 16:49:23 -0600
223+
224 update-notifier (3.192.1.7) bionic; urgency=medium
225
226 * Backport some fixes for the previous changes, from Andrea Azzarone
227diff --git a/tests/test_motd.py b/tests/test_motd.py
228new file mode 100755
229index 0000000..2523958
230--- /dev/null
231+++ b/tests/test_motd.py
232@@ -0,0 +1,151 @@
233+#!/usr/bin/python3
234+# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
235+
236+import apt_check
237+import io
238+import os
239+import subprocess
240+import unittest
241+import textwrap
242+
243+
244+def get_message(*args, **kwds):
245+ with io.StringIO() as stream:
246+ apt_check.write_human_readable_summary(stream, *args, **kwds)
247+ return stream.getvalue()
248+
249+
250+class TestMotd(unittest.TestCase):
251+ """ ensure that the tree is pep8 clean """
252+
253+ def test_esm_disabled_upto_date_esm_avail(self):
254+ self.assertEqual(
255+ get_message(upgrades=0, security_updates=0,
256+ esm_updates=0, have_esm=False,
257+ disabled_esm_updates=23),
258+ textwrap.dedent(
259+ """
260+ UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
261+
262+ 0 updates can be installed immediately.
263+ 0 of these updates are security updates.
264+
265+ Enable UA Infrastructure ESM to receive 23 additional security updates.
266+ See https://ubuntu.com/esm or run: sudo ua status
267+ """).lstrip())
268+
269+ def test_esm_disabled_security_esm_avail(self):
270+ self.assertEqual(
271+ get_message(upgrades=15, security_updates=7,
272+ esm_updates=0, have_esm=False,
273+ disabled_esm_updates=23),
274+ textwrap.dedent(
275+ """
276+ UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
277+
278+ 15 updates can be installed immediately.
279+ 7 of these updates are security updates.
280+ To see these additional updates run: apt list --upgradable
281+
282+ Enable UA Infrastructure ESM to receive 23 additional security updates.
283+ See https://ubuntu.com/esm or run: sudo ua status
284+ """).lstrip())
285+
286+ def test_esm_disabled_security_no_esm_avail(self):
287+ self.assertEqual(
288+ get_message(upgrades=15, security_updates=7,
289+ esm_updates=0, have_esm=False,
290+ disabled_esm_updates=0),
291+ textwrap.dedent(
292+ """
293+ UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
294+
295+ 15 updates can be installed immediately.
296+ 7 of these updates are security updates.
297+ To see these additional updates run: apt list --upgradable
298+
299+ Enable UA Infrastructure ESM to receive additional future security updates.
300+ See https://ubuntu.com/esm or run: sudo ua status
301+ """).lstrip())
302+
303+ def test_esm_disabled_nosecurity(self):
304+ self.assertEqual(
305+ get_message(upgrades=15, security_updates=0,
306+ esm_updates=0, have_esm=False,
307+ disabled_esm_updates=0),
308+ textwrap.dedent(
309+ """
310+ UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
311+
312+ 15 updates can be installed immediately.
313+ 0 of these updates are security updates.
314+ To see these additional updates run: apt list --upgradable
315+
316+ Enable UA Infrastructure ESM to receive additional future security updates.
317+ See https://ubuntu.com/esm or run: sudo ua status
318+ """).lstrip())
319+
320+ def test_esm_disabled_noupdates(self):
321+ self.assertEqual(
322+ get_message(upgrades=0, security_updates=0,
323+ esm_updates=0, have_esm=False,
324+ disabled_esm_updates=0),
325+ textwrap.dedent(
326+ """
327+ UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
328+
329+ 0 updates can be installed immediately.
330+ 0 of these updates are security updates.
331+
332+ Enable UA Infrastructure ESM to receive additional future security updates.
333+ See https://ubuntu.com/esm or run: sudo ua status
334+ """).lstrip())
335+
336+ def test_esm_enabled_nosecurity(self):
337+ self.assertEqual(
338+ get_message(upgrades=35, security_updates=0,
339+ esm_updates=13, have_esm=True,
340+ disabled_esm_updates=0),
341+ textwrap.dedent(
342+ """
343+ UA Infrastructure Extended Security Maintenance (ESM) is enabled.
344+
345+ 35 updates can be installed immediately.
346+ 13 of these updates are provided through UA Infrastructure ESM.
347+ 0 of these updates are security updates.
348+ To see these additional updates run: apt list --upgradable
349+ """).lstrip())
350+
351+ def test_esm_enabled_somesecurity(self):
352+ self.assertEqual(
353+ get_message(upgrades=47, security_updates=7,
354+ esm_updates=13, have_esm=True,
355+ disabled_esm_updates=0),
356+ textwrap.dedent(
357+ """
358+ UA Infrastructure Extended Security Maintenance (ESM) is enabled.
359+
360+ 47 updates can be installed immediately.
361+ 13 of these updates are provided through UA Infrastructure ESM.
362+ 7 of these updates are security updates.
363+ To see these additional updates run: apt list --upgradable
364+ """).lstrip())
365+
366+ def test_esm_enabled_noupdates(self):
367+ self.assertEqual(
368+ get_message(upgrades=0, security_updates=0,
369+ esm_updates=0, have_esm=True,
370+ disabled_esm_updates=0),
371+ textwrap.dedent(
372+ """
373+ UA Infrastructure Extended Security Maintenance (ESM) is enabled.
374+
375+ 0 updates can be installed immediately.
376+ 0 of these updates are security updates.
377+ """).lstrip())
378+
379+
380+if __name__ == "__main__":
381+ import logging
382+ logging.basicConfig(level=logging.DEBUG)
383+ unittest.main()
384diff --git a/tests/test_pep8.py b/tests/test_pep8.py
385index a85bf7e..fa6c416 100644
386--- a/tests/test_pep8.py
387+++ b/tests/test_pep8.py
388@@ -16,17 +16,21 @@ class TestPep8Clean(unittest.TestCase):
389
390 def test_pep8_clean(self):
391 CURDIR = os.path.dirname(os.path.abspath(__file__))
392- py_files = set()
393 for dirpath, dirs, files in os.walk(os.path.join(CURDIR, "..")):
394 for f in files:
395 if os.path.splitext(f)[1] != ".py":
396 continue
397 if f in IGNORE_FILES:
398 continue
399- py_files.add(os.path.join(dirpath, f))
400- ret_code = subprocess.call(
401- ["pep8", "--ignore={0}".format(IGNORE_PEP8)] + list(py_files))
402- self.assertEqual(0, ret_code)
403+ py_file = os.path.join(dirpath, f)
404+ if f == 'test_motd.py':
405+ ret_code = subprocess.call(
406+ ["pep8", "--ignore={0}".format(IGNORE_PEP8 + ", E501"),
407+ py_file])
408+ else:
409+ ret_code = subprocess.call(
410+ ["pep8", "--ignore={0}".format(IGNORE_PEP8), py_file])
411+ self.assertEqual(0, ret_code)
412
413
414 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches