From 652c8ca285b93fb3306d5c7825f916111e41b645 Mon Sep 17 00:00:00 2001 From: Jay Lau Date: Fri, 25 Apr 2014 16:03:40 +0800 Subject: [PATCH] Payload meta_data is empty when remove metadata When update metadata for a host aggregation, all of the values will be in the variable of "updates", if remove metadata, the format would be {"foo": None, "bar": None}; If adding metadata, the format would be {"foo": "foo1", "bar": "bar1"}. The current logic of update_metadata() is as following: 1) Get all metadata from variable "updates". 2) Traverse updates to see which values are new added and which needs to be removed. For the new added values, put the metadata to variable "to_add"; for the values which need to be removed, just remove them from metadata. 3) Set the values of variable "to_add" as payload metadata. The above logic will make the values which was removed from metadata cannot be in payload, this caused the third party receiver cannot know which metadata was removed. The fix was always using the values from variable "updates" as the metadata for payload as it include values removed and new added. Change-Id: I7b78795e325f52cfb9c24eabd9ef42990666c02d Closes-Bug: #1269684 --- nova/objects/aggregate.py | 1 - nova/tests/objects/test_aggregate.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/nova/objects/aggregate.py b/nova/objects/aggregate.py index 6e75a20dd..c5cabc44b 100644 --- a/nova/objects/aggregate.py +++ b/nova/objects/aggregate.py @@ -119,7 +119,6 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject): to_add[key] = value self.metadata[key] = value db.aggregate_metadata_add(context, self.id, to_add) - payload['meta_data'] = to_add compute_utils.notify_about_aggregate_update(context, "updatemetadata.end", payload) diff --git a/nova/tests/objects/test_aggregate.py b/nova/tests/objects/test_aggregate.py index c27fadb84..ca665474a 100644 --- a/nova/tests/objects/test_aggregate.py +++ b/nova/tests/objects/test_aggregate.py @@ -16,6 +16,7 @@ from nova import db from nova import exception from nova.objects import aggregate from nova.openstack.common import timeutils +from nova.tests import fake_notifier from nova.tests.objects import test_objects @@ -91,12 +92,22 @@ class _TestAggregateObject(object): db.aggregate_metadata_delete(self.context, 123, 'todelete') db.aggregate_metadata_add(self.context, 123, {'toadd': 'myval'}) self.mox.ReplayAll() + fake_notifier.NOTIFICATIONS = [] agg = aggregate.Aggregate() agg._context = self.context agg.id = 123 agg.metadata = {'foo': 'bar'} agg.obj_reset_changes() agg.update_metadata({'todelete': None, 'toadd': 'myval'}) + self.assertEqual(2, len(fake_notifier.NOTIFICATIONS)) + msg = fake_notifier.NOTIFICATIONS[0] + self.assertEqual('aggregate.updatemetadata.start', msg.event_type) + self.assertEqual({'todelete': None, 'toadd': 'myval'}, + msg.payload['meta_data']) + msg = fake_notifier.NOTIFICATIONS[1] + self.assertEqual('aggregate.updatemetadata.end', msg.event_type) + self.assertEqual({'todelete': None, 'toadd': 'myval'}, + msg.payload['meta_data']) self.assertEqual({'foo': 'bar', 'toadd': 'myval'}, agg.metadata) def test_destroy(self):