Merge "add tags field to instance.update notification"
This commit is contained in:
@@ -67,11 +67,12 @@
|
||||
"nova_object.version": "1.3",
|
||||
"nova_object.namespace": "nova"
|
||||
},
|
||||
"tags": [],
|
||||
"user_id": "fake",
|
||||
"uuid": "c03c0bf9-f46e-4e4f-93f1-817568567ee2"},
|
||||
"nova_object.name": "InstanceUpdatePayload",
|
||||
"nova_object.namespace": "nova",
|
||||
"nova_object.version": "1.1"},
|
||||
"nova_object.version": "1.2"},
|
||||
"priority": "INFO",
|
||||
"publisher_id": "nova-compute:fake-mini"
|
||||
}
|
||||
|
||||
@@ -148,22 +148,27 @@ class InstanceActionVolumeSwapPayload(InstanceActionPayload):
|
||||
class InstanceUpdatePayload(InstancePayload):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: locked and display_description added to InstancePayload
|
||||
VERSION = '1.1'
|
||||
# Version 1.2: Added tags field
|
||||
VERSION = '1.2'
|
||||
fields = {
|
||||
'state_update': fields.ObjectField('InstanceStateUpdatePayload'),
|
||||
'audit_period': fields.ObjectField('AuditPeriodPayload'),
|
||||
'bandwidth': fields.ListOfObjectsField('BandwidthPayload'),
|
||||
'old_display_name': fields.StringField(nullable=True)
|
||||
'old_display_name': fields.StringField(nullable=True),
|
||||
'tags': fields.ListOfStringsField(),
|
||||
}
|
||||
|
||||
def __init__(self, instance, state_update, audit_period, bandwidth,
|
||||
old_display_name):
|
||||
tags = [instance_tag.tag for instance_tag in instance.tags.objects]
|
||||
|
||||
super(InstanceUpdatePayload, self).__init__(
|
||||
instance=instance,
|
||||
state_update=state_update,
|
||||
audit_period=audit_period,
|
||||
bandwidth=bandwidth,
|
||||
old_display_name=old_display_name)
|
||||
old_display_name=old_display_name,
|
||||
tags=tags)
|
||||
|
||||
|
||||
@nova_base.NovaObjectRegistry.register_notification
|
||||
|
||||
@@ -186,6 +186,9 @@ class NotificationSampleTestBase(test.TestCase,
|
||||
found_server = self._wait_for_state_change(self.api, created_server,
|
||||
expected_status)
|
||||
found_server['reservation_id'] = reservation_id
|
||||
|
||||
if found_server['status'] == 'ACTIVE':
|
||||
self.api.put_server_tags(found_server['id'], ['tag1'])
|
||||
return found_server
|
||||
|
||||
def _wait_until_deleted(self, server):
|
||||
|
||||
@@ -267,7 +267,8 @@ class TestInstanceNotificationSample(
|
||||
{'network_name': 'private-network',
|
||||
'out_bytes': 0,
|
||||
'in_bytes': 0},
|
||||
'nova_object.version': '1.0'}]
|
||||
'nova_object.version': '1.0'}],
|
||||
'tags': ["tag1"]
|
||||
},
|
||||
|
||||
# deleting -> deleted
|
||||
@@ -280,7 +281,9 @@ class TestInstanceNotificationSample(
|
||||
'terminated_at': '2012-10-29T13:42:11Z',
|
||||
'ip_addresses': [],
|
||||
'power_state': 'pending',
|
||||
'bandwidth': []},
|
||||
'bandwidth': [],
|
||||
'tags': ["tag1"]
|
||||
},
|
||||
]
|
||||
|
||||
self._verify_instance_update_steps(delete_steps, instance_updates,
|
||||
|
||||
@@ -364,7 +364,7 @@ notification_object_data = {
|
||||
'InstancePayload': '1.1-5b9e3a4bb805d9fed20063bc237e4913',
|
||||
'InstanceStateUpdatePayload': '1.0-07e111c0fa0f6db0f79b0726d593e3da',
|
||||
'InstanceUpdateNotification': '1.0-a73147b93b520ff0061865849d3dfa56',
|
||||
'InstanceUpdatePayload': '1.1-12955de638c3a4bcd734601711214d39',
|
||||
'InstanceUpdatePayload': '1.2-67174f00c1ed9b5a6c408a31bd2540a5',
|
||||
'IpPayload': '1.0-8ecf567a99e516d4af094439a7632d34',
|
||||
'NotificationPublisher': '1.0-bbbc1402fb0e443a3eb227cc52b61545',
|
||||
'ServiceStatusNotification': '1.0-a73147b93b520ff0061865849d3dfa56',
|
||||
@@ -457,6 +457,8 @@ class TestInstanceNotification(test.NoDBTestCase):
|
||||
@mock.patch('nova.notifications.objects.instance.'
|
||||
'InstanceUpdateNotification._emit')
|
||||
def test_send_version_instance_update_uses_flavor(self, mock_emit):
|
||||
# instance.update notification needs some tags value to avoid lazy-load
|
||||
self.instance.tags = objects.TagList()
|
||||
# Make sure that the notification payload chooses the values in
|
||||
# instance.flavor.$value instead of instance.$value
|
||||
notification_base._send_versioned_instance_update(
|
||||
|
||||
@@ -520,6 +520,16 @@ class NotificationsTestCase(test.TestCase):
|
||||
self.assertEqual(payload["old_display_name"], old_display_name)
|
||||
self.assertEqual(payload["display_name"], new_display_name)
|
||||
|
||||
def test_send_versioned_tags_update(self):
|
||||
objects.TagList.create(self.context,
|
||||
self.instance.uuid, ['tag1', 'tag2'])
|
||||
notifications.send_update(self.context, self.instance, self.instance)
|
||||
self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))
|
||||
|
||||
self.assertEqual(['tag1', 'tag2'],
|
||||
fake_notifier.VERSIONED_NOTIFICATIONS[0]
|
||||
['payload']['nova_object.data']['tags'])
|
||||
|
||||
def test_send_no_state_change(self):
|
||||
called = [False]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user