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
=== modified file 'softwarecenter/ui/gtk3/app.py'
--- softwarecenter/ui/gtk3/app.py 2012-04-13 16:51:59 +0000
+++ softwarecenter/ui/gtk3/app.py 2012-04-25 08:28:20 +0000
@@ -62,7 +62,7 @@
62 MOUSE_EVENT_BACK_BUTTON,62 MOUSE_EVENT_BACK_BUTTON,
63 SOFTWARE_CENTER_TOS_LINK,63 SOFTWARE_CENTER_TOS_LINK,
64 SOFTWARE_CENTER_NAME_KEYRING)64 SOFTWARE_CENTER_NAME_KEYRING)
65from softwarecenter.utils import (clear_token_from_ubuntu_sso,65from softwarecenter.utils import (clear_token_from_ubuntu_sso_sync,
66 get_http_proxy_string_from_gsettings,66 get_http_proxy_string_from_gsettings,
67 wait_for_apt_cache_ready,67 wait_for_apt_cache_ready,
68 ExecutionTime,68 ExecutionTime,
@@ -811,7 +811,9 @@
811 installed_purchases)811 installed_purchases)
812 if deauthorize:812 if deauthorize:
813 # clear the ubuntu SSO token for this account813 # clear the ubuntu SSO token for this account
814 clear_token_from_ubuntu_sso(SOFTWARE_CENTER_NAME_KEYRING)814 # FIXME: as this is a sync call it maybe slow so we should
815 # probably provide a async() version of this as well
816 clear_token_from_ubuntu_sso_sync(SOFTWARE_CENTER_NAME_KEYRING)
815817
816 # uninstall the list of purchased packages818 # uninstall the list of purchased packages
817 # TODO: do we need to check for dependencies and show a removal819 # TODO: do we need to check for dependencies and show a removal
818820
=== modified file 'softwarecenter/utils.py'
--- softwarecenter/utils.py 2012-04-18 08:46:49 +0000
+++ softwarecenter/utils.py 2012-04-25 08:28:20 +0000
@@ -418,22 +418,32 @@
418 return ""418 return ""
419419
420420
421def clear_token_from_ubuntu_sso(appname):421def clear_token_from_ubuntu_sso_sync(appname):
422 """ send a dbus signal to the com.ubuntu.sso service to clear422 """ send a dbus signal to the com.ubuntu.sso service to clear
423 the credentials for the given appname, e.g. _("Ubuntu Software Center")423 the credentials for the given appname, e.g. _("Ubuntu Software Center")
424 and wait for it to finish (or 2s)
424 """425 """
425 from ubuntu_sso import (426 from ubuntu_sso import (
426 DBUS_BUS_NAME,427 DBUS_BUS_NAME,
427 DBUS_CREDENTIALS_IFACE,428 DBUS_CREDENTIALS_IFACE,
428 DBUS_CREDENTIALS_PATH,429 DBUS_CREDENTIALS_PATH,
429 )430 )
431 # clean
432 loop = GObject.MainLoop()
430 bus = dbus.SessionBus()433 bus = dbus.SessionBus()
431 obj = bus.get_object(bus_name=DBUS_BUS_NAME,434 obj = bus.get_object(bus_name=DBUS_BUS_NAME,
432 object_path=DBUS_CREDENTIALS_PATH,435 object_path=DBUS_CREDENTIALS_PATH,
433 follow_name_owner_changes=True)436 follow_name_owner_changes=True)
434 proxy = dbus.Interface(object=obj,437 proxy = dbus.Interface(object=obj,
435 dbus_interface=DBUS_CREDENTIALS_IFACE)438 dbus_interface=DBUS_CREDENTIALS_IFACE)
439 proxy.connect_to_signal("CredentialsCleared", loop.quit)
440 proxy.connect_to_signal("CredentialsNotFound", loop.quit)
441 proxy.connect_to_signal("CredentialsError", loop.quit)
436 proxy.clear_credentials(appname, {})442 proxy.clear_credentials(appname, {})
443 # ensure we don't hang forever here
444 GObject.timeout_add_seconds(2, loop.quit)
445 # run the mainloop until the credentials are clear
446 loop.run()
437447
438448
439def get_nice_date_string(cur_t):449def get_nice_date_string(cur_t):
440450
=== modified file 'test/test_utils.py'
--- test/test_utils.py 2012-03-27 08:58:21 +0000
+++ test/test_utils.py 2012-04-25 08:28:20 +0000
@@ -15,6 +15,7 @@
15 release_filename_in_lists_from_deb_line,15 release_filename_in_lists_from_deb_line,
16 get_http_proxy_string_from_libproxy,16 get_http_proxy_string_from_libproxy,
17 )17 )
18from softwarecenter.testutils import do_events
1819
1920
20class TestSCUtils(unittest.TestCase):21class TestSCUtils(unittest.TestCase):
@@ -129,6 +130,11 @@
129 uuid = get_uuid()130 uuid = get_uuid()
130 self.assertTrue(uuid and len(uuid) > 0)131 self.assertTrue(uuid and len(uuid) > 0)
131132
133 def test_clear_credentials(self):
134 from softwarecenter.utils import clear_token_from_ubuntu_sso_sync
135 res = clear_token_from_ubuntu_sso_sync("fo")
136 do_events()
137
132 def test_make_string_from_list(self):138 def test_make_string_from_list(self):
133 from softwarecenter.utils import make_string_from_list139 from softwarecenter.utils import make_string_from_list
134 base = "There was a problem posting this review to %s (omg!)"140 base = "There was a problem posting this review to %s (omg!)"
135141
=== modified file 'utils/piston-helpers/piston_generic_helper.py'
--- utils/piston-helpers/piston_generic_helper.py 2012-04-11 08:40:19 +0000
+++ utils/piston-helpers/piston_generic_helper.py 2012-04-25 08:28:20 +0000
@@ -51,7 +51,7 @@
51 SOFTWARE_CENTER_SSO_DESCRIPTION,51 SOFTWARE_CENTER_SSO_DESCRIPTION,
52 )52 )
53 53
54from softwarecenter.utils import clear_token_from_ubuntu_sso54from softwarecenter.utils import clear_token_from_ubuntu_sso_sync
5555
56# the piston import56# the piston import
57from softwarecenter.backend.piston.ubuntusso_pristine import UbuntuSsoAPI57from softwarecenter.backend.piston.ubuntusso_pristine import UbuntuSsoAPI
@@ -112,7 +112,7 @@
112 return len(res) > 0112 return len(res) > 0
113113
114 def clear_token(self):114 def clear_token(self):
115 clear_token_from_ubuntu_sso(SOFTWARE_CENTER_NAME_KEYRING)115 clear_token_from_ubuntu_sso_sync(SOFTWARE_CENTER_NAME_KEYRING)
116116
117 def get_oauth_token_sync(self):117 def get_oauth_token_sync(self):
118 self.oauth = None118 self.oauth = None

Subscribers

People subscribed via source and target branches