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
(cherry picked from commit 682276be6d
)
This commit is contained in:
parent
a98a52d85e
commit
b9a1ccc5fd
|
@ -343,9 +343,14 @@ class InstanceMetadata(object):
|
|||
if self.instance.key_name:
|
||||
if cells_opts.get_cell_type() == 'compute':
|
||||
cells_api = cells_rpcapi.CellsAPI()
|
||||
keypair = cells_api.get_keypair_at_top(
|
||||
context.get_admin_context(), self.instance.user_id,
|
||||
self.instance.key_name)
|
||||
try:
|
||||
keypair = cells_api.get_keypair_at_top(
|
||||
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:
|
||||
keypairs = self.instance.keypairs
|
||||
# NOTE(mriedem): It's possible for the keypair to be deleted
|
||||
|
|
|
@ -591,6 +591,24 @@ class MetadataTestCase(test.TestCase):
|
|||
self._test_as_json_with_options(is_cells=True,
|
||||
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')
|
||||
def test_metadata_as_json_deleted_keypair(self, mock_inst_get_by_uuid):
|
||||
"""Tests that we handle missing instance keypairs.
|
||||
|
|
Loading…
Reference in New Issue