Handle keypair not found from metadata server using cells
Fixes https://bugs.launchpad.net/nova/+bug/1592167 for the cells case. The fix done in https://bugs.launchpad.net/nova/+bug/1592167 only solves the problem when cells are not used at all Closes-bug: #1592167 Change-Id: Id663b426261150a1cce310cb4a61d9572f78c016
This commit is contained in:
parent
22842a4b88
commit
682276be6d
|
@ -342,9 +342,14 @@ class InstanceMetadata(object):
|
||||||
if self.instance.key_name:
|
if self.instance.key_name:
|
||||||
if cells_opts.get_cell_type() == 'compute':
|
if cells_opts.get_cell_type() == 'compute':
|
||||||
cells_api = cells_rpcapi.CellsAPI()
|
cells_api = cells_rpcapi.CellsAPI()
|
||||||
keypair = cells_api.get_keypair_at_top(
|
try:
|
||||||
context.get_admin_context(), self.instance.user_id,
|
keypair = cells_api.get_keypair_at_top(
|
||||||
self.instance.key_name)
|
context.get_admin_context(), self.instance.user_id,
|
||||||
|
self.instance.key_name)
|
||||||
|
except exception.KeypairNotFound:
|
||||||
|
# NOTE(lpigueir): If keypair was deleted, treat
|
||||||
|
# it like it never had any
|
||||||
|
keypair = None
|
||||||
else:
|
else:
|
||||||
keypairs = self.instance.keypairs
|
keypairs = self.instance.keypairs
|
||||||
# NOTE(mriedem): It's possible for the keypair to be deleted
|
# NOTE(mriedem): It's possible for the keypair to be deleted
|
||||||
|
|
|
@ -568,6 +568,24 @@ class MetadataTestCase(test.TestCase):
|
||||||
self._test_as_json_with_options(is_cells=True,
|
self._test_as_json_with_options(is_cells=True,
|
||||||
os_version=os_version)
|
os_version=os_version)
|
||||||
|
|
||||||
|
@mock.patch('nova.cells.rpcapi.CellsAPI.get_keypair_at_top',
|
||||||
|
side_effect=exception.KeypairNotFound(
|
||||||
|
name='key', user_id='fake_user'))
|
||||||
|
@mock.patch.object(objects.Instance, 'get_by_uuid')
|
||||||
|
def test_as_json_deleted_keypair_in_cells_mode(self,
|
||||||
|
mock_get_keypair_at_top,
|
||||||
|
mock_inst_get_by_uuid):
|
||||||
|
self.flags(enable=True, group='cells')
|
||||||
|
self.flags(cell_type='compute', group='cells')
|
||||||
|
|
||||||
|
instance = self.instance.obj_clone()
|
||||||
|
delattr(instance, 'keypairs')
|
||||||
|
md = fake_InstanceMetadata(self, instance)
|
||||||
|
meta = md._metadata_as_json(base.OPENSTACK_VERSIONS[-1], path=None)
|
||||||
|
meta = jsonutils.loads(meta)
|
||||||
|
self.assertNotIn('keys', meta)
|
||||||
|
self.assertNotIn('public_keys', meta)
|
||||||
|
|
||||||
@mock.patch.object(objects.Instance, 'get_by_uuid')
|
@mock.patch.object(objects.Instance, 'get_by_uuid')
|
||||||
def test_metadata_as_json_deleted_keypair(self, mock_inst_get_by_uuid):
|
def test_metadata_as_json_deleted_keypair(self, mock_inst_get_by_uuid):
|
||||||
"""Tests that we handle missing instance keypairs.
|
"""Tests that we handle missing instance keypairs.
|
||||||
|
|
Loading…
Reference in New Issue