Merge lp:~rackspace-titan/nova/lp796619 into lp:~hudson-openstack/nova/trunk

Proposed by Alex Meade
Status: Merged
Approved by: Brian Waldon
Approved revision: 1175
Merged at revision: 1177
Proposed branch: lp:~rackspace-titan/nova/lp796619
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 112 lines (+85/-1)
2 files modified
nova/crypto.py (+2/-1)
nova/tests/test_crypto.py (+83/-0)
To merge this branch: bzr merge lp:~rackspace-titan/nova/lp796619
Reviewer Review Type Date Requested Status
Brian Waldon (community) Approve
Brian Lamar (community) Approve
Devin Carlen (community) Approve
Trey Morris (community) Approve
Review via email: mp+64411@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Brian Lamar (blamar) wrote :

Pretty obvious this isn't being used anywhere. Before I approve this though, since it isn't being used...it is something that should just be removed instead of fixed?

I'm a big fan of removing code...although sometimes I get carried away.

review: Needs Information
Revision history for this message
Alex Meade (alex-meade) wrote :

ah, I just discovered that it is actually used directly through nova-manage. Sorry about that misinformation earlier, I was grepping one level too deep.

I suppose we should keep it then eh?

Revision history for this message
Trey Morris (tr3buchet) wrote :

I've grep'd inside branch/nova and been confused a few times too :D.

(trey|nova)~/nova/trunk> ack revoke_certs_by_user_and_project
bin/nova-manage
352: crypto.revoke_certs_by_user_and_project(user_id, project_id)

nova/crypto.py
176:def revoke_certs_by_user_and_project(user_id, project_id):
(trey|nova)~/nova/trunk>

If it's being used it needs to be kept unless we're writing off that functionality.

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

hooray for tests!

review: Approve
Revision history for this message
Brian Lamar (blamar) :
review: Approve
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Good work, Alex.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/crypto.py'
2--- nova/crypto.py 2011-05-11 13:28:07 +0000
3+++ nova/crypto.py 2011-06-13 19:26:07 +0000
4@@ -176,7 +176,8 @@
5 def revoke_certs_by_user_and_project(user_id, project_id):
6 """Revoke certs for user in project."""
7 admin = context.get_admin_context()
8- for cert in db.certificate_get_all_by_user(admin, user_id, project_id):
9+ for cert in db.certificate_get_all_by_user_and_project(admin,
10+ user_id, project_id):
11 revoke_cert(cert['project_id'], cert['file_name'])
12
13
14
15=== modified file 'nova/tests/test_crypto.py'
16--- nova/tests/test_crypto.py 2011-05-11 13:28:07 +0000
17+++ nova/tests/test_crypto.py 2011-06-13 19:26:07 +0000
18@@ -16,7 +16,11 @@
19 Tests for Crypto module.
20 """
21
22+import mox
23+import stubout
24+
25 from nova import crypto
26+from nova import db
27 from nova import test
28
29
30@@ -46,3 +50,82 @@
31 plain = decrypt(cipher_text)
32
33 self.assertEquals(plain_text, plain)
34+
35+
36+class RevokeCertsTest(test.TestCase):
37+
38+ def setUp(self):
39+ super(RevokeCertsTest, self).setUp()
40+ self.stubs = stubout.StubOutForTesting()
41+
42+ def tearDown(self):
43+ self.stubs.UnsetAll()
44+ super(RevokeCertsTest, self).tearDown()
45+
46+ def test_revoke_certs_by_user_and_project(self):
47+ user_id = 'test_user'
48+ project_id = 2
49+ file_name = 'test_file'
50+
51+ def mock_certificate_get_all_by_user_and_project(context,
52+ user_id,
53+ project_id):
54+
55+ return [{"user_id": user_id, "project_id": project_id,
56+ "file_name": file_name}]
57+
58+ self.stubs.Set(db, 'certificate_get_all_by_user_and_project',
59+ mock_certificate_get_all_by_user_and_project)
60+
61+ self.mox.StubOutWithMock(crypto, 'revoke_cert')
62+ crypto.revoke_cert(project_id, file_name)
63+
64+ self.mox.ReplayAll()
65+
66+ crypto.revoke_certs_by_user_and_project(user_id, project_id)
67+
68+ self.mox.VerifyAll()
69+
70+ def test_revoke_certs_by_user(self):
71+ user_id = 'test_user'
72+ project_id = 2
73+ file_name = 'test_file'
74+
75+ def mock_certificate_get_all_by_user(context, user_id):
76+
77+ return [{"user_id": user_id, "project_id": project_id,
78+ "file_name": file_name}]
79+
80+ self.stubs.Set(db, 'certificate_get_all_by_user',
81+ mock_certificate_get_all_by_user)
82+
83+ self.mox.StubOutWithMock(crypto, 'revoke_cert')
84+ crypto.revoke_cert(project_id, mox.IgnoreArg())
85+
86+ self.mox.ReplayAll()
87+
88+ crypto.revoke_certs_by_user(user_id)
89+
90+ self.mox.VerifyAll()
91+
92+ def test_revoke_certs_by_project(self):
93+ user_id = 'test_user'
94+ project_id = 2
95+ file_name = 'test_file'
96+
97+ def mock_certificate_get_all_by_project(context, project_id):
98+
99+ return [{"user_id": user_id, "project_id": project_id,
100+ "file_name": file_name}]
101+
102+ self.stubs.Set(db, 'certificate_get_all_by_project',
103+ mock_certificate_get_all_by_project)
104+
105+ self.mox.StubOutWithMock(crypto, 'revoke_cert')
106+ crypto.revoke_cert(project_id, mox.IgnoreArg())
107+
108+ self.mox.ReplayAll()
109+
110+ crypto.revoke_certs_by_project(project_id)
111+
112+ self.mox.VerifyAll()