]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add availability_zone to the volume and snapshot notifications
authorMichael Kerrin <michael.kerrin@hp.com>
Thu, 28 Mar 2013 15:41:10 +0000 (15:41 +0000)
committerMichael Kerrin <michael.kerrin@hp.com>
Tue, 2 Apr 2013 14:58:47 +0000 (14:58 +0000)
Change-Id: I27b6dde68a1618a02c2309f007ead9dd1f04879e

cinder/tests/test_volume.py
cinder/volume/utils.py

index 47a23811560842212236485d7d852c202da9fe6d..64760ecef1ce10e05c0d4d04d7d4c10c1d52c429 100644 (file)
@@ -114,6 +114,38 @@ class VolumeTestCase(test.TestCase):
         self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
         self.volume.create_volume(self.context, volume_id)
         self.assertEquals(len(test_notifier.NOTIFICATIONS), 2)
+        msg = test_notifier.NOTIFICATIONS[0]
+        self.assertEqual(msg['event_type'], 'volume.create.start')
+        expected = {
+            'status': 'creating',
+            'display_name': None,
+            'availability_zone': 'nova',
+            'tenant_id': 'fake',
+            'created_at': 'DONTCARE',
+            'volume_id': volume_id,
+            'volume_type': None,
+            'snapshot_id': None,
+            'user_id': 'fake',
+            'launched_at': '',
+            'size': 0,
+        }
+        self.assertDictMatch(msg['payload'], expected)
+        msg = test_notifier.NOTIFICATIONS[1]
+        self.assertEqual(msg['event_type'], 'volume.create.end')
+        expected = {
+            'status': 'creating',
+            'display_name': None,
+            'availability_zone': 'nova',
+            'tenant_id': 'fake',
+            'created_at': 'DONTCARE',
+            'volume_id': volume_id,
+            'volume_type': None,
+            'snapshot_id': None,
+            'user_id': 'fake',
+            'launched_at': '',
+            'size': 0,
+        }
+        self.assertDictMatch(msg['payload'], expected)
         self.assertEqual(volume_id, db.volume_get(context.get_admin_context(),
                          volume_id).id)
 
@@ -122,6 +154,38 @@ class VolumeTestCase(test.TestCase):
                             volume_id)
         self.assertEquals(vol['status'], 'deleted')
         self.assertEquals(len(test_notifier.NOTIFICATIONS), 4)
+        msg = test_notifier.NOTIFICATIONS[2]
+        self.assertEqual(msg['event_type'], 'volume.delete.start')
+        expected = {
+            'status': 'available',
+            'display_name': None,
+            'availability_zone': 'nova',
+            'tenant_id': 'fake',
+            'created_at': 'DONTCARE',
+            'volume_id': volume_id,
+            'volume_type': None,
+            'snapshot_id': None,
+            'user_id': 'fake',
+            'launched_at': 'DONTCARE',
+            'size': 0,
+        }
+        self.assertDictMatch(msg['payload'], expected)
+        msg = test_notifier.NOTIFICATIONS[3]
+        self.assertEqual(msg['event_type'], 'volume.delete.end')
+        expected = {
+            'status': 'available',
+            'display_name': None,
+            'availability_zone': 'nova',
+            'tenant_id': 'fake',
+            'created_at': 'DONTCARE',
+            'volume_id': volume_id,
+            'volume_type': None,
+            'snapshot_id': None,
+            'user_id': 'fake',
+            'launched_at': 'DONTCARE',
+            'size': 0,
+        }
+        self.assertDictMatch(msg['payload'], expected)
         self.assertRaises(exception.NotFound,
                           db.volume_get,
                           self.context,
@@ -383,7 +447,8 @@ class VolumeTestCase(test.TestCase):
             'tenant_id': 'fake',
             'user_id': 'fake',
             'volume_id': volume['id'],
-            'volume_size': 0
+            'volume_size': 0,
+            'availability_zone': 'nova'
         }
         self.assertDictMatch(msg['payload'], expected)
         msg = test_notifier.NOTIFICATIONS[3]
@@ -397,7 +462,8 @@ class VolumeTestCase(test.TestCase):
             'tenant_id': 'fake',
             'user_id': 'fake',
             'volume_id': volume['id'],
-            'volume_size': 0
+            'volume_size': 0,
+            'availability_zone': 'nova'
         }
         self.assertDictMatch(msg['payload'], expected)
 
@@ -414,7 +480,8 @@ class VolumeTestCase(test.TestCase):
             'tenant_id': 'fake',
             'user_id': 'fake',
             'volume_id': volume['id'],
-            'volume_size': 0
+            'volume_size': 0,
+            'availability_zone': 'nova'
         }
         self.assertDictMatch(msg['payload'], expected)
         msg = test_notifier.NOTIFICATIONS[5]
@@ -428,7 +495,8 @@ class VolumeTestCase(test.TestCase):
             'tenant_id': 'fake',
             'user_id': 'fake',
             'volume_id': volume['id'],
-            'volume_size': 0
+            'volume_size': 0,
+            'availability_zone': 'nova'
         }
         self.assertDictMatch(msg['payload'], expected)
 
@@ -872,30 +940,6 @@ class VolumeTestCase(test.TestCase):
                           'name',
                           'description')
 
-    def test_create_volume_usage_notification(self):
-        """Ensure create volume generates appropriate usage notification"""
-        volume = self._create_volume()
-        volume_id = volume['id']
-        self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
-        self.volume.create_volume(self.context, volume_id)
-        self.assertEquals(len(test_notifier.NOTIFICATIONS), 2)
-        msg = test_notifier.NOTIFICATIONS[0]
-        self.assertEquals(msg['event_type'], 'volume.create.start')
-        msg = test_notifier.NOTIFICATIONS[1]
-        self.assertEquals(msg['priority'], 'INFO')
-        self.assertEquals(msg['event_type'], 'volume.create.end')
-        payload = msg['payload']
-        self.assertEquals(payload['tenant_id'], volume['project_id'])
-        self.assertEquals(payload['user_id'], volume['user_id'])
-        self.assertEquals(payload['volume_id'], volume['id'])
-        self.assertEquals(payload['status'], 'creating')
-        self.assertEquals(payload['size'], volume['size'])
-        self.assertTrue('display_name' in payload)
-        self.assertTrue('snapshot_id' in payload)
-        self.assertTrue('launched_at' in payload)
-        self.assertTrue('created_at' in payload)
-        self.volume.delete_volume(self.context, volume_id)
-
     def test_begin_roll_detaching_volume(self):
         """Test begin_detaching and roll_detaching functions."""
         volume = self._create_volume()
index b7f7b35468311f52eb3beb6f2a6d9aba5e5a40a9..43e9e3dbbd87124484f57b7f874c3003f5628028 100644 (file)
@@ -61,6 +61,7 @@ def null_safe_str(s):
 def _usage_from_volume(context, volume_ref, **kw):
     usage_info = dict(tenant_id=volume_ref['project_id'],
                       user_id=volume_ref['user_id'],
+                      availability_zone=volume_ref['availability_zone'],
                       volume_id=volume_ref['id'],
                       volume_type=volume_ref['volume_type_id'],
                       display_name=volume_ref['display_name'],
@@ -93,6 +94,7 @@ def _usage_from_snapshot(context, snapshot_ref, **extra_usage_info):
     usage_info = {
         'tenant_id': snapshot_ref['project_id'],
         'user_id': snapshot_ref['user_id'],
+        'availability_zone': snapshot_ref.volume['availability_zone'],
         'volume_id': snapshot_ref['volume_id'],
         'volume_size': snapshot_ref['volume_size'],
         'snapshot_id': snapshot_ref['id'],