Merge lp:~justin-fathomdb/nova/bug732204 into lp:~hudson-openstack/nova/trunk

Proposed by justinsb
Status: Merged
Approved by: Jay Pipes
Approved revision: 806
Merge reported by: Jay Pipes
Merged at revision: not available
Proposed branch: lp:~justin-fathomdb/nova/bug732204
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 84 lines (+27/-8)
3 files modified
nova/api/openstack/servers.py (+9/-5)
nova/tests/api/openstack/fakes.py (+9/-2)
nova/tests/api/openstack/test_servers.py (+9/-1)
To merge this branch: bzr merge lp:~justin-fathomdb/nova/bug732204
Reviewer Review Type Date Requested Status
Rick Harris (community) Approve
Jay Pipes (community) Approve
Dan Prince (community) Approve
Review via email: mp+53359@code.launchpad.net

Description of the change

Keypairs are not required in the OpenStack API; don't require them!

To post a comment you must log in.
Revision history for this message
Dan Prince (dan-prince) wrote :

LGTM.

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

Do we have a test case that stresses the code path where no key pair is present?

review: Needs Information
Revision history for this message
justinsb (justin-fathomdb) wrote :

Well, I have a testing branch that is failing right now because it needs a
key pair:
https://code.launchpad.net/~justin-fathomdb/nova/test-openstack-servers

So we will (hopefully) have a test soon, but it's not in this MP.

Revision history for this message
Jay Pipes (jaypipes) wrote :

I understand about the other branch, but can we add a test case to this branch that stresses the code path of not having a key pair, or is that not possible?

Revision history for this message
justinsb (justin-fathomdb) wrote :

I'll see if I can rustle something up...

Revision history for this message
justinsb (justin-fathomdb) wrote :

Added test with and without keypairs. Test fails without the patch.

Revision history for this message
Jay Pipes (jaypipes) wrote :

danke! lgtm.

review: Approve
Revision history for this message
Rick Harris (rconradharris) wrote :

Nice job, Justin. Ran the code w/ and w/o fix, tests worked as expected.

Small nits:

> 66 + def _test_create_instance_helper(self, with_key_pair)

`with_key_pair` isn't used.

> 78 + fakes.stub_out_key_pair_funcs(self.stubs, False)

Test might be a bit more readable if kwarg passing was used:

    fakes.stub_out_key_pair_funcs(self.stubs, have_key_pair=False)

review: Needs Fixing
Revision history for this message
justinsb (justin-fathomdb) wrote :

Thanks Rick - obviously wasn't paying 100% attention there....

Revision history for this message
Rick Harris (rconradharris) wrote :

lgtm

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (30.3 KiB)

The attempt to merge lp:~justin-fathomdb/nova/bug732204 into lp:nova failed. Below is the output from the failed tests.

AccountsTest
    test_account_create OK
    test_account_delete OK
    test_account_update OK
    test_get_account OK
AdminAPITest
    test_admin_disabled OK
    test_admin_enabled OK
APITest
    test_exceptions_are_converted_to_faults OK
Test
    test_authorize_token OK
    test_authorize_user OK
    test_bad_token OK
    test_bad_user_bad_key OK
    test_bad_user_good_key OK
    test_no_user OK
    test_token_expiry OK
TestFunctional
    test_token_doesnotexist OK
    test_token_expiry OK
TestLimiter
    test_authorize_token OK
LimiterTest
    test_limiter_custom_max_limit OK
    test_limiter_limit_and_offset OK
    test_limiter_limit_medium OK
    test_limiter_limit_over_max OK
    test_limiter_limit_zero OK
    test_limiter_negative_limit OK
    test_limiter_negative_offset OK
    test_limiter_nothing OK
    test_limiter_offset_bad OK
    test_limiter_offset_blank OK
    test_limiter_offset_medium OK
    test_limiter_offset_over_max OK
    test_limiter_offset_zero OK
TestFaults
    test_fault_parts OK
    test_raise OK
    test_retry_header OK
FlavorsTest
    test_get_flavor_by_id OK
    test_get_flavor_list OK
GlanceImageServiceTest
    test_create OK
    test_create_and_show_non_existing_image OK
    test_delete OK
    test_update OK
ImageControllerWithGlanceServiceTest
    test_get_image_details OK
    test_get_image_index OK
LocalImageServiceTest
    test_create OK
    test_create_and_show_non_existing_image OK
    test_delete...

Revision history for this message
justinsb (justin-fathomdb) wrote :

Hopefully this will keep Jenkins happy.

And no, this time I wasn't using git-bzr :-)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (30.3 KiB)

The attempt to merge lp:~justin-fathomdb/nova/bug732204 into lp:nova failed. Below is the output from the failed tests.

AccountsTest
    test_account_create OK
    test_account_delete OK
    test_account_update OK
    test_get_account OK
AdminAPITest
    test_admin_disabled OK
    test_admin_enabled OK
APITest
    test_exceptions_are_converted_to_faults OK
Test
    test_authorize_token OK
    test_authorize_user OK
    test_bad_token OK
    test_bad_user_bad_key OK
    test_bad_user_good_key OK
    test_no_user OK
    test_token_expiry OK
TestFunctional
    test_token_doesnotexist OK
    test_token_expiry OK
TestLimiter
    test_authorize_token OK
LimiterTest
    test_limiter_custom_max_limit OK
    test_limiter_limit_and_offset OK
    test_limiter_limit_medium OK
    test_limiter_limit_over_max OK
    test_limiter_limit_zero OK
    test_limiter_negative_limit OK
    test_limiter_negative_offset OK
    test_limiter_nothing OK
    test_limiter_offset_bad OK
    test_limiter_offset_blank OK
    test_limiter_offset_medium OK
    test_limiter_offset_over_max OK
    test_limiter_offset_zero OK
TestFaults
    test_fault_parts OK
    test_raise OK
    test_retry_header OK
FlavorsTest
    test_get_flavor_by_id OK
    test_get_flavor_list OK
GlanceImageServiceTest
    test_create OK
    test_create_and_show_non_existing_image OK
    test_delete OK
    test_update OK
ImageControllerWithGlanceServiceTest
    test_get_image_details OK
    test_get_image_index OK
LocalImageServiceTest
    test_create OK
    test_create_and_show_non_existing_image OK
    test_delete...

Revision history for this message
Jay Pipes (jaypipes) wrote :

cleaning this up locally...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/servers.py'
2--- nova/api/openstack/servers.py 2011-03-11 19:49:32 +0000
3+++ nova/api/openstack/servers.py 2011-03-16 00:01:22 +0000
4@@ -146,10 +146,14 @@
5 return faults.Fault(exc.HTTPUnprocessableEntity())
6
7 context = req.environ['nova.context']
8+
9+ key_name = None
10+ key_data = None
11 key_pairs = auth_manager.AuthManager.get_key_pairs(context)
12- if not key_pairs:
13- raise exception.NotFound(_("No keypairs defined"))
14- key_pair = key_pairs[0]
15+ if key_pairs:
16+ key_pair = key_pairs[0]
17+ key_name = key_pair['name']
18+ key_data = key_pair['public_key']
19
20 image_id = common.get_image_id_from_image_hash(self._image_service,
21 context, env['server']['imageId'])
22@@ -174,8 +178,8 @@
23 ramdisk_id=ramdisk_id,
24 display_name=env['server']['name'],
25 display_description=env['server']['name'],
26- key_name=key_pair['name'],
27- key_data=key_pair['public_key'],
28+ key_name=key_name,
29+ key_data=key_data,
30 metadata=metadata,
31 onset_files=env.get('onset_files', []))
32
33
34=== modified file 'nova/tests/api/openstack/fakes.py'
35--- nova/tests/api/openstack/fakes.py 2011-03-11 22:19:14 +0000
36+++ nova/tests/api/openstack/fakes.py 2011-03-16 00:01:22 +0000
37@@ -85,10 +85,17 @@
38 return mapper
39
40
41-def stub_out_key_pair_funcs(stubs):
42+def stub_out_key_pair_funcs(stubs, have_key_pair=True):
43 def key_pair(context, user_id):
44 return [dict(name='key', public_key='public_key')]
45- stubs.Set(nova.db, 'key_pair_get_all_by_user', key_pair)
46+
47+ def no_key_pair(context, user_id):
48+ return []
49+
50+ if have_key_pair:
51+ stubs.Set(nova.db, 'key_pair_get_all_by_user', key_pair)
52+ else:
53+ stubs.Set(nova.db, 'key_pair_get_all_by_user', no_key_pair)
54
55
56 def stub_out_image_service(stubs):
57
58=== modified file 'nova/tests/api/openstack/test_servers.py'
59--- nova/tests/api/openstack/test_servers.py 2011-03-11 19:49:32 +0000
60+++ nova/tests/api/openstack/test_servers.py 2011-03-16 00:01:22 +0000
61@@ -216,7 +216,8 @@
62 servers = json.loads(res.body)['servers']
63 self.assertEqual([s['id'] for s in servers], [1, 2])
64
65- def test_create_instance(self):
66+ def _test_create_instance_helper(self):
67+ """Shared implementation for tests below that create instance"""
68 def instance_create(context, inst):
69 return {'id': '1', 'display_name': 'server_test'}
70
71@@ -271,6 +272,13 @@
72
73 self.assertEqual(res.status_int, 200)
74
75+ def test_create_instance(self):
76+ self._test_create_instance_helper()
77+
78+ def test_create_instance_no_key_pair(self):
79+ fakes.stub_out_key_pair_funcs(self.stubs, have_key_pair=False)
80+ self._test_create_instance_helper()
81+
82 def test_update_no_body(self):
83 req = webob.Request.blank('/v1.0/servers/1')
84 req.method = 'PUT'