Merge lp:~tpatil/nova/bug838466 into lp:~hudson-openstack/nova/trunk

Proposed by Tushar Patil
Status: Merged
Approved by: Christopher MacGown
Approved revision: 1518
Merged at revision: 1526
Proposed branch: lp:~tpatil/nova/bug838466
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 48 lines (+17/-4)
2 files modified
nova/compute/api.py (+4/-4)
nova/tests/test_compute.py (+13/-0)
To merge this branch: bzr merge lp:~tpatil/nova/bug838466
Reviewer Review Type Date Requested Status
Christopher MacGown (community) Approve
Vish Ishaya (community) Approve
Review via email: mp+73615@code.launchpad.net

Commit message

Instance record is not inserted in db if the security group passed to the RunInstances API doesn't exists.

To post a comment you must log in.
Revision history for this message
Vish Ishaya (vishvananda) wrote :

lgtm

review: Approve
Revision history for this message
Christopher MacGown (0x44) wrote :

Hi Tushar,

I've created a failing test for the previous revision that passes with your code @ lp:~0x44/nova/bug838466 , please merge or write your own. Otherwise, lgtm.

review: Needs Fixing
Revision history for this message
Tushar Patil (tpatil) wrote :

I should have written this unit test at the first place. Anyway thank you very much for your help.

Merged your unit test, Please review again.

Revision history for this message
Christopher MacGown (0x44) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/compute/api.py'
2--- nova/compute/api.py 2011-08-31 23:07:29 +0000
3+++ nova/compute/api.py 2011-09-03 00:13:26 +0000
4@@ -383,10 +383,6 @@
5 If you are changing this method, be sure to update both
6 call paths.
7 """
8- instance = dict(launch_index=num, **base_options)
9- instance = self.db.instance_create(context, instance)
10- instance_id = instance['id']
11-
12 elevated = context.elevated()
13 if security_group is None:
14 security_group = ['default']
15@@ -400,6 +396,10 @@
16 security_group_name)
17 security_groups.append(group['id'])
18
19+ instance = dict(launch_index=num, **base_options)
20+ instance = self.db.instance_create(context, instance)
21+ instance_id = instance['id']
22+
23 for security_group_id in security_groups:
24 self.db.instance_add_security_group(elevated,
25 instance_id,
26
27=== modified file 'nova/tests/test_compute.py'
28--- nova/tests/test_compute.py 2011-08-29 12:34:40 +0000
29+++ nova/tests/test_compute.py 2011-09-03 00:13:26 +0000
30@@ -161,6 +161,19 @@
31 db.security_group_destroy(self.context, group['id'])
32 db.instance_destroy(self.context, ref[0]['id'])
33
34+ def test_create_instance_with_invalid_security_group_raises(self):
35+ instance_type = instance_types.get_default_instance_type()
36+
37+ pre_build_len = len(db.instance_get_all(context.get_admin_context()))
38+ self.assertRaises(exception.SecurityGroupNotFoundForProject,
39+ self.compute_api.create,
40+ self.context,
41+ instance_type=instance_type,
42+ image_href=None,
43+ security_group=['this_is_a_fake_sec_group'])
44+ self.assertEqual(pre_build_len,
45+ len(db.instance_get_all(context.get_admin_context())))
46+
47 def test_create_instance_associates_config_drive(self):
48 """Make sure create associates a config drive."""
49