Merge lp:~xtoddx/nova/lp724633 into lp:~hudson-openstack/nova/trunk

Proposed by Todd Willey
Status: Merged
Approved by: Devin Carlen
Approved revision: 740
Merged at revision: 740
Proposed branch: lp:~xtoddx/nova/lp724633
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 156 lines (+34/-24)
5 files modified
nova/api/openstack/auth.py (+3/-3)
nova/db/api.py (+10/-10)
nova/db/sqlalchemy/api.py (+7/-4)
nova/tests/api/openstack/fakes.py (+12/-5)
nova/tests/api/openstack/test_auth.py (+2/-2)
To merge this branch: bzr merge lp:~xtoddx/nova/lp724633
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Vish Ishaya (community) Approve
Matt Dietz Pending
Review via email: mp+51243@code.launchpad.net

Description of the change

Cleanup db method names for dealing with auth_tokens to follow standard naming pattern.

To post a comment you must log in.
Revision history for this message
Todd Willey (xtoddx) wrote :

Changed to work-in-progress to fix the way tokens to be deleted are passed.

Revision history for this message
Vish Ishaya (vishvananda) wrote :

coolness. lgtm

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/auth.py'
2--- nova/api/openstack/auth.py 2011-02-23 19:53:02 +0000
3+++ nova/api/openstack/auth.py 2011-02-25 04:54:12 +0000
4@@ -103,11 +103,11 @@
5 2 days ago.
6 """
7 ctxt = context.get_admin_context()
8- token = self.db.auth_get_token(ctxt, token_hash)
9+ token = self.db.auth_token_get(ctxt, token_hash)
10 if token:
11 delta = datetime.datetime.now() - token.created_at
12 if delta.days >= 2:
13- self.db.auth_destroy_token(ctxt, token)
14+ self.db.auth_token_destroy(ctxt, token.id)
15 else:
16 return self.auth.get_user(token.user_id)
17 return None
18@@ -131,6 +131,6 @@
19 token_dict['server_management_url'] = req.url
20 token_dict['storage_url'] = ''
21 token_dict['user_id'] = user.id
22- token = self.db.auth_create_token(ctxt, token_dict)
23+ token = self.db.auth_token_create(ctxt, token_dict)
24 return token, user
25 return None, None
26
27=== modified file 'nova/db/api.py'
28--- nova/db/api.py 2011-02-23 20:54:46 +0000
29+++ nova/db/api.py 2011-02-25 04:54:12 +0000
30@@ -630,19 +630,19 @@
31 ###############
32
33
34-def auth_destroy_token(context, token):
35+def auth_token_destroy(context, token_id):
36 """Destroy an auth token."""
37- return IMPL.auth_destroy_token(context, token)
38-
39-
40-def auth_get_token(context, token_hash):
41+ return IMPL.auth_token_destroy(context, token_id)
42+
43+
44+def auth_token_get(context, token_hash):
45 """Retrieves a token given the hash representing it."""
46- return IMPL.auth_get_token(context, token_hash)
47-
48-
49-def auth_create_token(context, token):
50+ return IMPL.auth_token_get(context, token_hash)
51+
52+
53+def auth_token_create(context, token):
54 """Creates a new token."""
55- return IMPL.auth_create_token(context, token)
56+ return IMPL.auth_token_create(context, token)
57
58
59 ###################
60
61=== modified file 'nova/db/sqlalchemy/api.py'
62--- nova/db/sqlalchemy/api.py 2011-02-23 20:54:46 +0000
63+++ nova/db/sqlalchemy/api.py 2011-02-25 04:54:12 +0000
64@@ -1262,16 +1262,19 @@
65
66
67 @require_admin_context
68-def auth_destroy_token(_context, token):
69+def auth_token_destroy(context, token_id):
70 session = get_session()
71- session.delete(token)
72+ with session.begin():
73+ token_ref = auth_token_get(context, token_id, session=session)
74+ token_ref.delete(session=session)
75
76
77 @require_admin_context
78-def auth_get_token(_context, token_hash):
79+def auth_token_get(context, token_hash):
80 session = get_session()
81 tk = session.query(models.AuthToken).\
82 filter_by(token_hash=token_hash).\
83+ filter_by(deleted=can_read_deleted(context)).\
84 first()
85 if not tk:
86 raise exception.NotFound(_('Token %s does not exist') % token_hash)
87@@ -1279,7 +1282,7 @@
88
89
90 @require_admin_context
91-def auth_create_token(_context, token):
92+def auth_token_create(_context, token):
93 tk = models.AuthToken()
94 tk.update(token)
95 tk.save()
96
97=== modified file 'nova/tests/api/openstack/fakes.py'
98--- nova/tests/api/openstack/fakes.py 2011-02-23 19:53:02 +0000
99+++ nova/tests/api/openstack/fakes.py 2011-02-25 04:54:12 +0000
100@@ -188,7 +188,11 @@
101
102
103 class FakeToken(object):
104+ id = 0
105+
106 def __init__(self, **kwargs):
107+ FakeToken.id += 1
108+ self.id = FakeToken.id
109 for k, v in kwargs.iteritems():
110 setattr(self, k, v)
111
112@@ -203,19 +207,22 @@
113 data = {}
114
115 @staticmethod
116- def auth_get_token(context, token_hash):
117+ def auth_token_get(context, token_hash):
118 return FakeAuthDatabase.data.get(token_hash, None)
119
120 @staticmethod
121- def auth_create_token(context, token):
122+ def auth_token_create(context, token):
123 fake_token = FakeToken(created_at=datetime.datetime.now(), **token)
124 FakeAuthDatabase.data[fake_token.token_hash] = fake_token
125+ FakeAuthDatabase.data['id_%i' % fake_token.id] = fake_token
126 return fake_token
127
128 @staticmethod
129- def auth_destroy_token(context, token):
130- if token.token_hash in FakeAuthDatabase.data:
131- del FakeAuthDatabase.data['token_hash']
132+ def auth_token_destroy(context, token_id):
133+ token = FakeAuthDatabase.data.get('id_%i' % token_id)
134+ if token and token.token_hash in FakeAuthDatabase.data:
135+ del FakeAuthDatabase.data[token.token_hash]
136+ del FakeAuthDatabase.data['id_%i' % token_id]
137
138
139 class FakeAuthManager(object):
140
141=== modified file 'nova/tests/api/openstack/test_auth.py'
142--- nova/tests/api/openstack/test_auth.py 2011-02-25 01:04:25 +0000
143+++ nova/tests/api/openstack/test_auth.py 2011-02-25 04:54:12 +0000
144@@ -99,10 +99,10 @@
145 token_hash=token_hash,
146 created_at=datetime.datetime(1990, 1, 1))
147
148- self.stubs.Set(fakes.FakeAuthDatabase, 'auth_destroy_token',
149+ self.stubs.Set(fakes.FakeAuthDatabase, 'auth_token_destroy',
150 destroy_token_mock)
151
152- self.stubs.Set(fakes.FakeAuthDatabase, 'auth_get_token',
153+ self.stubs.Set(fakes.FakeAuthDatabase, 'auth_token_get',
154 bad_token)
155
156 req = webob.Request.blank('/v1.0/')