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
diff --git a/data/apt_check.py b/data/apt_check.py
index 100faac..6bb716f 100755
--- a/data/apt_check.py
+++ b/data/apt_check.py
@@ -16,6 +16,8 @@ DISTRO = subprocess.check_output(
16 ["lsb_release", "-c", "-s"],16 ["lsb_release", "-c", "-s"],
17 universal_newlines=True).strip()17 universal_newlines=True).strip()
1818
19ESM_ORIGINS = ("UbuntuESM", "UbuntuESMApps")
20
1921
20def _(msg):22def _(msg):
21 return gettext.dgettext("update-notifier", msg)23 return gettext.dgettext("update-notifier", msg)
@@ -45,6 +47,8 @@ def saveDistUpgrade(cache, depcache):
45def isSecurityUpgrade(ver):47def isSecurityUpgrade(ver):
46 " check if the given version is a security update (or masks one) "48 " check if the given version is a security update (or masks one) "
47 security_pockets = [("Ubuntu", "%s-security" % DISTRO),49 security_pockets = [("Ubuntu", "%s-security" % DISTRO),
50 ("UbuntuESM", "%s-infra-security" % DISTRO),
51 ("UbuntuESMApps", "%s-apps-security" % DISTRO),
48 ("gNewSense", "%s-security" % DISTRO),52 ("gNewSense", "%s-security" % DISTRO),
49 ("Debian", "%s-updates" % DISTRO)]53 ("Debian", "%s-updates" % DISTRO)]
50 for (file, index) in ver.file_list:54 for (file, index) in ver.file_list:
@@ -54,6 +58,14 @@ def isSecurityUpgrade(ver):
54 return False58 return False
5559
5660
61def isESMUpgrade(ver):
62 " check if the given version is a security update (or masks one) "
63 for (file, index) in ver.file_list:
64 if file.origin in ESM_ORIGINS and file.archive.startswith(DISTRO):
65 return True
66 return False
67
68
57def write_package_names(outstream, cache, depcache):69def write_package_names(outstream, cache, depcache):
58 " write out package names that change to outstream "70 " write out package names that change to outstream "
59 pkgs = [pkg for pkg in cache.packages if depcache.marked_install(pkg) or71 pkgs = [pkg for pkg in cache.packages if depcache.marked_install(pkg) or
@@ -61,20 +73,92 @@ def write_package_names(outstream, cache, depcache):
61 outstream.write("\n".join([p.name for p in pkgs]))73 outstream.write("\n".join([p.name for p in pkgs]))
6274
6375
64def write_human_readable_summary(outstream, upgrades, security_updates):76def write_human_readable_summary(outstream, upgrades, security_updates,
77 esm_updates, have_esm, disabled_esm_updates):
65 " write out human summary summary to outstream "78 " write out human summary summary to outstream "
79 if have_esm is not None:
80 if have_esm:
81 outstream.write(gettext.dgettext("update-notifier",
82 "UA Infrastructure Extended "
83 "Security Maintenance (ESM) is "
84 "enabled."))
85 else:
86 outstream.write(gettext.dgettext("update-notifier",
87 "UA Infrastructure Extended "
88 "Security Maintenance (ESM) is "
89 "not enabled."))
90 outstream.write("\n\n")
91
66 outstream.write(gettext.dngettext("update-notifier",92 outstream.write(gettext.dngettext("update-notifier",
67 "%i package can be updated.",93 "%i package can be updated.",
68 "%i packages can be updated.",94 "%i packages can be updated.",
69 upgrades) % upgrades)95 upgrades) % upgrades)
70 outstream.write("\n")96 outstream.write("\n")
97 if esm_updates > 0:
98 outstream.write(gettext.dngettext("update-notifier",
99 "%i of these updates is provided "
100 "through UA Infrastructure ESM.",
101 "%i of these updates are "
102 "provided through UA "
103 "Infrastructure ESM.",
104 esm_updates) %
105 esm_updates)
106 outstream.write("\n")
71 outstream.write(gettext.dngettext("update-notifier",107 outstream.write(gettext.dngettext("update-notifier",
72 "%i update is a security update.",108 "%i of these updates is a "
73 "%i updates are security updates.",109 "security update.",
74 security_updates) % security_updates)110 "%i of these updates are "
111 "security updates.",
112 security_updates) %
113 security_updates)
114 if upgrades > 0 or security_updates > 0 or esm_updates > 0:
115 outstream.write("\n")
116 outstream.write(gettext.dgettext("update-notifier",
117 "To see these additional updates "
118 "run: apt list --upgradable"))
119 if have_esm is not None and not have_esm:
120 outstream.write("\n")
121 if disabled_esm_updates > 0:
122 outstream.write("\n")
123 outstream.write(gettext.dngettext("update-notifier",
124 "Enable UA Infrastructure ESM "
125 "to receive %i additional "
126 "security update.",
127 "Enable UA Infrastructure ESM "
128 "to receive %i additional "
129 "security updates.",
130 disabled_esm_updates) %
131 disabled_esm_updates)
132 else:
133 outstream.write("\n")
134 outstream.write(gettext.dgettext("update-notifier",
135 "Enable UA Infrastructure ESM to "
136 "receive additional future "
137 "security updates."))
138 outstream.write("\n")
139 outstream.write(gettext.dgettext("update-notifier",
140 "See https://ubuntu.com/esm "
141 "or run: sudo ua status"))
75 outstream.write("\n")142 outstream.write("\n")
76143
77144
145def has_disabled_esm_security_update(depcache, pkg):
146 " check if we have a disabled ESM security update "
147 inst_ver = pkg.current_ver
148 if not inst_ver:
149 return False
150
151 for ver in pkg.version_list:
152 if ver == inst_ver:
153 break
154
155 for (file, index) in ver.file_list:
156 if (file.origin in ESM_ORIGINS and file.archive.startswith(DISTRO)
157 and depcache.policy.get_priority(file) == -32768):
158 return True
159 return False
160
161
78def init():162def init():
79 " init the system, be nice "163 " init the system, be nice "
80 # FIXME: do a ionice here too?164 # FIXME: do a ionice here too?
@@ -115,13 +199,34 @@ def run(options=None):
115 sys.stderr.write("E: " + _("Error: Marking the upgrade (%s)") % e)199 sys.stderr.write("E: " + _("Error: Marking the upgrade (%s)") % e)
116 sys.exit(-1)200 sys.exit(-1)
117201
202 # Check if we have ESM enabled or disabled; and if it exists in the
203 # first place.
204 have_esm = None # None == does not exist
205 for file in cache.file_list:
206 if file.origin in ESM_ORIGINS and file.archive.startswith(DISTRO):
207 # In case of multiple ESM repos, one enabled is sufficient.
208 if depcache.policy.get_priority(file) == -32768:
209 # We found a disabled ESM repository, but we'll only count
210 # ESM as disabled here if we have not found any other ESM
211 # repo, so one ESM repo being enabled means ESM is enabled.
212 if have_esm is None:
213 have_esm = False
214 else:
215 have_esm = True
216 break
217
118 # analyze the ugprade218 # analyze the ugprade
119 upgrades = 0219 upgrades = 0
120 security_updates = 0220 security_updates = 0
221 esm_updates = 0
222 disabled_esm_updates = 0
121223
122 # we need another cache that has more pkg details224 # we need another cache that has more pkg details
123 with apt.Cache() as aptcache:225 with apt.Cache() as aptcache:
124 for pkg in cache.packages:226 for pkg in cache.packages:
227 if has_disabled_esm_security_update(depcache, pkg):
228 disabled_esm_updates += 1
229
125 # skip packages that are not marked upgraded/installed230 # skip packages that are not marked upgraded/installed
126 if not (depcache.marked_install(pkg) or231 if not (depcache.marked_install(pkg) or
127 depcache.marked_upgrade(pkg)):232 depcache.marked_upgrade(pkg)):
@@ -134,6 +239,8 @@ def run(options=None):
134 continue239 continue
135 # check for security upgrades240 # check for security upgrades
136 if isSecurityUpgrade(cand_ver):241 if isSecurityUpgrade(cand_ver):
242 if isESMUpgrade(cand_ver):
243 esm_updates += 1
137 upgrades += 1244 upgrades += 1
138 security_updates += 1245 security_updates += 1
139 continue246 continue
@@ -160,6 +267,8 @@ def run(options=None):
160 0):267 0):
161 # print("skipping '%s' " % ver.VerStr)268 # print("skipping '%s' " % ver.VerStr)
162 continue269 continue
270 if isESMUpgrade(ver):
271 esm_updates += 1
163 if isSecurityUpgrade(ver):272 if isSecurityUpgrade(ver):
164 security_updates += 1273 security_updates += 1
165 break274 break
@@ -168,7 +277,9 @@ def run(options=None):
168 if options and options.show_package_names:277 if options and options.show_package_names:
169 write_package_names(sys.stderr, cache, depcache)278 write_package_names(sys.stderr, cache, depcache)
170 elif options and options.readable_output:279 elif options and options.readable_output:
171 write_human_readable_summary(sys.stdout, upgrades, security_updates)280 write_human_readable_summary(sys.stdout, upgrades, security_updates,
281 esm_updates, have_esm,
282 disabled_esm_updates)
172 else:283 else:
173 # print the number of regular upgrades and the number of284 # print the number of regular upgrades and the number of
174 # security upgrades285 # security upgrades
diff --git a/debian/changelog b/debian/changelog
index ce2d89e..b688483 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,23 @@
1update-notifier (3.192.1.8) bionic; urgency=medium
2
3 [ Andreas Hasenack ]
4 * data/apt_check.py: Update ESM security pockets names (LP: #1881632)
5 - the UbuntuESM pocket was renamed from <distro>-security to
6 <distro>-infra-security
7 - new origin UbuntuESMApps, with a corresponding pocket of
8 <distro>-apps-security
9
10 [ Brian Murray ]
11 * data/apt_check.py: modify wording and output regarding ESM support.
12 (LP: #1842508)
13
14 [ Julian Andres Klode ]
15 * Handle missing cases of LP: #1822340, where we told people ESM is not
16 enabled, but not how to enable it.
17 * Fix multiple disabled ESM repositories being counted as enabled ones.
18
19 -- Chad Smith <chad.smith@canonical.com> Tue, 29 Sep 2020 16:49:23 -0600
20
1update-notifier (3.192.1.7) bionic; urgency=medium21update-notifier (3.192.1.7) bionic; urgency=medium
222
3 * Backport some fixes for the previous changes, from Andrea Azzarone23 * Backport some fixes for the previous changes, from Andrea Azzarone
diff --git a/tests/test_motd.py b/tests/test_motd.py
4new file mode 10075524new file mode 100755
index 0000000..2523958
--- /dev/null
+++ b/tests/test_motd.py
@@ -0,0 +1,151 @@
1#!/usr/bin/python3
2# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
3
4import apt_check
5import io
6import os
7import subprocess
8import unittest
9import textwrap
10
11
12def get_message(*args, **kwds):
13 with io.StringIO() as stream:
14 apt_check.write_human_readable_summary(stream, *args, **kwds)
15 return stream.getvalue()
16
17
18class TestMotd(unittest.TestCase):
19 """ ensure that the tree is pep8 clean """
20
21 def test_esm_disabled_upto_date_esm_avail(self):
22 self.assertEqual(
23 get_message(upgrades=0, security_updates=0,
24 esm_updates=0, have_esm=False,
25 disabled_esm_updates=23),
26 textwrap.dedent(
27 """
28 UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
29
30 0 updates can be installed immediately.
31 0 of these updates are security updates.
32
33 Enable UA Infrastructure ESM to receive 23 additional security updates.
34 See https://ubuntu.com/esm or run: sudo ua status
35 """).lstrip())
36
37 def test_esm_disabled_security_esm_avail(self):
38 self.assertEqual(
39 get_message(upgrades=15, security_updates=7,
40 esm_updates=0, have_esm=False,
41 disabled_esm_updates=23),
42 textwrap.dedent(
43 """
44 UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
45
46 15 updates can be installed immediately.
47 7 of these updates are security updates.
48 To see these additional updates run: apt list --upgradable
49
50 Enable UA Infrastructure ESM to receive 23 additional security updates.
51 See https://ubuntu.com/esm or run: sudo ua status
52 """).lstrip())
53
54 def test_esm_disabled_security_no_esm_avail(self):
55 self.assertEqual(
56 get_message(upgrades=15, security_updates=7,
57 esm_updates=0, have_esm=False,
58 disabled_esm_updates=0),
59 textwrap.dedent(
60 """
61 UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
62
63 15 updates can be installed immediately.
64 7 of these updates are security updates.
65 To see these additional updates run: apt list --upgradable
66
67 Enable UA Infrastructure ESM to receive additional future security updates.
68 See https://ubuntu.com/esm or run: sudo ua status
69 """).lstrip())
70
71 def test_esm_disabled_nosecurity(self):
72 self.assertEqual(
73 get_message(upgrades=15, security_updates=0,
74 esm_updates=0, have_esm=False,
75 disabled_esm_updates=0),
76 textwrap.dedent(
77 """
78 UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
79
80 15 updates can be installed immediately.
81 0 of these updates are security updates.
82 To see these additional updates run: apt list --upgradable
83
84 Enable UA Infrastructure ESM to receive additional future security updates.
85 See https://ubuntu.com/esm or run: sudo ua status
86 """).lstrip())
87
88 def test_esm_disabled_noupdates(self):
89 self.assertEqual(
90 get_message(upgrades=0, security_updates=0,
91 esm_updates=0, have_esm=False,
92 disabled_esm_updates=0),
93 textwrap.dedent(
94 """
95 UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
96
97 0 updates can be installed immediately.
98 0 of these updates are security updates.
99
100 Enable UA Infrastructure ESM to receive additional future security updates.
101 See https://ubuntu.com/esm or run: sudo ua status
102 """).lstrip())
103
104 def test_esm_enabled_nosecurity(self):
105 self.assertEqual(
106 get_message(upgrades=35, security_updates=0,
107 esm_updates=13, have_esm=True,
108 disabled_esm_updates=0),
109 textwrap.dedent(
110 """
111 UA Infrastructure Extended Security Maintenance (ESM) is enabled.
112
113 35 updates can be installed immediately.
114 13 of these updates are provided through UA Infrastructure ESM.
115 0 of these updates are security updates.
116 To see these additional updates run: apt list --upgradable
117 """).lstrip())
118
119 def test_esm_enabled_somesecurity(self):
120 self.assertEqual(
121 get_message(upgrades=47, security_updates=7,
122 esm_updates=13, have_esm=True,
123 disabled_esm_updates=0),
124 textwrap.dedent(
125 """
126 UA Infrastructure Extended Security Maintenance (ESM) is enabled.
127
128 47 updates can be installed immediately.
129 13 of these updates are provided through UA Infrastructure ESM.
130 7 of these updates are security updates.
131 To see these additional updates run: apt list --upgradable
132 """).lstrip())
133
134 def test_esm_enabled_noupdates(self):
135 self.assertEqual(
136 get_message(upgrades=0, security_updates=0,
137 esm_updates=0, have_esm=True,
138 disabled_esm_updates=0),
139 textwrap.dedent(
140 """
141 UA Infrastructure Extended Security Maintenance (ESM) is enabled.
142
143 0 updates can be installed immediately.
144 0 of these updates are security updates.
145 """).lstrip())
146
147
148if __name__ == "__main__":
149 import logging
150 logging.basicConfig(level=logging.DEBUG)
151 unittest.main()
diff --git a/tests/test_pep8.py b/tests/test_pep8.py
index a85bf7e..fa6c416 100644
--- a/tests/test_pep8.py
+++ b/tests/test_pep8.py
@@ -16,17 +16,21 @@ class TestPep8Clean(unittest.TestCase):
1616
17 def test_pep8_clean(self):17 def test_pep8_clean(self):
18 CURDIR = os.path.dirname(os.path.abspath(__file__))18 CURDIR = os.path.dirname(os.path.abspath(__file__))
19 py_files = set()
20 for dirpath, dirs, files in os.walk(os.path.join(CURDIR, "..")):19 for dirpath, dirs, files in os.walk(os.path.join(CURDIR, "..")):
21 for f in files:20 for f in files:
22 if os.path.splitext(f)[1] != ".py":21 if os.path.splitext(f)[1] != ".py":
23 continue22 continue
24 if f in IGNORE_FILES:23 if f in IGNORE_FILES:
25 continue24 continue
26 py_files.add(os.path.join(dirpath, f))25 py_file = os.path.join(dirpath, f)
27 ret_code = subprocess.call(26 if f == 'test_motd.py':
28 ["pep8", "--ignore={0}".format(IGNORE_PEP8)] + list(py_files))27 ret_code = subprocess.call(
29 self.assertEqual(0, ret_code)28 ["pep8", "--ignore={0}".format(IGNORE_PEP8 + ", E501"),
29 py_file])
30 else:
31 ret_code = subprocess.call(
32 ["pep8", "--ignore={0}".format(IGNORE_PEP8), py_file])
33 self.assertEqual(0, ret_code)
3034
3135
32if __name__ == "__main__":36if __name__ == "__main__":

Subscribers

People subscribed via source and target branches