From daddc54befea4414776368b0ae8f689872b21e27 Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Fri, 1 Feb 2013 16:15:00 -0800 Subject: Access DB as dict not as attributes part 5 Partially implements bp db-api-cleanup Change-Id: Id34c20701ae0cae503c2218c9a6008d5e0bb0e76 --- nova/network/manager.py | 6 +++--- nova/tests/api/ec2/test_cloud.py | 10 +++++----- nova/tests/test_db_api.py | 14 +++++++------- nova/tests/test_libvirt.py | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/nova/network/manager.py b/nova/network/manager.py index b88fe78fc..be63da8fc 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -1125,10 +1125,10 @@ class NetworkManager(manager.SchedulerDependentManager): elif fixed_range: network = self.db.network_get_by_cidr(elevated, fixed_range) - if require_disassociated and network.project_id is not None: + if require_disassociated and network['project_id'] is not None: raise ValueError(_('Network must be disassociated from project %s' - ' before delete') % network.project_id) - self.db.network_delete_safe(context, network.id) + ' before delete') % network['project_id']) + self.db.network_delete_safe(context, network['id']) @property def _bottom_reserved_ips(self): # pylint: disable=R0201 diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index c60a0148e..a220cae6d 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -712,10 +712,10 @@ class CloudTestCase(test.TestCase): # Aggregate based zones agg = db.aggregate_create(self.context, {'name': 'agg1'}, {'availability_zone': 'zone1'}) - db.aggregate_host_add(self.context, agg.id, 'host1_zones') + db.aggregate_host_add(self.context, agg['id'], 'host1_zones') agg = db.aggregate_create(self.context, {'name': 'agg2'}, {'availability_zone': 'zone2'}) - db.aggregate_host_add(self.context, agg.id, 'host2_zones') + db.aggregate_host_add(self.context, agg['id'], 'host2_zones') result = self.cloud.describe_availability_zones(self.context) self.assertEqual(len(result['availabilityZoneInfo']), 3) admin_ctxt = context.get_admin_context(read_deleted="no") @@ -737,7 +737,7 @@ class CloudTestCase(test.TestCase): 'report_count': 0}) agg = db.aggregate_create(self.context, {'name': 'agg1'}, {'availability_zone': 'second_zone'}) - db.aggregate_host_add(self.context, agg.id, 'host2_zones') + db.aggregate_host_add(self.context, agg['id'], 'host2_zones') admin_ctxt = context.get_admin_context(read_deleted="no") result = self.cloud.describe_availability_zones(admin_ctxt, @@ -771,13 +771,13 @@ class CloudTestCase(test.TestCase): 'topic': "compute"}) agg = db.aggregate_create(self.context, {'name': 'agg1'}, {'availability_zone': 'zone1'}) - db.aggregate_host_add(self.context, agg.id, 'host1') + db.aggregate_host_add(self.context, agg['id'], 'host1') comp2 = db.service_create(self.context, {'host': 'host2', 'topic': "compute"}) agg2 = db.aggregate_create(self.context, {'name': 'agg2'}, {'availability_zone': 'zone2'}) - db.aggregate_host_add(self.context, agg2.id, 'host2') + db.aggregate_host_add(self.context, agg2['id'], 'host2') result = self.cloud.describe_instances(self.context) result = result['reservationSet'][0] diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 5581e81ac..c6bf2941e 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -1238,7 +1238,7 @@ class AggregateDBApiTestCase(test.TestCase): ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt, metadata={'availability_zone': 'fake_avail_zone'}) - self.assertEqual(result.availability_zone, 'fake_avail_zone') + self.assertEqual(result['availability_zone'], 'fake_avail_zone') new_values = _get_fake_aggr_values() new_values['availability_zone'] = 'different_avail_zone' updated = db.aggregate_update(ctxt, 1, new_values) @@ -1256,8 +1256,8 @@ class AggregateDBApiTestCase(test.TestCase): updated = db.aggregate_get(ctxt, result['id']) self.assertThat(values['metadata'], matchers.DictMatches(expected)) - self.assertNotEqual(result.availability_zone, - updated.availability_zone) + self.assertNotEqual(result['availability_zone'], + updated['availability_zone']) def test_aggregate_update_with_existing_metadata(self): ctxt = context.get_admin_context() @@ -1335,10 +1335,10 @@ class AggregateDBApiTestCase(test.TestCase): ctxt = context.get_admin_context() result = _create_aggregate(context=ctxt, metadata={'availability_zone': 'fake_avail_zone'}) - db.aggregate_metadata_delete(ctxt, result.id, 'availability_zone') - expected = db.aggregate_metadata_get(ctxt, result.id) - aggregate = db.aggregate_get(ctxt, result.id) - self.assertEquals(aggregate.availability_zone, None) + db.aggregate_metadata_delete(ctxt, result['id'], 'availability_zone') + expected = db.aggregate_metadata_get(ctxt, result['id']) + aggregate = db.aggregate_get(ctxt, result['id']) + self.assertEquals(aggregate['availability_zone'], None) self.assertThat({}, matchers.DictMatches(expected)) def test_aggregate_metadata_delete_raise_not_found(self): diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 52e308b85..cef9252c5 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -2330,7 +2330,7 @@ class LibvirtConnTestCase(test.TestCase): migrate_data) self.assertEqual(ret, None) self.assertTrue(os.path.exists('%s/%s/' % - (tmpdir, inst_ref.name))) + (tmpdir, inst_ref['name']))) db.instance_destroy(self.context, inst_ref['uuid']) def test_pre_block_migration_works_correctly(self): -- cgit