Merge lp:~cmiller/desktopcouch/remote-oauth-for-replication into lp:desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: Stuart Langridge
Approved revision: 77
Merged at revision: not available
Proposed branch: lp:~cmiller/desktopcouch/remote-oauth-for-replication
Merge into: lp:desktopcouch
Diff against target: 120 lines
4 files modified
desktopcouch/pair/couchdb_pairing/couchdb_io.py (+7/-6)
desktopcouch/pair/couchdb_pairing/dbus_io.py (+7/-1)
desktopcouch/records/server_base.py (+0/-2)
desktopcouch/replication.py (+11/-4)
To merge this branch: bzr merge lp:~cmiller/desktopcouch/remote-oauth-for-replication
Reviewer Review Type Date Requested Status
Stuart Langridge (community) Approve
Eric Casteleijn (community) Approve
Ubuntu One hackers Pending
Review via email: mp+12672@code.launchpad.net

Commit message

    Use the oauth tokens we stored at pairing time to talk to the remote end.
    (LP: #439412)

    Retreive oauth information from pairing records and give it back in the info
    about pairings.

    Log exceptions in replication and catch them, instead of letting them percolate
    up to the caller.

To post a comment you must log in.
Revision history for this message
Stuart Langridge (sil) wrote :

I don't understand why this:

101 + try:
102 + raise last_exception
103 + except:
104 + logging.exception("failed to unpair from other end.")
105 + continue

Why raise an exception and then immediately catch it again?

review: Needs Fixing
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good, tests pass

review: Approve
77. By Chad Miller

Document ugliness that is confusing if you don't know that logging.exception
peeks at the currently handled exception and logs the stack trace at a level
of Error.

Revision history for this message
Chad Miller (cmiller) wrote :

> I don't understand why this:
>
> 101 + try:
> 102 + raise last_exception
> 103 + except:
> 104 + logging.exception("failed to unpair from other end.")
> 105 + continue
>
> Why raise an exception and then immediately catch it again?

I want to log an exception that I caught earlier, and logging.exception looks for current exception information.

Revision history for this message
Stuart Langridge (sil) wrote :

Cool, happy now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/pair/couchdb_pairing/couchdb_io.py'
2--- desktopcouch/pair/couchdb_pairing/couchdb_io.py 2009-09-28 18:58:18 +0000
3+++ desktopcouch/pair/couchdb_pairing/couchdb_io.py 2009-09-30 19:34:09 +0000
4@@ -158,6 +158,8 @@
5 v = dict()
6 v["record_id"] = row.id
7 v["active"] = True
8+ if "oauth" in row.value:
9+ v["oauth"] = row.value["oauth"]
10 if "unpaired" in row.value:
11 v["active"] = not row.value["unpaired"]
12 hostid = row.value["pairing_identifier"]
13@@ -216,15 +218,15 @@
14
15 if target_host:
16 # Target databases must exist before replicating to them.
17- logging.debug("creating %r %s:%d", target_database, target_host,
18- target_port)
19+ logging.debug("creating %r %s:%d %s", target_database, target_host,
20+ target_port, target_oauth)
21 create_database(target_host, target_port, target_database,
22 target_ssl, target_oauth)
23+ logging.debug("db exists, and we're ready to replicate")
24 except:
25- logging.exception("can't talk to couchdb. %r %s:%d oauth=%s",
26+ logging.exception("can't create/verify %r %s:%d oauth=%s",
27 target_database, target_host, target_port, target_oauth)
28
29- logging.debug("db exists, and we're ready to replicate")
30 try:
31 # regardless of source and target, we talk to our local couchdb :(
32 port = int(desktopcouch_find_port())
33@@ -239,8 +241,7 @@
34 logging.debug("replicate result: %r %r", resp, data)
35 ###
36 except:
37- logging.error("can't talk to couchdb. %r <== %r", url, record)
38- raise
39+ logging.exception("can't send %r %r <== %r", source_database, url, record)
40
41 def get_pairings(uri=None):
42 """Get a list of paired servers."""
43
44=== modified file 'desktopcouch/pair/couchdb_pairing/dbus_io.py'
45--- desktopcouch/pair/couchdb_pairing/dbus_io.py 2009-09-14 15:56:42 +0000
46+++ desktopcouch/pair/couchdb_pairing/dbus_io.py 2009-09-30 19:34:09 +0000
47@@ -141,7 +141,13 @@
48 def get_seen_paired_hosts():
49 pairing_encyclopedia = couchdb_io.get_all_known_pairings()
50 return (
51- (uuid, addr, port, pairing_encyclopedia[uuid]["active"])
52+ (
53+ uuid,
54+ addr,
55+ port,
56+ not pairing_encyclopedia[uuid]["active"],
57+ pairing_encyclopedia[uuid]["oauth"],
58+ )
59 for uuid, (addr, port)
60 in nearby_desktop_couch_instances.items()
61 if uuid in pairing_encyclopedia)
62
63=== modified file 'desktopcouch/records/server_base.py'
64--- desktopcouch/records/server_base.py 2009-09-28 15:37:18 +0000
65+++ desktopcouch/records/server_base.py 2009-09-30 19:34:09 +0000
66@@ -73,8 +73,6 @@
67 )
68 req.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(), consumer, access_token)
69 headers.update(httplib2._normalize_headers(req.to_header()))
70- for header in headers.iteritems():
71- logging.debug("header %s", header)
72
73 class OAuthCapableHttp(httplib2.Http):
74 """Subclass of httplib2.Http which specifically uses our OAuth
75
76=== modified file 'desktopcouch/replication.py'
77--- desktopcouch/replication.py 2009-09-28 16:01:11 +0000
78+++ desktopcouch/replication.py 2009-09-30 19:34:09 +0000
79@@ -83,7 +83,7 @@
80 # that we have paired with. Now, it's time to send our changes to
81 # all those.
82
83- for remote_hostid, addr, port, is_unpaired in \
84+ for remote_hostid, addr, port, is_unpaired, remote_oauth in \
85 dbus_io.get_seen_paired_hosts():
86
87 if is_unpaired:
88@@ -94,14 +94,20 @@
89 try:
90 # Tell her gently, using each pseudonym.
91 couchdb_io.expunge_pairing(local_identifier,
92- couchdb_io.mkuri(addr, port))
93+ couchdb_io.mkuri(addr, port), remote_oauth)
94 count += 1
95 except Exception, e:
96 last_exception = e
97 if count == 0:
98 if last_exception is not None:
99 # If she didn't recognize us, something's wrong.
100- raise last_exception
101+ try:
102+ raise last_exception
103+ # push caught exception back...
104+ except:
105+ # ... so that we log it here.
106+ logging.exception("failed to unpair from other end.")
107+ continue
108 else:
109 # Finally, find your inner peace...
110 couchdb_io.expunge_pairing(remote_identifier)
111@@ -116,7 +122,8 @@
112 if not is_running: return
113 couchdb_io.replicate(db_name, db_name,
114 target_host=addr, target_port=port,
115- source_port=local_port)
116+ source_port=local_port, target_oauth=remote_oauth)
117+ log.debug("replication of discovered hosts finished")
118 except Exception, e:
119 log.exception("replication of discovered hosts aborted")
120 pass

Subscribers

People subscribed via source and target branches