Merge ~nteodosio/update-manager:focal-json-to-api into update-manager:ubuntu/focal

Proposed by Nathan Teodosio
Status: Merged
Merged at revision: c7c319022492201d3950059ed4eda1f968d3c67c
Proposed branch: ~nteodosio/update-manager:focal-json-to-api
Merge into: update-manager:ubuntu/focal
Diff against target: 109 lines (+41/-29)
2 files modified
UpdateManager/UpdateManager.py (+31/-29)
debian/changelog (+10/-0)
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+462928@code.launchpad.net

Description of the change

Ditch ua security-status, use Pro API.

Re-spin of https://code.launchpad.net/~nteodosio/update-manager/+git/update-manager/+merge/459153, which was actually only partially merged at the time due to SRU rejection.

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

Thanks! I'm fixing the typo in the changelog and merging

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 7c6fa3d..f677cb9 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,11 +37,11 @@ warnings.filterwarnings("ignore", "Accessed deprecated property",
14
15 import distro_info
16 import fnmatch
17-import json
18 import os
19 import subprocess
20 import sys
21 import time
22+import threading
23 from gettext import gettext as _
24
25 import dbus
26@@ -269,36 +270,37 @@ class UpdateManager(Gtk.Window):
27 and pkg.installed:
28 self.oem_metapackages.add(pkg)
29
30+ def _fetch_ua_updates(self):
31+ self.ua_updates = ua.updates().updates
32+
33 def _get_ua_security_status(self):
34 self.ua_security_packages = []
35- try:
36- p = subprocess.Popen(['pro', 'security-status', '--format=json'],
37- stdout=subprocess.PIPE)
38- except OSError:
39- pass
40- else:
41- while p.poll() is None:
42- while Gtk.events_pending():
43- Gtk.main_iteration()
44- time.sleep(0.05)
45- s = json.load(p.stdout)
46- for package in s.get('packages', []):
47- if package.get('service_name', '') == 'standard-security':
48- continue
49- status = package.get('status', '')
50- if (
51- status == 'pending_attach'
52- or status == 'pending_enable'
53- or status == 'upgrade_available'
54- ):
55- name = package.get('package', '')
56- version = package.get('version', '')
57- size = package.get('download_size', 0)
58- downloadable = status == 'upgrade_available'
59- self.ua_security_packages.append(
60- (name, version, size, downloadable)
61- )
62- self.cache.create_pro_cache(self.ua_security_packages)
63+ t = threading.Thread(target=self._fetch_ua_updates, daemon=True)
64+ t.start()
65+ while t.is_alive():
66+ while Gtk.events_pending():
67+ Gtk.main_iteration()
68+ time.sleep(0.05)
69+ for package in self.ua_updates:
70+ if (
71+ package.provided_by == 'standard-security'
72+ or package.provided_by == 'standard-updates'
73+ ):
74+ continue
75+ status = package.status
76+ if (
77+ status == 'pending_attach'
78+ or status == 'pending_enable'
79+ or status == 'upgrade_available'
80+ ):
81+ name = package.package
82+ version = package.version
83+ size = package.download_size
84+ downloadable = status == 'upgrade_available'
85+ self.ua_security_packages.append(
86+ (name, version, size, downloadable)
87+ )
88+ self.cache.create_pro_cache(self.ua_security_packages)
89
90 def _make_available_pane(self, install_count, need_reboot=False,
91 cancelled_update=False, error_occurred=False):
92diff --git a/debian/changelog b/debian/changelog
93index 70d8dde..6777871 100644
94--- a/debian/changelog
95+++ b/debian/changelog
96@@ -1,3 +1,13 @@
97+update-manager (1:20.04.11) focal; urgency=medium
98+
99+ * Replace Popen to 'ua security-status --format=json' by the Ubuntu Pro API.
100+ The former is not stable enough would break the porgram once in a while
101+ when something unrelated to Update Manager (Livepatch, for instance) went
102+ awry. The updates() end point from the API, on the other hand, does not
103+ raise exceptions. LP: #2058133.
104+
105+ -- Nathan Pratta Teodosio <nathan.teodosio@canonical.com> Fri, 22 Mar 2024 08:38:43 +0100
106+
107 update-manager (1:20.04.10.20) focal; urgency=medium
108
109 * d/control: Depend on ubuntu-advantage-tools >= 30~.

Subscribers

People subscribed via source and target branches