Skip to content

Commit

Permalink
Pull system_metadata for notifications on instance.save()
Browse files Browse the repository at this point in the history
When saving changes on an instance object a notification is sent out.
An attempt is made to pull flavor information from the instance but if
system_metadata is not joined then an exception is raised and the
notification fails.  This ensures that system_metadata is available for
those notifications.

Conflicts:

	nova/objects/base.py

The conflict is from change Icd2944f17b6100d51007dbc48da90e4e992bbd48

Change-Id: Ifd317f847c3839cd6019038bb3dc856b9f107000
Closes-bug: 1244311
(cherry picked from commit e03963b)
  • Loading branch information
Andrew Laski authored and Matt Riedemann committed Nov 1, 2013
1 parent 3cdfe89 commit e360dc2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions nova/objects/base.py
Expand Up @@ -140,6 +140,7 @@ def wrapper(self, *args, **kwargs):
for key, value in updates.iteritems():
if key in self.fields:
self[key] = self._attr_from_primitive(key, value)
self.obj_reset_changes()
self._changed_fields = set(updates.get('obj_what_changed', []))
return result
else:
Expand Down
5 changes: 5 additions & 0 deletions nova/objects/instance.py
Expand Up @@ -443,6 +443,11 @@ def _handle_cell_update_from_api():

expected_attrs = [attr for attr in _INSTANCE_OPTIONAL_JOINED_FIELDS
if self.obj_attr_is_set(attr)]
# NOTE(alaski): We need to pull system_metadata for the
# notification.send_update() below. If we don't there's a KeyError
# when it tries to extract the flavor.
if 'system_metadata' not in expected_attrs:
expected_attrs.append('system_metadata')
old_ref, inst_ref = db.instance_update_and_get_original(
context, self.uuid, updates, update_cells=False,
columns_to_join=_expected_cols(expected_attrs))
Expand Down
8 changes: 4 additions & 4 deletions nova/tests/compute/test_compute.py
Expand Up @@ -2071,7 +2071,7 @@ def _test_reboot(self, soft,
db.instance_update_and_get_original(econtext, instance['uuid'],
{'power_state': fake_power_state1},
update_cells=False,
columns_to_join=[],
columns_to_join=['system_metadata']
).AndReturn((None,
updated_dbinstance1))

Expand Down Expand Up @@ -2117,7 +2117,7 @@ def fake_reboot(*args, **kwargs):
'task_state': None,
'vm_state': vm_states.ACTIVE},
update_cells=False,
columns_to_join=[],
columns_to_join=['system_metadata'],
).AndRaise(exception.InstanceNotFound(
instance_id=instance['uuid']))
self.compute._notify_about_instance_usage(
Expand All @@ -2129,7 +2129,7 @@ def fake_reboot(*args, **kwargs):
econtext, updated_dbinstance1['uuid'],
{'vm_state': vm_states.ERROR},
update_cells=False,
columns_to_join=[],
columns_to_join=['system_metadata'],
).AndRaise(exception.InstanceNotFound(
instance_id=instance['uuid']))
else:
Expand All @@ -2139,7 +2139,7 @@ def fake_reboot(*args, **kwargs):
'task_state': None,
'vm_state': vm_states.ACTIVE},
update_cells=False,
columns_to_join=[],
columns_to_join=['system_metadata'],
).AndReturn((None, updated_dbinstance2))
self.compute._notify_about_instance_usage(
econtext,
Expand Down
6 changes: 4 additions & 2 deletions nova/tests/objects/test_instance.py
Expand Up @@ -254,7 +254,8 @@ def _save_test_helper(self, cell_type, save_kwargs):
db.instance_update_and_get_original(
self.context, fake_uuid, expected_updates,
update_cells=False,
columns_to_join=['info_cache', 'security_groups']
columns_to_join=['info_cache', 'security_groups',
'system_metadata']
).AndReturn((old_ref, new_ref))
if cell_type == 'api':
cells_rpcapi.CellsAPI().AndReturn(cells_api_mock)
Expand Down Expand Up @@ -324,7 +325,8 @@ def test_save_rename_sends_notification(self):
).AndReturn(old_ref)
db.instance_update_and_get_original(
self.context, fake_uuid, expected_updates, update_cells=False,
columns_to_join=['info_cache', 'security_groups']
columns_to_join=['info_cache', 'security_groups',
'system_metadata']
).AndReturn((old_ref, new_ref))
notifications.send_update(self.context, mox.IgnoreArg(),
mox.IgnoreArg())
Expand Down

0 comments on commit e360dc2

Please sign in to comment.