Merge lp:~juliank/update-notifier/esm into lp:update-notifier/ubuntu

Proposed by Julian Andres Klode
Status: Merged
Merged at revision: 958
Proposed branch: lp:~juliank/update-notifier/esm
Merge into: lp:update-notifier/ubuntu
Diff against target: 339 lines (+243/-7)
4 files modified
data/apt_check.py (+97/-7)
debian/changelog (+7/-0)
debian/rules (+2/-0)
tests/test_motd.py (+137/-0)
To merge this branch: bzr merge lp:~juliank/update-notifier/esm
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+365288@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

Nothing critical but a few comments appear in-line.

Revision history for this message
Joshua Powers (powersj) wrote :

one in-line

Revision history for this message
Patricia Gaughen (gaughen) :
lp:~juliank/update-notifier/esm updated
960. By Julian Andres Klode

apt-check: Count enabled ESM upgrades

Revision history for this message
Brian Murray (brian-murray) wrote :

A few more comments, thanks for addressing the other ones.

Revision history for this message
Julian Andres Klode (juliank) :
lp:~juliank/update-notifier/esm updated
961. By Julian Andres Klode

apt-check: Tell people to enable ESM if ESM updates are available

962. By Julian Andres Klode

Add changelog entry and test case

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/apt_check.py'
--- data/apt_check.py 2018-11-13 20:53:28 +0000
+++ data/apt_check.py 2019-04-02 13:17:38 +0000
@@ -45,6 +45,7 @@
45def isSecurityUpgrade(ver):45def isSecurityUpgrade(ver):
46 " check if the given version is a security update (or masks one) "46 " check if the given version is a security update (or masks one) "
47 security_pockets = [("Ubuntu", "%s-security" % DISTRO),47 security_pockets = [("Ubuntu", "%s-security" % DISTRO),
48 ("UbuntuESM", "%s-security" % DISTRO),
48 ("gNewSense", "%s-security" % DISTRO),49 ("gNewSense", "%s-security" % DISTRO),
49 ("Debian", "%s-updates" % DISTRO)]50 ("Debian", "%s-updates" % DISTRO)]
50 for (file, index) in ver.file_list:51 for (file, index) in ver.file_list:
@@ -54,6 +55,14 @@
54 return False55 return False
5556
5657
58def isESMUpgrade(ver):
59 " check if the given version is a security update (or masks one) "
60 for (file, index) in ver.file_list:
61 if file.origin == "UbuntuESM" and file.archive.startswith(DISTRO):
62 return True
63 return False
64
65
57def write_package_names(outstream, cache, depcache):66def write_package_names(outstream, cache, depcache):
58 " write out package names that change to outstream "67 " write out package names that change to outstream "
59 pkgs = [pkg for pkg in cache.packages if depcache.marked_install(pkg)68 pkgs = [pkg for pkg in cache.packages if depcache.marked_install(pkg)
@@ -61,19 +70,77 @@
61 outstream.write("\n".join([p.name for p in pkgs]))70 outstream.write("\n".join([p.name for p in pkgs]))
6271
6372
64def write_human_readable_summary(outstream, upgrades, security_updates):73def write_human_readable_summary(outstream, upgrades, security_updates,
74 esm_updates, have_esm, disabled_esm_updates):
65 " write out human summary summary to outstream "75 " write out human summary summary to outstream "
76 if have_esm is not None:
77 if have_esm:
78 outstream.write(gettext.dgettext("update-notifier",
79 "Extended Security Maintenance "
80 "(ESM) is enabled."))
81 else:
82 outstream.write(gettext.dgettext("update-notifier",
83 "Extended Security Maintenance "
84 "(ESM) is not enabled."))
85 outstream.write("\n\n")
86
66 outstream.write(gettext.dngettext("update-notifier",87 outstream.write(gettext.dngettext("update-notifier",
67 "%i package can be updated.",88 "%i update can be installed "
68 "%i packages can be updated.",89 "immediately.",
90 "%i updates can be installed "
91 "immediately.",
69 upgrades) % upgrades)92 upgrades) % upgrades)
70 outstream.write("\n")93 outstream.write("\n")
94 if esm_updates > 0:
95 outstream.write(gettext.dngettext("update-notifier",
96 "%i of these updates is "
97 "provided through ESM.",
98 "%i of these updates are "
99 "provided through ESM.",
100 esm_updates) %
101 esm_updates)
102 outstream.write("\n")
71 outstream.write(gettext.dngettext("update-notifier",103 outstream.write(gettext.dngettext("update-notifier",
72 "%i update is a security update.",104 "%i of these updates is a "
73 "%i updates are security updates.",105 "security update.",
74 security_updates) % security_updates)106 "%i of these updates are "
107 "security updates.",
108 security_updates) %
109 security_updates)
75 outstream.write("\n")110 outstream.write("\n")
76111
112 if disabled_esm_updates > 0:
113 outstream.write("\n")
114 outstream.write(gettext.dngettext("update-notifier",
115 "Enable ESM to receive %i additional "
116 "security update.",
117 "Enable ESM to receive %i additional "
118 "security updates.",
119 disabled_esm_updates) %
120 disabled_esm_updates)
121 outstream.write("\n")
122 outstream.write(gettext.dgettext("update-notifier",
123 "See 'ua enable esm' or "
124 "https://ubuntu.com/esm"))
125 outstream.write("\n")
126
127
128def has_disabled_esm_security_update(depcache, pkg):
129 " check if we have a disabled ESM security update "
130 inst_ver = pkg.current_ver
131 if not inst_ver:
132 return False
133
134 for ver in pkg.version_list:
135 if ver == inst_ver:
136 break
137
138 for (file, index) in ver.file_list:
139 if (file.origin == "UbuntuESM" and file.archive.startswith(DISTRO)
140 and depcache.policy.get_priority(file) == -32768):
141 return True
142 return False
143
77144
78def init():145def init():
79 " init the system, be nice "146 " init the system, be nice "
@@ -115,13 +182,30 @@
115 sys.stderr.write("E: " + _("Error: Marking the upgrade (%s)") % e)182 sys.stderr.write("E: " + _("Error: Marking the upgrade (%s)") % e)
116 sys.exit(-1)183 sys.exit(-1)
117184
185 # Check if we have ESM enabled or disabled; and if it exists in the
186 # first place.
187 have_esm = None # None == does not exist
188 for file in cache.file_list:
189 if file.origin == "UbuntuESM" and file.archive.startswith(DISTRO):
190 # In case of multiple ESM repos, one enabled is sufficient.
191 if have_esm is None and depcache.policy.get_priority(file) == -32768:
192 have_esm = False
193 else:
194 have_esm = True
195 break
196
118 # analyze the ugprade197 # analyze the ugprade
119 upgrades = 0198 upgrades = 0
120 security_updates = 0199 security_updates = 0
200 esm_updates = 0
201 disabled_esm_updates = 0
121202
122 # we need another cache that has more pkg details203 # we need another cache that has more pkg details
123 with apt.Cache() as aptcache:204 with apt.Cache() as aptcache:
124 for pkg in cache.packages:205 for pkg in cache.packages:
206 if has_disabled_esm_security_update(depcache, pkg):
207 disabled_esm_updates += 1
208
125 # skip packages that are not marked upgraded/installed209 # skip packages that are not marked upgraded/installed
126 if not (depcache.marked_install(pkg)210 if not (depcache.marked_install(pkg)
127 or depcache.marked_upgrade(pkg)):211 or depcache.marked_upgrade(pkg)):
@@ -134,6 +218,8 @@
134 continue218 continue
135 # check for security upgrades219 # check for security upgrades
136 if isSecurityUpgrade(cand_ver):220 if isSecurityUpgrade(cand_ver):
221 if isESMUpgrade(cand_ver):
222 esm_updates += 1
137 upgrades += 1223 upgrades += 1
138 security_updates += 1224 security_updates += 1
139 continue225 continue
@@ -159,6 +245,8 @@
159 and apt_pkg.version_compare(ver.ver_str,245 and apt_pkg.version_compare(ver.ver_str,
160 inst_ver.ver_str) <= 0):246 inst_ver.ver_str) <= 0):
161 continue247 continue
248 if isESMUpgrade(ver):
249 esm_updates += 1
162 if isSecurityUpgrade(ver):250 if isSecurityUpgrade(ver):
163 security_updates += 1251 security_updates += 1
164 break252 break
@@ -167,7 +255,9 @@
167 if options and options.show_package_names:255 if options and options.show_package_names:
168 write_package_names(sys.stderr, cache, depcache)256 write_package_names(sys.stderr, cache, depcache)
169 elif options and options.readable_output:257 elif options and options.readable_output:
170 write_human_readable_summary(sys.stdout, upgrades, security_updates)258 write_human_readable_summary(sys.stdout, upgrades, security_updates,
259 esm_updates, have_esm,
260 disabled_esm_updates)
171 else:261 else:
172 # print the number of regular upgrades and the number of262 # print the number of regular upgrades and the number of
173 # security upgrades263 # security upgrades
174264
=== modified file 'debian/changelog'
--- debian/changelog 2019-03-19 10:27:07 +0000
+++ debian/changelog 2019-04-02 13:17:38 +0000
@@ -1,3 +1,10 @@
1update-notifier (3.192.16) UNRELEASED; urgency=medium
2
3 * Rewrite and extend motd messaging (LP: #1822340)
4 * Count ESM security updates as security updates
5
6 -- Julian Andres Klode <juliank@ubuntu.com> Fri, 29 Mar 2019 16:26:45 +0100
7
1update-notifier (3.192.15) disco; urgency=medium8update-notifier (3.192.15) disco; urgency=medium
29
3 * debian/control:10 * debian/control:
411
=== modified file 'debian/rules'
--- debian/rules 2018-05-09 10:59:08 +0000
+++ debian/rules 2019-04-02 13:17:38 +0000
@@ -13,3 +13,5 @@
1313
14override_dh_auto_test:14override_dh_auto_test:
15 cd tests && python3 test_package-data-downloader.py15 cd tests && python3 test_package-data-downloader.py
16 cd tests && python3 test_motd.py
17
1618
=== added symlink 'tests/apt_check.py'
=== target is u'../data/apt_check.py'
=== added file 'tests/test_motd.py'
--- tests/test_motd.py 1970-01-01 00:00:00 +0000
+++ tests/test_motd.py 2019-04-02 13:17:38 +0000
@@ -0,0 +1,137 @@
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 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 ESM to receive 23 additional security updates.
34 See 'ua enable esm' or https://ubuntu.com/esm
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 Extended Security Maintenance (ESM) is not enabled.
45
46 15 updates can be installed immediately.
47 7 of these updates are security updates.
48
49 Enable ESM to receive 23 additional security updates.
50 See 'ua enable esm' or https://ubuntu.com/esm
51 """).lstrip())
52
53 def test_esm_disabled_security_no_esm_avail(self):
54 self.assertEqual(
55 get_message(upgrades=15, security_updates=7,
56 esm_updates=0, have_esm=False,
57 disabled_esm_updates=0),
58 textwrap.dedent(
59 """
60 Extended Security Maintenance (ESM) is not enabled.
61
62 15 updates can be installed immediately.
63 7 of these updates are security updates.
64 """).lstrip())
65
66 def test_esm_disabled_nosecurity(self):
67 self.assertEqual(
68 get_message(upgrades=15, security_updates=0,
69 esm_updates=0, have_esm=False,
70 disabled_esm_updates=0),
71 textwrap.dedent(
72 """
73 Extended Security Maintenance (ESM) is not enabled.
74
75 15 updates can be installed immediately.
76 0 of these updates are security updates.
77 """).lstrip())
78
79 def test_esm_disabled_noupdates(self):
80 self.assertEqual(
81 get_message(upgrades=0, security_updates=0,
82 esm_updates=0, have_esm=False,
83 disabled_esm_updates=0),
84 textwrap.dedent(
85 """
86 Extended Security Maintenance (ESM) is not enabled.
87
88 0 updates can be installed immediately.
89 0 of these updates are security updates.
90 """).lstrip())
91
92 def test_esm_enabled_nosecurity(self):
93 self.assertEqual(
94 get_message(upgrades=35, security_updates=0,
95 esm_updates=13, have_esm=True,
96 disabled_esm_updates=0),
97 textwrap.dedent(
98 """
99 Extended Security Maintenance (ESM) is enabled.
100
101 35 updates can be installed immediately.
102 13 of these updates are provided through ESM.
103 0 of these updates are security updates.
104 """).lstrip())
105
106 def test_esm_enabled_somesecurity(self):
107 self.assertEqual(
108 get_message(upgrades=47, security_updates=7,
109 esm_updates=13, have_esm=True,
110 disabled_esm_updates=0),
111 textwrap.dedent(
112 """
113 Extended Security Maintenance (ESM) is enabled.
114
115 47 updates can be installed immediately.
116 13 of these updates are provided through ESM.
117 7 of these updates are security updates.
118 """).lstrip())
119
120 def test_esm_enabled_noupdates(self):
121 self.assertEqual(
122 get_message(upgrades=0, security_updates=0,
123 esm_updates=0, have_esm=True,
124 disabled_esm_updates=0),
125 textwrap.dedent(
126 """
127 Extended Security Maintenance (ESM) is enabled.
128
129 0 updates can be installed immediately.
130 0 of these updates are security updates.
131 """).lstrip())
132
133
134if __name__ == "__main__":
135 import logging
136 logging.basicConfig(level=logging.DEBUG)
137 unittest.main()

Subscribers

People subscribed via source and target branches

to all changes: