Merge "Handle finish and revert resize notifications."

This commit is contained in:
Jenkins 2013-01-07 13:22:08 +00:00 committed by Gerrit Code Review
commit b5e3d5d4cb
2 changed files with 187 additions and 1 deletions

View File

@ -49,6 +49,8 @@ class _Base(plugin.NotificationBase):
return ['compute.instance.create.end',
'compute.instance.exists',
'compute.instance.delete.start',
'compute.instance.finish_resize.end',
'compute.instance.resize.revert.end',
]
@staticmethod

View File

@ -164,6 +164,128 @@ INSTANCE_EXISTS = {
u'timestamp': u'2012-05-08 16:03:44.122481',
}
INSTANCE_FINISH_RESIZE_END = {
u'_context_roles': [u'admin'],
u'_context_request_id': u'req-e3f71bb9-e9b9-418b-a9db-a5950c851b25',
u'_context_quota_class': None,
u'event_type': u'compute.instance.finish_resize.end',
u'_context_user_name': u'admin',
u'_context_project_name': u'admin',
u'timestamp': u'2013-01-04 15:10:17.436974',
u'_context_is_admin': True,
u'message_id': u'a2f7770d-b85d-4797-ab10-41407a44368e',
u'_context_auth_token': None,
u'_context_instance_lock_checked': False,
u'_context_project_id': u'cea4b25edb484e5392727181b7721d29',
u'_context_timestamp': u'2013-01-04T15:08:39.162612',
u'_context_read_deleted': u'no',
u'_context_user_id': u'01b83a5e23f24a6fb6cd073c0aee6eed',
u'_context_remote_address': u'10.147.132.184',
u'publisher_id': u'compute.ip-10-147-132-184.ec2.internal',
u'payload': {u'state_description': u'',
u'availability_zone': None,
u'ephemeral_gb': 0,
u'instance_type_id': 5,
u'deleted_at': u'',
u'fixed_ips': [{u'floating_ips': [],
u'label': u'private',
u'version': 4,
u'meta': {},
u'address': u'10.0.0.3',
u'type': u'fixed'}],
u'memory_mb': 2048,
u'user_id': u'01b83a5e23f24a6fb6cd073c0aee6eed',
u'reservation_id': u'r-u3fvim06',
u'hostname': u's1',
u'state': u'resized',
u'launched_at': u'2013-01-04T15:10:14.923939',
u'metadata': [],
u'ramdisk_id': u'5f23128e-5525-46d8-bc66-9c30cd87141a',
u'access_ip_v6': None,
u'disk_gb': 20,
u'access_ip_v4': None,
u'kernel_id': u'571478e0-d5e7-4c2e-95a5-2bc79443c28a',
u'host': u'ip-10-147-132-184.ec2.internal',
u'display_name': u's1',
u'image_ref_url': u'http://10.147.132.184:9292/images/'
'a130b9d9-e00e-436e-9782-836ccef06e8a',
u'root_gb': 20,
u'tenant_id': u'cea4b25edb484e5392727181b7721d29',
u'created_at': u'2013-01-04T11:21:48.000000',
u'instance_id': u'648e8963-6886-4c3c-98f9-4511c292f86b',
u'instance_type': u'm1.small',
u'vcpus': 1,
u'image_meta': {u'kernel_id':
u'571478e0-d5e7-4c2e-95a5-2bc79443c28a',
u'ramdisk_id':
u'5f23128e-5525-46d8-bc66-9c30cd87141a',
u'base_image_ref':
u'a130b9d9-e00e-436e-9782-836ccef06e8a'
},
u'architecture': None,
u'os_type': None
},
u'priority': u'INFO'
}
INSTANCE_RESIZE_REVERT_END = {
u'_context_roles': [u'admin'],
u'_context_request_id': u'req-9da1d714-dabe-42fd-8baa-583e57cd4f1a',
u'_context_quota_class': None,
u'event_type': u'compute.instance.resize.revert.end',
u'_context_user_name': u'admin',
u'_context_project_name': u'admin',
u'timestamp': u'2013-01-04 15:20:32.009532',
u'_context_is_admin': True,
u'message_id': u'c48deeba-d0c3-4154-b3db-47480b52267a',
u'_context_auth_token': None,
u'_context_instance_lock_checked': False,
u'_context_project_id': u'cea4b25edb484e5392727181b7721d29',
u'_context_timestamp': u'2013-01-04T15:19:51.018218',
u'_context_read_deleted': u'no',
u'_context_user_id': u'01b83a5e23f24a6fb6cd073c0aee6eed',
u'_context_remote_address': u'10.147.132.184',
u'publisher_id': u'compute.ip-10-147-132-184.ec2.internal',
u'payload': {u'state_description': u'resize_reverting',
u'availability_zone': None,
u'ephemeral_gb': 0,
u'instance_type_id': 2,
u'deleted_at': u'',
u'reservation_id': u'r-u3fvim06',
u'memory_mb': 512,
u'user_id': u'01b83a5e23f24a6fb6cd073c0aee6eed',
u'hostname': u's1',
u'state': u'resized',
u'launched_at': u'2013-01-04T15:10:14.000000',
u'metadata': [],
u'ramdisk_id': u'5f23128e-5525-46d8-bc66-9c30cd87141a',
u'access_ip_v6': None,
u'disk_gb': 0,
u'access_ip_v4': None,
u'kernel_id': u'571478e0-d5e7-4c2e-95a5-2bc79443c28a',
u'host': u'ip-10-147-132-184.ec2.internal',
u'display_name': u's1',
u'image_ref_url': u'http://10.147.132.184:9292/images/'
'a130b9d9-e00e-436e-9782-836ccef06e8a',
u'root_gb': 0,
u'tenant_id': u'cea4b25edb484e5392727181b7721d29',
u'created_at': u'2013-01-04T11:21:48.000000',
u'instance_id': u'648e8963-6886-4c3c-98f9-4511c292f86b',
u'instance_type': u'm1.tiny',
u'vcpus': 1,
u'image_meta': {u'kernel_id':
u'571478e0-d5e7-4c2e-95a5-2bc79443c28a',
u'ramdisk_id':
u'5f23128e-5525-46d8-bc66-9c30cd87141a',
u'base_image_ref':
u'a130b9d9-e00e-436e-9782-836ccef06e8a'
},
u'architecture': None,
u'os_type': None
},
u'priority': u'INFO'
}
class TestNotifications(unittest.TestCase):
def test_process_notification(self):
@ -226,7 +348,7 @@ class TestNotifications(unittest.TestCase):
c = counters[0]
self.assertEqual(c.volume, INSTANCE_CREATE_END['payload']['root_gb'])
def test_instance_create_ephemiral_disk_size(self):
def test_instance_create_ephemeral_disk_size(self):
ic = notifications.EphemeralDiskSize()
counters = ic.process_notification(INSTANCE_CREATE_END)
self.assertEqual(len(counters), 1)
@ -253,3 +375,65 @@ class TestNotifications(unittest.TestCase):
ic = notifications.Instance()
counters = ic.process_notification(INSTANCE_DELETE_START)
self.assertEqual(len(counters), 1)
def test_instance_finish_resize_instance(self):
ic = notifications.Instance()
counters = ic.process_notification(INSTANCE_FINISH_RESIZE_END)
self.assertEqual(len(counters), 1)
c = counters[0]
self.assertEqual(c.volume, 1)
def test_instance_finish_resize_flavor(self):
ic = notifications.InstanceFlavor()
counters = ic.process_notification(INSTANCE_FINISH_RESIZE_END)
self.assertEqual(len(counters), 1)
c = counters[0]
self.assertEqual(c.volume, 1)
self.assertEqual(c.name, 'instance:m1.small')
def test_instance_finish_resize_memory(self):
ic = notifications.Memory()
counters = ic.process_notification(INSTANCE_FINISH_RESIZE_END)
self.assertEqual(len(counters), 1)
c = counters[0]
self.assertEqual(c.volume,
INSTANCE_FINISH_RESIZE_END['payload']['memory_mb'])
def test_instance_finish_resize_vcpus(self):
ic = notifications.VCpus()
counters = ic.process_notification(INSTANCE_FINISH_RESIZE_END)
self.assertEqual(len(counters), 1)
c = counters[0]
self.assertEqual(c.volume,
INSTANCE_FINISH_RESIZE_END['payload']['vcpus'])
def test_instance_resize_finish_instance(self):
ic = notifications.Instance()
counters = ic.process_notification(INSTANCE_FINISH_RESIZE_END)
self.assertEqual(len(counters), 1)
c = counters[0]
self.assertEqual(c.volume, 1)
def test_instance_resize_finish_flavor(self):
ic = notifications.InstanceFlavor()
counters = ic.process_notification(INSTANCE_RESIZE_REVERT_END)
self.assertEqual(len(counters), 1)
c = counters[0]
self.assertEqual(c.volume, 1)
self.assertEqual(c.name, 'instance:m1.tiny')
def test_instance_resize_finish_memory(self):
ic = notifications.Memory()
counters = ic.process_notification(INSTANCE_RESIZE_REVERT_END)
self.assertEqual(len(counters), 1)
c = counters[0]
self.assertEqual(c.volume,
INSTANCE_RESIZE_REVERT_END['payload']['memory_mb'])
def test_instance_resize_finish_vcpus(self):
ic = notifications.VCpus()
counters = ic.process_notification(INSTANCE_RESIZE_REVERT_END)
self.assertEqual(len(counters), 1)
c = counters[0]
self.assertEqual(c.volume,
INSTANCE_RESIZE_REVERT_END['payload']['vcpus'])