Skip to content

Commit abcafdb

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Remove 'get_keypair_at_top'"
2 parents 5a9b3f3 + cace9b4 commit abcafdb

File tree

8 files changed

+8
-194
lines changed

8 files changed

+8
-194
lines changed

nova/api/metadata/base.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
from nova.api.metadata import vendordata_dynamic
3131
from nova.api.metadata import vendordata_json
3232
from nova import block_device
33-
from nova.cells import opts as cells_opts
34-
from nova.cells import rpcapi as cells_rpcapi
3533
import nova.conf
3634
from nova import context
3735
from nova import exception
@@ -327,23 +325,12 @@ def _metadata_as_json(self, version, path):
327325
metadata['network_config'] = self.network_config
328326

329327
if self.instance.key_name:
330-
if cells_opts.get_cell_type() == 'compute':
331-
cells_api = cells_rpcapi.CellsAPI()
332-
try:
333-
keypair = cells_api.get_keypair_at_top(
334-
context.get_admin_context(), self.instance.user_id,
335-
self.instance.key_name)
336-
except exception.KeypairNotFound:
337-
# NOTE(lpigueir): If keypair was deleted, treat
338-
# it like it never had any
339-
keypair = None
340-
else:
341-
keypairs = self.instance.keypairs
342-
# NOTE(mriedem): It's possible for the keypair to be deleted
343-
# before it was migrated to the instance_extra table, in which
344-
# case lazy-loading instance.keypairs will handle the 404 and
345-
# just set an empty KeyPairList object on the instance.
346-
keypair = keypairs[0] if keypairs else None
328+
keypairs = self.instance.keypairs
329+
# NOTE(mriedem): It's possible for the keypair to be deleted
330+
# before it was migrated to the instance_extra table, in which
331+
# case lazy-loading instance.keypairs will handle the 404 and
332+
# just set an empty KeyPairList object on the instance.
333+
keypair = keypairs[0] if keypairs else None
347334

348335
if keypair:
349336
metadata['public_keys'] = {

nova/cells/manager.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -550,19 +550,3 @@ def rebuild_instance(self, ctxt, instance, image_href, admin_password,
550550

551551
def set_admin_password(self, ctxt, instance, new_pass):
552552
self.msg_runner.set_admin_password(ctxt, instance, new_pass)
553-
554-
def get_keypair_at_top(self, ctxt, user_id, name):
555-
responses = self.msg_runner.get_keypair_at_top(ctxt, user_id, name)
556-
keypairs = [resp.value for resp in responses if resp.value is not None]
557-
558-
if len(keypairs) == 0:
559-
return None
560-
elif len(keypairs) > 1:
561-
cell_names = ', '.join([resp.cell_name for resp in responses
562-
if resp.value is not None])
563-
LOG.warning("The same keypair name '%(name)s' exists in the "
564-
"following cells: %(cell_names)s. The keypair "
565-
"value from the first cell is returned.",
566-
{'name': name, 'cell_names': cell_names})
567-
568-
return keypairs[0]

nova/cells/messaging.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,18 +1146,6 @@ def consoleauth_delete_tokens(self, message, instance_uuid):
11461146
def get_migrations(self, message, filters):
11471147
return self.compute_api.get_migrations(message.ctxt, filters)
11481148

1149-
def get_keypair_at_top(self, message, user_id, name):
1150-
"""Get keypair in API cells by name. Just return None if there is
1151-
no match keypair.
1152-
"""
1153-
if not self._at_the_top():
1154-
return
1155-
1156-
try:
1157-
return objects.KeyPair.get_by_name(message.ctxt, user_id, name)
1158-
except exception.KeypairNotFound:
1159-
pass
1160-
11611149

11621150
_CELL_MESSAGE_TYPE_TO_MESSAGE_CLS = {'targeted': _TargetedMessage,
11631151
'broadcast': _BroadcastMessage,
@@ -1724,15 +1712,6 @@ def set_admin_password(self, ctxt, instance, new_pass):
17241712
self._instance_action(ctxt, instance, 'set_admin_password',
17251713
extra_kwargs={'new_pass': new_pass})
17261714

1727-
def get_keypair_at_top(self, ctxt, user_id, name):
1728-
"""Get Key Pair by name at top level cell."""
1729-
message = _BroadcastMessage(self, ctxt,
1730-
'get_keypair_at_top',
1731-
dict(user_id=user_id, name=name),
1732-
'up',
1733-
need_response=True, run_locally=False)
1734-
return message.process()
1735-
17361715
@staticmethod
17371716
def get_message_types():
17381717
return _CELL_MESSAGE_TYPE_TO_MESSAGE_CLS.keys()

nova/cells/rpcapi.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,3 @@ def set_admin_password(self, ctxt, instance, new_pass):
611611
cctxt = self.client.prepare(version='1.29')
612612
cctxt.cast(ctxt, 'set_admin_password', instance=instance,
613613
new_pass=new_pass)
614-
615-
def get_keypair_at_top(self, ctxt, user_id, name):
616-
if not CONF.cells.enable:
617-
return
618-
619-
cctxt = self.client.prepare(version='1.37')
620-
keypair = cctxt.call(ctxt, 'get_keypair_at_top', user_id=user_id,
621-
name=name)
622-
if keypair is None:
623-
raise exception.KeypairNotFound(user_id=user_id,
624-
name=name)
625-
return keypair

nova/tests/unit/cells/test_cells_manager.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -848,27 +848,3 @@ def test_set_admin_password(self):
848848
instance='fake-instance', new_pass='fake-password')
849849
set_admin_password.assert_called_once_with(self.ctxt,
850850
'fake-instance', 'fake-password')
851-
852-
def test_get_keypair_at_top(self):
853-
keypairs = [self._get_fake_response('fake_keypair'),
854-
self._get_fake_response('fake_keypair2')]
855-
with mock.patch.object(self.msg_runner,
856-
'get_keypair_at_top',
857-
return_value=keypairs) as fake_get_keypair:
858-
response = self.cells_manager.get_keypair_at_top(self.ctxt,
859-
'fake_user_id',
860-
'fake_name')
861-
fake_get_keypair.assert_called_once_with(self.ctxt, 'fake_user_id',
862-
'fake_name')
863-
self.assertEqual('fake_keypair', response)
864-
865-
def test_get_keypair_at_top_with_empty_responses(self):
866-
with mock.patch.object(self.msg_runner,
867-
'get_keypair_at_top',
868-
return_value=[]) as fake_get_keypair:
869-
self.assertIsNone(
870-
self.cells_manager.get_keypair_at_top(self.ctxt,
871-
'fake_user_id',
872-
'fake_name'))
873-
fake_get_keypair.assert_called_once_with(self.ctxt, 'fake_user_id',
874-
'fake_name')

nova/tests/unit/cells/test_cells_messaging.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,48 +1896,6 @@ def test_get_migrations(self):
18961896
self.assertIn(response.value_or_raise(), [migrations_from_cell1,
18971897
migrations_from_cell2])
18981898

1899-
@mock.patch.object(objects.KeyPair, 'get_by_name',
1900-
return_value='fake_keypair')
1901-
def test_get_keypair_at_top(self, fake_get_by_name):
1902-
user_id = 'fake_user_id'
1903-
name = 'fake_keypair_name'
1904-
responses = self.src_msg_runner.get_keypair_at_top(self.ctxt,
1905-
user_id, name)
1906-
fake_get_by_name.assert_called_once_with(self.ctxt, user_id, name)
1907-
1908-
for response in responses:
1909-
if response.value is not None:
1910-
self.assertEqual('fake_keypair', response.value)
1911-
1912-
@mock.patch.object(objects.KeyPair, 'get_by_name')
1913-
def test_get_keypair_at_top_with_objects_exception(self, fake_get_by_name):
1914-
user_id = 'fake_user_id'
1915-
name = 'fake_keypair_name'
1916-
keypair_exception = exception.KeypairNotFound(user_id=user_id,
1917-
name=name)
1918-
fake_get_by_name.side_effect = keypair_exception
1919-
responses = self.src_msg_runner.get_keypair_at_top(self.ctxt,
1920-
user_id,
1921-
name)
1922-
fake_get_by_name.assert_called_once_with(self.ctxt, user_id, name)
1923-
1924-
for response in responses:
1925-
self.assertIsNone(response.value)
1926-
1927-
@mock.patch.object(messaging._BroadcastMessage, 'process')
1928-
def test_get_keypair_at_top_with_process_response(self, fake_process):
1929-
user_id = 'fake_user_id'
1930-
name = 'fake_keypair_name'
1931-
response = messaging.Response(self.ctxt, 'cell', 'keypair', False)
1932-
other_response = messaging.Response(self.ctxt, 'cell',
1933-
'fake_other_keypair', False)
1934-
fake_process.return_value = [response, other_response]
1935-
1936-
responses = self.src_msg_runner.get_keypair_at_top(self.ctxt,
1937-
user_id, name)
1938-
fake_process.assert_called_once_with()
1939-
self.assertEqual(fake_process.return_value, responses)
1940-
19411899

19421900
class CellsPublicInterfacesTestCase(test.NoDBTestCase):
19431901
"""Test case for the public interfaces into cells messaging."""

nova/tests/unit/cells/test_cells_rpcapi.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -805,25 +805,3 @@ def test_set_admin_password(self):
805805
'new_pass': 'fake-password'}
806806
self._check_result(call_info, 'set_admin_password',
807807
expected_args, version='1.29')
808-
809-
def test_get_keypair_at_top(self):
810-
call_info = self._stub_rpc_method('call', 'fake_response')
811-
result = self.cells_rpcapi.get_keypair_at_top(self.fake_context,
812-
'fake_user_id', 'fake_name')
813-
814-
expected_args = {'user_id': 'fake_user_id',
815-
'name': 'fake_name'}
816-
self._check_result(call_info, 'get_keypair_at_top',
817-
expected_args, version='1.37')
818-
self.assertEqual(result, 'fake_response')
819-
820-
def test_get_keypair_at_top_with_not_found(self):
821-
call_info = self._stub_rpc_method('call', None)
822-
self.assertRaises(exception.KeypairNotFound,
823-
self.cells_rpcapi.get_keypair_at_top,
824-
self.fake_context, 'fake_user_id', 'fake_name')
825-
826-
expected_args = {'user_id': 'fake_user_id',
827-
'name': 'fake_name'}
828-
self._check_result(call_info, 'get_keypair_at_top',
829-
expected_args, version='1.37')

nova/tests/unit/test_metadata.py

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,10 @@ def test_local_ipv4_from_address(self):
558558

559559
@mock.patch('oslo_serialization.base64.encode_as_text',
560560
return_value=FAKE_SEED)
561-
@mock.patch('nova.cells.rpcapi.CellsAPI.get_keypair_at_top')
562561
@mock.patch.object(jsonutils, 'dump_as_bytes')
563562
def _test_as_json_with_options(self, mock_json_dump_as_bytes,
564-
mock_cells_keypair, mock_base64,
565-
is_cells=False, os_version=base.GRIZZLY):
566-
if is_cells:
567-
self.flags(enable=True, group='cells')
568-
self.flags(cell_type='compute', group='cells')
569-
563+
mock_base64,
564+
os_version=base.GRIZZLY):
570565
instance = self.instance
571566
keypair = self.keypair
572567
md = fake_InstanceMetadata(self, instance)
@@ -604,45 +599,14 @@ def _test_as_json_with_options(self, mock_json_dump_as_bytes,
604599
expose_trusted = md._check_os_version(base.ROCKY, os_version)
605600
expected_metadata['devices'] = fake_metadata_dicts(
606601
True, expose_trusted)
607-
mock_cells_keypair.return_value = keypair
608602
md._metadata_as_json(os_version, 'non useless path parameter')
609-
if instance.key_name:
610-
if is_cells:
611-
mock_cells_keypair.assert_called_once_with(mock.ANY,
612-
instance.user_id,
613-
instance.key_name)
614-
self.assertIsInstance(mock_cells_keypair.call_args[0][0],
615-
context.RequestContext)
616603
self.assertEqual(md.md_mimetype, base.MIME_TYPE_APPLICATION_JSON)
617604
mock_json_dump_as_bytes.assert_called_once_with(expected_metadata)
618605

619606
def test_as_json(self):
620607
for os_version in base.OPENSTACK_VERSIONS:
621608
self._test_as_json_with_options(os_version=os_version)
622609

623-
def test_as_json_with_cells_mode(self):
624-
for os_version in base.OPENSTACK_VERSIONS:
625-
self._test_as_json_with_options(is_cells=True,
626-
os_version=os_version)
627-
628-
@mock.patch('nova.cells.rpcapi.CellsAPI.get_keypair_at_top',
629-
side_effect=exception.KeypairNotFound(
630-
name='key', user_id='fake_user'))
631-
@mock.patch.object(objects.Instance, 'get_by_uuid')
632-
def test_as_json_deleted_keypair_in_cells_mode(self,
633-
mock_get_keypair_at_top,
634-
mock_inst_get_by_uuid):
635-
self.flags(enable=True, group='cells')
636-
self.flags(cell_type='compute', group='cells')
637-
638-
instance = self.instance.obj_clone()
639-
delattr(instance, 'keypairs')
640-
md = fake_InstanceMetadata(self, instance)
641-
meta = md._metadata_as_json(base.OPENSTACK_VERSIONS[-1], path=None)
642-
meta = jsonutils.loads(meta)
643-
self.assertNotIn('keys', meta)
644-
self.assertNotIn('public_keys', meta)
645-
646610
@mock.patch.object(objects.Instance, 'get_by_uuid')
647611
def test_metadata_as_json_deleted_keypair(self, mock_inst_get_by_uuid):
648612
"""Tests that we handle missing instance keypairs.

0 commit comments

Comments
 (0)