diff options
-rw-r--r-- | nova/compute/api.py | 2 | ||||
-rw-r--r-- | nova/tests/unit/api/openstack/compute/test_servers.py | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 704de35db1..d1b510cc41 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -822,7 +822,7 @@ class API(base.Base): config_drive = self._check_config_drive(config_drive) - if key_data is None and key_name: + if key_data is None and key_name is not None: key_pair = objects.KeyPair.get_by_name(context, context.user_id, key_name) diff --git a/nova/tests/unit/api/openstack/compute/test_servers.py b/nova/tests/unit/api/openstack/compute/test_servers.py index c3efb5e983..a43ed1c8a8 100644 --- a/nova/tests/unit/api/openstack/compute/test_servers.py +++ b/nova/tests/unit/api/openstack/compute/test_servers.py @@ -2289,6 +2289,15 @@ class ServersControllerCreateTest(test.TestCase): self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, self.req, self.body) + @mock.patch('nova.compute.api.API.create', + side_effect=exception.KeypairNotFound(name='', + user_id=1)) + def test_create_instance_empty_key_name(self, mock_create): + self.body['server']['key_name'] = '' + self.req.body = jsonutils.dumps(self.body) + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller.create, self.req, self.body) + def test_create_instance_valid_key_name(self): self.body['server']['key_name'] = 'key' self.req.body = jsonutils.dumps(self.body) |