Merge lp:~jtran/nova/lp824008 into lp:~hudson-openstack/nova/trunk

Proposed by John Tran
Status: Merged
Approved by: Rick Harris
Approved revision: 1438
Merged at revision: 1457
Proposed branch: lp:~jtran/nova/lp824008
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 60 lines (+30/-1)
3 files modified
nova/db/sqlalchemy/api.py (+2/-1)
nova/tests/test_cloud.py (+11/-0)
nova/tests/test_db_api.py (+17/-0)
To merge this branch: bzr merge lp:~jtran/nova/lp824008
Reviewer Review Type Date Requested Status
Rick Harris (community) Approve
Devin Carlen (community) Approve
Review via email: mp+71610@code.launchpad.net

Commit message

Fixed bug in which DescribeInstances was returning deleted instances. Added tests for pertinent api methods.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Revision history for this message
William Wolf (throughnothing) wrote :

I think for all of the tests you added, should we have args1 and args2, with distinct values, and actually check that the filtered results are giving us the correct instance? This just seems more explicit of a test to me, rather than just checking that the length is 1 instead of 2...is it the right 1?

lp:~jtran/nova/lp824008 updated
1438. By John Tran

test improvements per peer review

Revision history for this message
John Tran (jtran) wrote :

> I think for all of the tests you added, should we have args1 and args2, with
> distinct values, and actually check that the filtered results are giving us
> the correct instance? This just seems more explicit of a test to me, rather
> than just checking that the length is 1 instead of 2...is it the right 1?

Thanks for the feedback. I've implemented fixes as suggested.

Revision history for this message
Rick Harris (rconradharris) 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/db/sqlalchemy/api.py'
2--- nova/db/sqlalchemy/api.py 2011-08-15 20:31:43 +0000
3+++ nova/db/sqlalchemy/api.py 2011-08-16 16:19:48 +0000
4@@ -1209,7 +1209,8 @@
5 options(joinedload('security_groups')).\
6 options(joinedload_all('fixed_ips.network')).\
7 options(joinedload('metadata')).\
8- options(joinedload('instance_type'))
9+ options(joinedload('instance_type')).\
10+ filter_by(deleted=can_read_deleted(context))
11
12 # Make a copy of the filters dictionary to use going forward, as we'll
13 # be modifying it and we shouldn't affect the caller's use of it.
14
15=== modified file 'nova/tests/test_cloud.py'
16--- nova/tests/test_cloud.py 2011-08-05 05:06:22 +0000
17+++ nova/tests/test_cloud.py 2011-08-16 16:19:48 +0000
18@@ -487,6 +487,17 @@
19 db.service_destroy(self.context, comp1['id'])
20 db.service_destroy(self.context, comp2['id'])
21
22+ def test_describe_instances_deleted(self):
23+ args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
24+ inst1 = db.instance_create(self.context, args1)
25+ args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
26+ inst2 = db.instance_create(self.context, args2)
27+ db.instance_destroy(self.context, inst1.id)
28+ result = self.cloud.describe_instances(self.context)
29+ result = result['reservationSet'][0]['instancesSet']
30+ self.assertEqual(result[0]['instanceId'],
31+ ec2utils.id_to_ec2_id(inst2.id))
32+
33 def _block_device_mapping_create(self, instance_id, mappings):
34 volumes = []
35 for bdm in mappings:
36
37=== modified file 'nova/tests/test_db_api.py'
38--- nova/tests/test_db_api.py 2011-08-12 19:00:48 +0000
39+++ nova/tests/test_db_api.py 2011-08-16 16:19:48 +0000
40@@ -76,3 +76,20 @@
41 self.assertEqual(instance['id'], result['id'])
42 self.assertEqual(result['fixed_ips'][0]['floating_ips'][0].address,
43 '1.2.1.2')
44+
45+ def test_instance_get_all_by_filters(self):
46+ args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
47+ inst1 = db.instance_create(self.context, args)
48+ inst2 = db.instance_create(self.context, args)
49+ result = db.instance_get_all_by_filters(self.context, {})
50+ self.assertTrue(2, len(result))
51+
52+ def test_instance_get_all_by_filters_deleted(self):
53+ args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
54+ inst1 = db.instance_create(self.context, args1)
55+ args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
56+ inst2 = db.instance_create(self.context, args2)
57+ db.instance_destroy(self.context, inst1.id)
58+ result = db.instance_get_all_by_filters(self.context.elevated(), {})
59+ self.assertEqual(1, len(result))
60+ self.assertEqual(result[0].id, inst2.id)