Merge ~nteodosio/update-manager:bionic-ua into update-manager:ubuntu/bionic

Proposed by Nathan Teodosio
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 8dc69262b8bd510378499a476e72e175a3026576
Merged at revision: 8dc69262b8bd510378499a476e72e175a3026576
Proposed branch: ~nteodosio/update-manager:bionic-ua
Merge into: update-manager:ubuntu/bionic
Diff against target: 121 lines (+42/-30)
3 files modified
UpdateManager/UpdateManager.py (+31/-29)
debian/changelog (+10/-0)
debian/control (+1/-1)
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+459157@code.launchpad.net

Description of the change

Fix the crash caused by incomplete response of the 'ua security-status' when ubuntu-advantage-tools (UAT) is an older version.

As the documentation[1] states, this call returns no exceptions, so in my opinion it is simpler to switch to it than patching our old call to security-status.

However, this crash would also occur by using the version 27 of the API, so the effective fix here is to force ubuntu-advantage-tools >= 30.

Note that we already use the API in Noble[2].

[1] https://canonical-ubuntu-pro-client.readthedocs-hosted.com/en/latest/references/api/#u-pro-packages-updates-v1
[2] https://code.launchpad.net/~nteodosio/update-manager/+git/update-manager/+merge/456088

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/UpdateManager/UpdateManager.py b/UpdateManager/UpdateManager.py
2index 3430c5c..6cb2ead 100644
3--- a/UpdateManager/UpdateManager.py
4+++ b/UpdateManager/UpdateManager.py
5@@ -27,6 +27,7 @@ from gi.repository import Gdk, GdkX11
6 from gi.repository import Gio
7 from gi.repository import GLib
8 from gi.repository import GObject
9+import uaclient.api.u.pro.packages.updates.v1 as ua
10
11 GdkX11 # pyflakes
12
13@@ -36,10 +37,10 @@ warnings.filterwarnings("ignore", "Accessed deprecated property",
14
15 import apt_pkg
16 import distro_info
17-import json
18 import os
19 import subprocess
20 import sys
21+import threading
22 import time
23 from gettext import gettext as _
24
25@@ -249,36 +250,37 @@ class UpdateManager(Gtk.Window):
26 cancelled_update, error_occurred)
27 self._start_pane(pane)
28
29+ def _fetch_ua_updates(self):
30+ self.ua_updates = ua.updates().updates
31+
32 def _get_ua_security_status(self):
33 self.ua_security_packages = []
34- try:
35- p = subprocess.Popen(['pro', 'security-status', '--format=json'],
36- stdout=subprocess.PIPE)
37- except OSError:
38- pass
39- else:
40- while p.poll() is None:
41- while Gtk.events_pending():
42- Gtk.main_iteration()
43- time.sleep(0.05)
44- s = json.load(p.stdout)
45- for package in s.get('packages', []):
46- if package.get('service_name', '') == 'standard-security':
47- continue
48- status = package.get('status', '')
49- if (
50- status == 'pending_attach'
51- or status == 'pending_enable'
52- or status == 'upgrade_available'
53- ):
54- name = package.get('package', '')
55- version = package.get('version', '')
56- size = package.get('download_size', 0)
57- downloadable = status == 'upgrade_available'
58- self.ua_security_packages.append(
59- (name, version, size, downloadable)
60- )
61- self.cache.create_pro_cache(self.ua_security_packages)
62+ t = threading.Thread(target=self._fetch_ua_updates, daemon=True)
63+ t.start()
64+ while t.is_alive():
65+ while Gtk.events_pending():
66+ Gtk.main_iteration()
67+ time.sleep(0.05)
68+ for package in self.ua_updates:
69+ if (
70+ package.provided_by == 'standard-security'
71+ or package.provided_by == 'standard-updates'
72+ ):
73+ continue
74+ status = package.status
75+ if (
76+ status == 'pending_attach'
77+ or status == 'pending_enable'
78+ or status == 'upgrade_available'
79+ ):
80+ name = package.package
81+ version = package.version
82+ size = package.download_size
83+ downloadable = status == 'upgrade_available'
84+ self.ua_security_packages.append(
85+ (name, version, size, downloadable)
86+ )
87+ self.cache.create_pro_cache(self.ua_security_packages)
88
89 def _make_available_pane(self, install_count, need_reboot=False,
90 cancelled_update=False, error_occurred=False):
91diff --git a/debian/changelog b/debian/changelog
92index 9e83e4e..c53d2bd 100644
93--- a/debian/changelog
94+++ b/debian/changelog
95@@ -1,3 +1,13 @@
96+update-manager (1:18.04.11.23) UNRELEASED; urgency=medium
97+
98+ * Drop call to ua security-status --format=json.
99+ Use uaclient.api.u.pro.packages.updates.v1.updates instead.
100+ * d/control: Depend on ubuntu-advantage-tools >= 30~.
101+ Fixes edge case whereby the program crashes upon an incomplete
102+ response from ua security-status (LP: #2049785).
103+
104+ -- Nathan Pratta Teodosio <nathan.teodosio@canonical.com> Fri, 19 Jan 2024 12:58:34 +0100
105+
106 update-manager (1:18.04.11.22) bionic; urgency=medium
107
108 * Add back removed widgets to UI file to fix crash when updating
109diff --git a/debian/control b/debian/control
110index ad91c50..4fc5710 100644
111--- a/debian/control
112+++ b/debian/control
113@@ -30,7 +30,7 @@ Depends: ${python3:Depends},
114 python3-yaml,
115 distro-info-data,
116 lsb-release,
117- ubuntu-advantage-tools,
118+ ubuntu-advantage-tools (>= 30~),
119 ubuntu-release-upgrader-core (>= 1:18.04.9)
120 Recommends: libpam-modules (>= 1.0.1-9ubuntu3)
121 Replaces: update-manager (<< 1:0.146.2)

Subscribers

People subscribed via source and target branches