Skip to content

Commit ea29f20

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Remove 'instance_update_at_top', 'instance_destroy_at_top'"
2 parents dd6bd75 + a627723 commit ea29f20

File tree

12 files changed

+16
-693
lines changed

12 files changed

+16
-693
lines changed

nova/cells/manager.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ def _sync_instance(self, ctxt, instance):
175175
"""Broadcast an instance_update or instance_destroy message up to
176176
parent cells.
177177
"""
178-
if instance.deleted:
179-
self.instance_destroy_at_top(ctxt, instance)
180-
else:
181-
self.instance_update_at_top(ctxt, instance)
178+
pass
182179

183180
def build_instances(self, ctxt, build_inst_kwargs):
184181
"""Pick a cell (possibly ourselves) to build new instance(s) and
@@ -217,14 +214,6 @@ def run_compute_api_method(self, ctxt, cell_name, method_info, call):
217214
if call:
218215
return response.value_or_raise()
219216

220-
def instance_update_at_top(self, ctxt, instance):
221-
"""Update an instance at the top level cell."""
222-
self.msg_runner.instance_update_at_top(ctxt, instance)
223-
224-
def instance_destroy_at_top(self, ctxt, instance):
225-
"""Destroy an instance at the top level cell."""
226-
self.msg_runner.instance_destroy_at_top(ctxt, instance)
227-
228217
def instance_delete_everywhere(self, ctxt, instance, delete_type):
229218
"""This is used by API cell when it didn't know what cell
230219
an instance was in, but the instance was requested to be

nova/cells/messaging.py

Lines changed: 7 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from oslo_log import log as logging
3535
import oslo_messaging as messaging
3636
from oslo_serialization import jsonutils
37-
from oslo_utils import excutils
3837
from oslo_utils import importutils
3938
from oslo_utils import timeutils
4039
from oslo_utils import uuidutils
@@ -57,7 +56,6 @@
5756
from nova import objects
5857
from nova.objects import base as objects_base
5958
from nova import rpc
60-
from nova import utils
6159

6260
CONF = nova.conf.CONF
6361

@@ -661,19 +659,10 @@ def run_compute_api_method(self, message, method_info):
661659
expected_attrs = ['metadata', 'system_metadata', 'security_groups',
662660
'info_cache']
663661

664-
try:
665-
instance = objects.Instance.get_by_uuid(message.ctxt,
666-
instance_uuid, expected_attrs=expected_attrs)
667-
args[0] = instance
668-
except exception.InstanceNotFound:
669-
with excutils.save_and_reraise_exception():
670-
# Must be a race condition. Let's try to resolve it by
671-
# telling the top level cells that this instance doesn't
672-
# exist.
673-
instance = objects.Instance(context=message.ctxt,
674-
uuid=instance_uuid)
675-
self.msg_runner.instance_destroy_at_top(message.ctxt,
676-
instance)
662+
instance = objects.Instance.get_by_uuid(message.ctxt,
663+
instance_uuid, expected_attrs=expected_attrs)
664+
args[0] = instance
665+
677666
return fn(message.ctxt, *args, **method_info['method_kwargs'])
678667

679668
def update_capabilities(self, message, cell_name, capabilities):
@@ -771,18 +760,8 @@ def validate_console_port(self, message, instance_uuid, console_port,
771760
"""Validate console port with child cell compute node."""
772761
# 1st arg is instance_uuid that we need to turn into the
773762
# instance object.
774-
try:
775-
instance = objects.Instance.get_by_uuid(message.ctxt,
776-
instance_uuid)
777-
except exception.InstanceNotFound:
778-
with excutils.save_and_reraise_exception():
779-
# Must be a race condition. Let's try to resolve it by
780-
# telling the top level cells that this instance doesn't
781-
# exist.
782-
instance = objects.Instance(context=message.ctxt,
783-
uuid=instance_uuid)
784-
self.msg_runner.instance_destroy_at_top(message.ctxt,
785-
instance)
763+
instance = objects.Instance.get_by_uuid(message.ctxt,
764+
instance_uuid)
786765
return self.compute_rpcapi.validate_console_port(message.ctxt,
787766
instance, console_port, console_type)
788767

@@ -812,15 +791,6 @@ def _call_compute_api_with_obj(self, ctxt, instance, method, *args,
812791
# NOTE(comstud): We need to refresh the instance from this
813792
# cell's view in the DB.
814793
instance.refresh()
815-
except exception.InstanceNotFound:
816-
with excutils.save_and_reraise_exception():
817-
# Must be a race condition. Let's try to resolve it by
818-
# telling the top level cells that this instance doesn't
819-
# exist.
820-
instance = objects.Instance(context=ctxt,
821-
uuid=instance.uuid)
822-
self.msg_runner.instance_destroy_at_top(ctxt,
823-
instance)
824794
except exception.InstanceInfoCacheNotFound:
825795
if method not in ('delete', 'force_delete'):
826796
raise
@@ -1006,70 +976,6 @@ def _get_expected_task_state(self, instance):
1006976
if instance.obj_attr_is_set('task_state'):
1007977
return expected_task_state_map.get(instance.task_state)
1008978

1009-
def instance_update_at_top(self, message, instance, **kwargs):
1010-
"""Update an instance in the DB if we're a top level cell."""
1011-
if not self._at_the_top():
1012-
return
1013-
1014-
# Remove things that we can't update in the top level cells.
1015-
# 'metadata' is only updated in the API cell, so don't overwrite
1016-
# it based on what child cells say. Make sure to update
1017-
# 'cell_name' based on the routing path.
1018-
items_to_remove = ['id', 'security_groups', 'volumes', 'cell_name',
1019-
'name', 'metadata']
1020-
instance.obj_reset_changes(items_to_remove)
1021-
instance.cell_name = _reverse_path(message.routing_path)
1022-
1023-
# instance.display_name could be unicode
1024-
instance_repr = utils.get_obj_repr_unicode(instance)
1025-
LOG.debug("Got update for instance: %(instance)s",
1026-
{'instance': instance_repr}, instance_uuid=instance.uuid)
1027-
1028-
expected_vm_state = self._get_expected_vm_state(instance)
1029-
expected_task_state = self._get_expected_task_state(instance)
1030-
1031-
# It's possible due to some weird condition that the instance
1032-
# was already set as deleted... so we'll attempt to update
1033-
# it with permissions that allows us to read deleted.
1034-
with utils.temporary_mutation(message.ctxt, read_deleted="yes"):
1035-
try:
1036-
with instance.skip_cells_sync():
1037-
instance.save(expected_vm_state=expected_vm_state,
1038-
expected_task_state=expected_task_state)
1039-
except exception.InstanceNotFound:
1040-
# FIXME(comstud): Strange. Need to handle quotas here,
1041-
# if we actually want this code to remain..
1042-
instance.create()
1043-
except exception.NotFound:
1044-
# Can happen if we try to update a deleted instance's
1045-
# network information, for example.
1046-
pass
1047-
1048-
def instance_destroy_at_top(self, message, instance, **kwargs):
1049-
"""Destroy an instance from the DB if we're a top level cell."""
1050-
if not self._at_the_top():
1051-
return
1052-
LOG.debug("Got update to delete instance",
1053-
instance_uuid=instance.uuid)
1054-
try:
1055-
instance.destroy()
1056-
except exception.InstanceNotFound:
1057-
pass
1058-
except exception.ObjectActionError:
1059-
# NOTE(alaski): instance_destroy_at_top will sometimes be called
1060-
# when an instance does not exist in a cell but does in the parent.
1061-
# In that case instance.id is not set which causes instance.destroy
1062-
# to fail thinking that the object has already been destroyed.
1063-
# That's the right assumption for it to make because without cells
1064-
# that would be true. But for cells we'll try to pull the actual
1065-
# instance and try to delete it again.
1066-
try:
1067-
instance = objects.Instance.get_by_uuid(message.ctxt,
1068-
instance.uuid)
1069-
instance.destroy()
1070-
except exception.InstanceNotFound:
1071-
pass
1072-
1073979
def instance_delete_everywhere(self, message, instance, delete_type,
1074980
**kwargs):
1075981
"""Call compute API delete() or soft_delete() in every cell.
@@ -1091,10 +997,7 @@ def bw_usage_update_at_top(self, message, bw_update_info, **kwargs):
1091997
self.db.bw_usage_update(message.ctxt, **bw_update_info)
1092998

1093999
def _sync_instance(self, ctxt, instance):
1094-
if instance.deleted:
1095-
self.msg_runner.instance_destroy_at_top(ctxt, instance)
1096-
else:
1097-
self.msg_runner.instance_update_at_top(ctxt, instance)
1000+
pass
10981001

10991002
def sync_instances(self, message, project_id, updated_since, deleted,
11001003
**kwargs):
@@ -1356,20 +1259,6 @@ def run_compute_api_method(self, ctxt, cell_name, method_info, call):
13561259
cell_name, need_response=call)
13571260
return message.process()
13581261

1359-
def instance_update_at_top(self, ctxt, instance):
1360-
"""Update an instance at the top level cell."""
1361-
message = _BroadcastMessage(self, ctxt, 'instance_update_at_top',
1362-
dict(instance=instance), 'up',
1363-
run_locally=False)
1364-
message.process()
1365-
1366-
def instance_destroy_at_top(self, ctxt, instance):
1367-
"""Destroy an instance at the top level cell."""
1368-
message = _BroadcastMessage(self, ctxt, 'instance_destroy_at_top',
1369-
dict(instance=instance), 'up',
1370-
run_locally=False)
1371-
message.process()
1372-
13731262
def instance_delete_everywhere(self, ctxt, instance, delete_type):
13741263
"""This is used by API cell when it didn't know what cell
13751264
an instance was in, but the instance was requested to be

nova/cells/rpcapi.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,6 @@ def build_instances(self, ctxt, **kwargs):
201201
cctxt.cast(ctxt, 'build_instances',
202202
build_inst_kwargs=build_inst_kwargs)
203203

204-
def instance_update_at_top(self, ctxt, instance):
205-
"""Update instance at API level."""
206-
version = '1.35'
207-
if not self.client.can_send_version('1.35'):
208-
instance = objects_base.obj_to_primitive(instance)
209-
version = '1.34'
210-
cctxt = self.client.prepare(version=version)
211-
cctxt.cast(ctxt, 'instance_update_at_top', instance=instance)
212-
213-
def instance_destroy_at_top(self, ctxt, instance):
214-
"""Destroy instance at API level."""
215-
version = '1.35'
216-
if not self.client.can_send_version('1.35'):
217-
instance = objects_base.obj_to_primitive(instance)
218-
version = '1.34'
219-
cctxt = self.client.prepare(version=version)
220-
cctxt.cast(ctxt, 'instance_destroy_at_top', instance=instance)
221-
222204
def instance_delete_everywhere(self, ctxt, instance, delete_type):
223205
"""Delete instance everywhere. delete_type may be 'soft'
224206
or 'hard'. This is generally only used to resolve races

nova/cells/scheduler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def _create_instances_here(self, ctxt, instance_uuids, instance_properties,
112112
self.compute_api._create_block_device_mapping(block_device_mapping)
113113

114114
instances.append(instance)
115-
self.msg_runner.instance_update_at_top(ctxt, instance)
116115
return instances
117116

118117
def _create_action_here(self, ctxt, instance_uuids):
@@ -238,7 +237,6 @@ def _schedule_build_to_cells(self, message, instance_uuids,
238237
for instance_uuid in instance_uuids:
239238
instance = objects.Instance(context=ctxt, uuid=instance_uuid,
240239
vm_state=vm_states.ERROR)
241-
self.msg_runner.instance_update_at_top(ctxt, instance)
242240
try:
243241
instance.vm_state = vm_states.ERROR
244242
instance.save()

nova/compute/cells_api.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,11 @@ def _handle_cell_delete(self, context, instance, method_name):
271271
# that an update came up from a child cell and cell_name is
272272
# set now. If so try the delete again.
273273
with excutils.save_and_reraise_exception() as exc:
274-
try:
275-
instance.refresh()
276-
except exception.InstanceNotFound:
277-
# NOTE(melwitt): If the instance has already been
278-
# deleted by instance_destroy_at_top from a cell,
279-
# instance.refresh() will raise InstanceNotFound.
274+
instance.refresh()
275+
if instance.cell_name:
280276
exc.reraise = False
281-
else:
282-
if instance.cell_name:
283-
exc.reraise = False
284-
self._handle_cell_delete(context, instance,
285-
method_name)
286-
except exception.InstanceNotFound:
287-
# NOTE(melwitt): We can get here if anything tries to
288-
# lookup the instance after an instance_destroy_at_top hits.
289-
pass
277+
self._handle_cell_delete(context, instance,
278+
method_name)
290279
return
291280

292281
method = getattr(super(ComputeCellsAPI, self), method_name)

nova/objects/instance.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,6 @@ def destroy(self, hard_delete=False):
622622
else:
623623
constraint = None
624624

625-
cell_type = cells_opts.get_cell_type()
626-
if cell_type is not None:
627-
stale_instance = self.obj_clone()
628-
629625
try:
630626
db_inst = db.instance_destroy(self._context, self.uuid,
631627
constraint=constraint,
@@ -634,9 +630,6 @@ def destroy(self, hard_delete=False):
634630
except exception.ConstraintNotMet:
635631
raise exception.ObjectActionError(action='destroy',
636632
reason='host changed')
637-
if cell_type == 'compute':
638-
cells_api = cells_rpcapi.CellsAPI()
639-
cells_api.instance_destroy_at_top(self._context, stale_instance)
640633
delattr(self, base.get_attrname('id'))
641634

642635
def _save_info_cache(self, context):
@@ -848,10 +841,6 @@ def _handle_cell_update_from_api():
848841

849842
if cells_update_from_api:
850843
_handle_cell_update_from_api()
851-
elif cell_type == 'compute':
852-
if self._sync_cells:
853-
cells_api = cells_rpcapi.CellsAPI()
854-
cells_api.instance_update_at_top(context, stale_instance)
855844

856845
def _notify():
857846
# NOTE(danms): We have to be super careful here not to trigger

nova/tests/unit/cells/test_cells_manager.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,6 @@ def test_run_compute_api_method(self):
162162
call=True)
163163
self.assertEqual('fake-response', response)
164164

165-
def test_instance_update_at_top(self):
166-
self.mox.StubOutWithMock(self.msg_runner, 'instance_update_at_top')
167-
self.msg_runner.instance_update_at_top(self.ctxt, 'fake-instance')
168-
self.mox.ReplayAll()
169-
self.cells_manager.instance_update_at_top(self.ctxt,
170-
instance='fake-instance')
171-
172-
def test_instance_destroy_at_top(self):
173-
self.mox.StubOutWithMock(self.msg_runner, 'instance_destroy_at_top')
174-
self.msg_runner.instance_destroy_at_top(self.ctxt, 'fake-instance')
175-
self.mox.ReplayAll()
176-
self.cells_manager.instance_destroy_at_top(self.ctxt,
177-
instance='fake-instance')
178-
179165
def test_instance_delete_everywhere(self):
180166
self.mox.StubOutWithMock(self.msg_runner,
181167
'instance_delete_everywhere')

0 commit comments

Comments
 (0)