From 67e11fa809c83f25af9d09eac1bbe1c69a22a311 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 13 Jun 2011 10:10:45 -0400 Subject: fixed bug 796619 --- nova/crypto.py | 3 ++- nova/tests/test_crypto.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/crypto.py b/nova/crypto.py index bdc32482a..8d535f426 100644 --- a/nova/crypto.py +++ b/nova/crypto.py @@ -176,7 +176,8 @@ def revoke_certs_by_project(project_id): def revoke_certs_by_user_and_project(user_id, project_id): """Revoke certs for user in project.""" admin = context.get_admin_context() - for cert in db.certificate_get_all_by_user(admin, user_id, project_id): + for cert in db.certificate_get_all_by_user_and_project(admin, + user_id, project_id): revoke_cert(cert['project_id'], cert['file_name']) diff --git a/nova/tests/test_crypto.py b/nova/tests/test_crypto.py index 945d78794..1356ec8b8 100644 --- a/nova/tests/test_crypto.py +++ b/nova/tests/test_crypto.py @@ -16,7 +16,10 @@ Tests for Crypto module. """ +import mox + from nova import crypto +from nova import db from nova import test @@ -46,3 +49,69 @@ class SymmetricKeyTestCase(test.TestCase): plain = decrypt(cipher_text) self.assertEquals(plain_text, plain) + + +class RevokeCertsTest(test.TestCase): + + def test_revoke_certs_by_user_and_project(self): + user_id = 'test_user' + project_id = 2 + file_name = 'test_file' + + certificates = [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] + + self.mox.StubOutWithMock(db, 'certificate_get_all_by_user_and_project') + db.certificate_get_all_by_user_and_project(mox.IgnoreArg(), \ + user_id, project_id).AndReturn(certificates) + + self.mox.StubOutWithMock(crypto, 'revoke_cert') + crypto.revoke_cert(project_id, mox.IgnoreArg()) + + self.mox.ReplayAll() + + crypto.revoke_certs_by_user_and_project(user_id, project_id) + + self.mox.VerifyAll() + + def test_revoke_certs_by_user(self): + user_id = 'test_user' + project_id = 2 + file_name = 'test_file' + + certificates = [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] + + self.mox.StubOutWithMock(db, 'certificate_get_all_by_user') + db.certificate_get_all_by_user(mox.IgnoreArg(), \ + user_id).AndReturn(certificates) + + self.mox.StubOutWithMock(crypto, 'revoke_cert') + crypto.revoke_cert(project_id, mox.IgnoreArg()) + + self.mox.ReplayAll() + + crypto.revoke_certs_by_user(user_id) + + self.mox.VerifyAll() + + def test_revoke_certs_by_project(self): + user_id = 'test_user' + project_id = 2 + file_name = 'test_file' + + certificates = [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] + + self.mox.StubOutWithMock(db, 'certificate_get_all_by_project') + db.certificate_get_all_by_project(mox.IgnoreArg(), \ + project_id).AndReturn(certificates) + + self.mox.StubOutWithMock(crypto, 'revoke_cert') + crypto.revoke_cert(project_id, mox.IgnoreArg()) + + self.mox.ReplayAll() + + crypto.revoke_certs_by_project(project_id) + + self.mox.VerifyAll() -- cgit From bdfded59fda6716adbbcf981a45d1ed90aa23f89 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 13 Jun 2011 15:18:55 -0400 Subject: Improved tests --- nova/tests/test_crypto.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'nova') diff --git a/nova/tests/test_crypto.py b/nova/tests/test_crypto.py index 1356ec8b8..8eaef3293 100644 --- a/nova/tests/test_crypto.py +++ b/nova/tests/test_crypto.py @@ -17,6 +17,7 @@ Tests for Crypto module. """ import mox +import stubout from nova import crypto from nova import db @@ -53,20 +54,31 @@ class SymmetricKeyTestCase(test.TestCase): class RevokeCertsTest(test.TestCase): + def setUp(self): + super(RevokeCertsTest, self).setUp() + self.stubs = stubout.StubOutForTesting() + + def tearDown(self): + self.stubs.UnsetAll() + super(RevokeCertsTest, self).tearDown() + def test_revoke_certs_by_user_and_project(self): user_id = 'test_user' project_id = 2 file_name = 'test_file' - certificates = [{"user_id": user_id, "project_id": project_id, - "file_name": file_name}] + def mock_certificate_get_all_by_user_and_project(context, + user_id, + project_id): + + return [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] - self.mox.StubOutWithMock(db, 'certificate_get_all_by_user_and_project') - db.certificate_get_all_by_user_and_project(mox.IgnoreArg(), \ - user_id, project_id).AndReturn(certificates) + self.stubs.Set(db, 'certificate_get_all_by_user_and_project', + mock_certificate_get_all_by_user_and_project) self.mox.StubOutWithMock(crypto, 'revoke_cert') - crypto.revoke_cert(project_id, mox.IgnoreArg()) + crypto.revoke_cert(project_id, file_name) self.mox.ReplayAll() @@ -79,12 +91,13 @@ class RevokeCertsTest(test.TestCase): project_id = 2 file_name = 'test_file' - certificates = [{"user_id": user_id, "project_id": project_id, - "file_name": file_name}] + def mock_certificate_get_all_by_user(context, user_id): + + return [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] - self.mox.StubOutWithMock(db, 'certificate_get_all_by_user') - db.certificate_get_all_by_user(mox.IgnoreArg(), \ - user_id).AndReturn(certificates) + self.stubs.Set(db, 'certificate_get_all_by_user', + mock_certificate_get_all_by_user) self.mox.StubOutWithMock(crypto, 'revoke_cert') crypto.revoke_cert(project_id, mox.IgnoreArg()) @@ -100,12 +113,13 @@ class RevokeCertsTest(test.TestCase): project_id = 2 file_name = 'test_file' - certificates = [{"user_id": user_id, "project_id": project_id, - "file_name": file_name}] + def mock_certificate_get_all_by_project(context, project_id): + + return [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] - self.mox.StubOutWithMock(db, 'certificate_get_all_by_project') - db.certificate_get_all_by_project(mox.IgnoreArg(), \ - project_id).AndReturn(certificates) + self.stubs.Set(db, 'certificate_get_all_by_project', + mock_certificate_get_all_by_project) self.mox.StubOutWithMock(crypto, 'revoke_cert') crypto.revoke_cert(project_id, mox.IgnoreArg()) -- cgit From 431b9d52f2eb325c8be90d45d102c9e238d02325 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 13 Jun 2011 15:24:02 -0400 Subject: pep8 --- nova/tests/test_crypto.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'nova') diff --git a/nova/tests/test_crypto.py b/nova/tests/test_crypto.py index 8eaef3293..6c25b396e 100644 --- a/nova/tests/test_crypto.py +++ b/nova/tests/test_crypto.py @@ -67,15 +67,15 @@ class RevokeCertsTest(test.TestCase): project_id = 2 file_name = 'test_file' - def mock_certificate_get_all_by_user_and_project(context, + def mock_certificate_get_all_by_user_and_project(context, user_id, project_id): - return [{"user_id": user_id, "project_id": project_id, + return [{"user_id": user_id, "project_id": project_id, "file_name": file_name}] - self.stubs.Set(db, 'certificate_get_all_by_user_and_project', - mock_certificate_get_all_by_user_and_project) + self.stubs.Set(db, 'certificate_get_all_by_user_and_project', + mock_certificate_get_all_by_user_and_project) self.mox.StubOutWithMock(crypto, 'revoke_cert') crypto.revoke_cert(project_id, file_name) @@ -91,12 +91,12 @@ class RevokeCertsTest(test.TestCase): project_id = 2 file_name = 'test_file' - def mock_certificate_get_all_by_user(context, user_id): + def mock_certificate_get_all_by_user(context, user_id): - return [{"user_id": user_id, "project_id": project_id, + return [{"user_id": user_id, "project_id": project_id, "file_name": file_name}] - self.stubs.Set(db, 'certificate_get_all_by_user', + self.stubs.Set(db, 'certificate_get_all_by_user', mock_certificate_get_all_by_user) self.mox.StubOutWithMock(crypto, 'revoke_cert') @@ -115,10 +115,10 @@ class RevokeCertsTest(test.TestCase): def mock_certificate_get_all_by_project(context, project_id): - return [{"user_id": user_id, "project_id": project_id, + return [{"user_id": user_id, "project_id": project_id, "file_name": file_name}] - self.stubs.Set(db, 'certificate_get_all_by_project', + self.stubs.Set(db, 'certificate_get_all_by_project', mock_certificate_get_all_by_project) self.mox.StubOutWithMock(crypto, 'revoke_cert') -- cgit From bebeaa6b0bf69c0a4017d429e79174401df28550 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Mon, 13 Jun 2011 15:20:43 -0500 Subject: Removed clocksource=jiffies from PV_args. --- nova/tests/test_xenapi.py | 2 +- nova/virt/xenapi/vm_utils.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'nova') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 3a175b106..d1c88287a 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -331,7 +331,7 @@ class XenAPIVMTestCase(test.TestCase): def check_vm_params_for_linux(self): self.assertEquals(self.vm['platform']['nx'], 'false') - self.assertEquals(self.vm['PV_args'], 'clocksource=jiffies') + self.assertEquals(self.vm['PV_args'], '') self.assertEquals(self.vm['PV_bootloader'], 'pygrub') # check that these are not set diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index b9d4346e4..11da221f2 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -157,7 +157,6 @@ class VMHelper(HelperBase): rec['PV_ramdisk'] = ramdisk else: # 2. Use kernel within the image - rec['PV_args'] = 'clocksource=jiffies' rec['PV_bootloader'] = 'pygrub' else: # 3. Using hardware virtualization -- cgit From f3381ee03355d8800d229efb7f799df9e6c915e2 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 13 Jun 2011 21:14:26 -0400 Subject: pep8 --- nova/api/openstack/limits.py | 2 +- nova/compute/api.py | 2 +- nova/tests/scheduler/test_host_filter.py | 8 ++++---- nova/tests/scheduler/test_least_cost_scheduler.py | 8 ++++---- nova/tests/scheduler/test_zone_aware_scheduler.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/limits.py b/nova/api/openstack/limits.py index dc2bc6bbc..fede96e33 100644 --- a/nova/api/openstack/limits.py +++ b/nova/api/openstack/limits.py @@ -99,7 +99,7 @@ def create_resource(version='1.0'): serializers = { 'application/xml': wsgi.XMLDictSerializer(xmlns=xmlns, - metadata=metadata) + metadata=metadata), } return wsgi.Resource(controller, serializers=serializers) diff --git a/nova/compute/api.py b/nova/compute/api.py index b0949a729..5afc0480a 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -281,7 +281,7 @@ class API(base.Base): 'instance_type': instance_type, 'filter': filter_class, 'blob': zone_blob, - 'num_instances': num_instances + 'num_instances': num_instances, } rpc.cast(context, diff --git a/nova/tests/scheduler/test_host_filter.py b/nova/tests/scheduler/test_host_filter.py index 07817cc5a..10eafde08 100644 --- a/nova/tests/scheduler/test_host_filter.py +++ b/nova/tests/scheduler/test_host_filter.py @@ -133,11 +133,11 @@ class HostFilterTestCase(test.TestCase): raw = ['or', ['and', ['<', '$compute.host_memory_free', 30], - ['<', '$compute.disk_available', 300] + ['<', '$compute.disk_available', 300], ], ['and', ['>', '$compute.host_memory_free', 70], - ['>', '$compute.disk_available', 700] + ['>', '$compute.disk_available', 700], ] ] cooked = json.dumps(raw) @@ -183,12 +183,12 @@ class HostFilterTestCase(test.TestCase): self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps([]))) self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps({}))) self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps( - ['not', True, False, True, False] + ['not', True, False, True, False], ))) try: hf.filter_hosts(self.zone_manager, json.dumps( - 'not', True, False, True, False + 'not', True, False, True, False, )) self.fail("Should give KeyError") except KeyError, e: diff --git a/nova/tests/scheduler/test_least_cost_scheduler.py b/nova/tests/scheduler/test_least_cost_scheduler.py index 506fa62fb..9a5318aee 100644 --- a/nova/tests/scheduler/test_least_cost_scheduler.py +++ b/nova/tests/scheduler/test_least_cost_scheduler.py @@ -44,7 +44,7 @@ class WeightedSumTestCase(test.TestCase): hosts = [ FakeHost(1, 512 * MB, 100), FakeHost(2, 256 * MB, 400), - FakeHost(3, 512 * MB, 100) + FakeHost(3, 512 * MB, 100), ] weighted_fns = [ @@ -96,7 +96,7 @@ class LeastCostSchedulerTestCase(test.TestCase): def test_noop_cost_fn(self): FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.noop_cost_fn' + 'nova.scheduler.least_cost.noop_cost_fn', ] FLAGS.noop_cost_fn_weight = 1 @@ -110,7 +110,7 @@ class LeastCostSchedulerTestCase(test.TestCase): def test_cost_fn_weights(self): FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.noop_cost_fn' + 'nova.scheduler.least_cost.noop_cost_fn', ] FLAGS.noop_cost_fn_weight = 2 @@ -124,7 +124,7 @@ class LeastCostSchedulerTestCase(test.TestCase): def test_fill_first_cost_fn(self): FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.fill_first_cost_fn' + 'nova.scheduler.least_cost.fill_first_cost_fn', ] FLAGS.fill_first_cost_fn_weight = 1 diff --git a/nova/tests/scheduler/test_zone_aware_scheduler.py b/nova/tests/scheduler/test_zone_aware_scheduler.py index 9f70b9dbc..37c6488cc 100644 --- a/nova/tests/scheduler/test_zone_aware_scheduler.py +++ b/nova/tests/scheduler/test_zone_aware_scheduler.py @@ -201,7 +201,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase): 'instance_properties': {}, 'instance_type': {}, 'filter_driver': 'nova.scheduler.host_filter.AllHostsFilter', - 'blob': "Non-None blob data" + 'blob': "Non-None blob data", } result = sched.schedule_run_instance(None, 1, request_spec) -- cgit