Merge lp:~mvo/software-center/fix-clear-credentials-race into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 2995
Proposed branch: lp:~mvo/software-center/fix-clear-credentials-race
Merge into: lp:software-center
Diff against target: 107 lines (+23/-5)
4 files modified
softwarecenter/ui/gtk3/app.py (+4/-2)
softwarecenter/utils.py (+11/-1)
test/test_utils.py (+6/-0)
utils/piston-helpers/piston_generic_helper.py (+2/-2)
To merge this branch: bzr merge lp:~mvo/software-center/fix-clear-credentials-race
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+103421@code.launchpad.net

Description of the change

This branch fixes a incorrect use of the sso dbus backend. The way it works is that we need to wait until
it emits a CredentialsCleared signal and that caused bug #986117.

The attached branch adds that wait (and a additional quit after 2s
just to ensure that it does not hang forever in case of failure of SSO). I also renamed the function to
ensure that its clear that its a sync call that may block the UI. Fortunately we only use it currently in
the backend code that is run in its own process. The app.py deauthorize code is never called but we need
to keep that in mind when that code is updated. I added a comment for this there.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

This looks just great, and with it there is no sign of the previous error traceback as described in bug 986117. Very nice!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/ui/gtk3/app.py'
2--- softwarecenter/ui/gtk3/app.py 2012-04-13 16:51:59 +0000
3+++ softwarecenter/ui/gtk3/app.py 2012-04-25 08:28:20 +0000
4@@ -62,7 +62,7 @@
5 MOUSE_EVENT_BACK_BUTTON,
6 SOFTWARE_CENTER_TOS_LINK,
7 SOFTWARE_CENTER_NAME_KEYRING)
8-from softwarecenter.utils import (clear_token_from_ubuntu_sso,
9+from softwarecenter.utils import (clear_token_from_ubuntu_sso_sync,
10 get_http_proxy_string_from_gsettings,
11 wait_for_apt_cache_ready,
12 ExecutionTime,
13@@ -811,7 +811,9 @@
14 installed_purchases)
15 if deauthorize:
16 # clear the ubuntu SSO token for this account
17- clear_token_from_ubuntu_sso(SOFTWARE_CENTER_NAME_KEYRING)
18+ # FIXME: as this is a sync call it maybe slow so we should
19+ # probably provide a async() version of this as well
20+ clear_token_from_ubuntu_sso_sync(SOFTWARE_CENTER_NAME_KEYRING)
21
22 # uninstall the list of purchased packages
23 # TODO: do we need to check for dependencies and show a removal
24
25=== modified file 'softwarecenter/utils.py'
26--- softwarecenter/utils.py 2012-04-18 08:46:49 +0000
27+++ softwarecenter/utils.py 2012-04-25 08:28:20 +0000
28@@ -418,22 +418,32 @@
29 return ""
30
31
32-def clear_token_from_ubuntu_sso(appname):
33+def clear_token_from_ubuntu_sso_sync(appname):
34 """ send a dbus signal to the com.ubuntu.sso service to clear
35 the credentials for the given appname, e.g. _("Ubuntu Software Center")
36+ and wait for it to finish (or 2s)
37 """
38 from ubuntu_sso import (
39 DBUS_BUS_NAME,
40 DBUS_CREDENTIALS_IFACE,
41 DBUS_CREDENTIALS_PATH,
42 )
43+ # clean
44+ loop = GObject.MainLoop()
45 bus = dbus.SessionBus()
46 obj = bus.get_object(bus_name=DBUS_BUS_NAME,
47 object_path=DBUS_CREDENTIALS_PATH,
48 follow_name_owner_changes=True)
49 proxy = dbus.Interface(object=obj,
50 dbus_interface=DBUS_CREDENTIALS_IFACE)
51+ proxy.connect_to_signal("CredentialsCleared", loop.quit)
52+ proxy.connect_to_signal("CredentialsNotFound", loop.quit)
53+ proxy.connect_to_signal("CredentialsError", loop.quit)
54 proxy.clear_credentials(appname, {})
55+ # ensure we don't hang forever here
56+ GObject.timeout_add_seconds(2, loop.quit)
57+ # run the mainloop until the credentials are clear
58+ loop.run()
59
60
61 def get_nice_date_string(cur_t):
62
63=== modified file 'test/test_utils.py'
64--- test/test_utils.py 2012-03-27 08:58:21 +0000
65+++ test/test_utils.py 2012-04-25 08:28:20 +0000
66@@ -15,6 +15,7 @@
67 release_filename_in_lists_from_deb_line,
68 get_http_proxy_string_from_libproxy,
69 )
70+from softwarecenter.testutils import do_events
71
72
73 class TestSCUtils(unittest.TestCase):
74@@ -129,6 +130,11 @@
75 uuid = get_uuid()
76 self.assertTrue(uuid and len(uuid) > 0)
77
78+ def test_clear_credentials(self):
79+ from softwarecenter.utils import clear_token_from_ubuntu_sso_sync
80+ res = clear_token_from_ubuntu_sso_sync("fo")
81+ do_events()
82+
83 def test_make_string_from_list(self):
84 from softwarecenter.utils import make_string_from_list
85 base = "There was a problem posting this review to %s (omg!)"
86
87=== modified file 'utils/piston-helpers/piston_generic_helper.py'
88--- utils/piston-helpers/piston_generic_helper.py 2012-04-11 08:40:19 +0000
89+++ utils/piston-helpers/piston_generic_helper.py 2012-04-25 08:28:20 +0000
90@@ -51,7 +51,7 @@
91 SOFTWARE_CENTER_SSO_DESCRIPTION,
92 )
93
94-from softwarecenter.utils import clear_token_from_ubuntu_sso
95+from softwarecenter.utils import clear_token_from_ubuntu_sso_sync
96
97 # the piston import
98 from softwarecenter.backend.piston.ubuntusso_pristine import UbuntuSsoAPI
99@@ -112,7 +112,7 @@
100 return len(res) > 0
101
102 def clear_token(self):
103- clear_token_from_ubuntu_sso(SOFTWARE_CENTER_NAME_KEYRING)
104+ clear_token_from_ubuntu_sso_sync(SOFTWARE_CENTER_NAME_KEYRING)
105
106 def get_oauth_token_sync(self):
107 self.oauth = None

Subscribers

People subscribed via source and target branches