Add {root,ephemeral}_disk_size counters
Change-Id: Ia4b9a9048df5cfca7cb868ee518297de86c78b71 Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
3228eac892
commit
8034b27272
@ -68,4 +68,24 @@ class InstanceNotifications(plugin.NotificationBase):
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata={}),
|
||||
counter.Counter(source='?',
|
||||
name='root_disk_size',
|
||||
type='absolute',
|
||||
volume=message['payload']['root_gb'],
|
||||
user_id=message['payload']['user_id'],
|
||||
project_id=message['payload']['tenant_id'],
|
||||
resource_id=message['payload']['instance_id'],
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata={}),
|
||||
counter.Counter(source='?',
|
||||
name='ephemeral_disk_size',
|
||||
type='absolute',
|
||||
volume=message['payload']['ephemeral_gb'],
|
||||
user_id=message['payload']['user_id'],
|
||||
project_id=message['payload']['tenant_id'],
|
||||
resource_id=message['payload']['instance_id'],
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata={}),
|
||||
]
|
||||
|
@ -186,36 +186,38 @@ class TestNotifications(unittest.TestCase):
|
||||
]:
|
||||
yield compare, name, actual, expected
|
||||
|
||||
def _check_counters(self, counters):
|
||||
counter_names = [ counter.name for counter in counters ]
|
||||
self.assertEqual(len(counters), 5)
|
||||
self.assert_('instance' in counter_names)
|
||||
self.assert_('memory' in counter_names)
|
||||
self.assert_('vcpus' in counter_names)
|
||||
self.assert_('root_disk_size' in counter_names)
|
||||
self.assert_('ephemeral_disk_size' in counter_names)
|
||||
|
||||
@staticmethod
|
||||
def _find_counter(counters, name):
|
||||
return filter(lambda counter: counter.name == name, counters)[0]
|
||||
|
||||
def test_instance_create(self):
|
||||
ic = notifications.InstanceNotifications()
|
||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||
self._check_counters(counters)
|
||||
|
||||
self.assertEqual(len(counters), 3)
|
||||
|
||||
self.assertEqual(counters[0].name, 'instance')
|
||||
self.assertEqual(counters[0].volume, 1)
|
||||
|
||||
self.assertEqual(counters[1].name, 'memory')
|
||||
self.assertEqual(counters[1].volume, INSTANCE_CREATE_END['payload']['memory_mb'])
|
||||
|
||||
self.assertEqual(counters[2].name, 'vcpus')
|
||||
self.assertEqual(counters[2].volume, INSTANCE_CREATE_END['payload']['vcpus'])
|
||||
|
||||
self.assertEqual(self._find_counter(counters, 'instance').volume, 1)
|
||||
self.assertEqual(self._find_counter(counters, 'memory').volume,
|
||||
INSTANCE_CREATE_END['payload']['memory_mb'])
|
||||
self.assertEqual(self._find_counter(counters, 'vcpus').volume,
|
||||
INSTANCE_CREATE_END['payload']['vcpus'])
|
||||
self.assertEqual(self._find_counter(counters, 'root_disk_size').volume,
|
||||
INSTANCE_CREATE_END['payload']['root_gb'])
|
||||
self.assertEqual(self._find_counter(counters, 'ephemeral_disk_size').volume,
|
||||
INSTANCE_CREATE_END['payload']['ephemeral_gb'])
|
||||
|
||||
def test_instance_exists(self):
|
||||
ic = notifications.InstanceNotifications()
|
||||
counters = ic.process_notification(INSTANCE_EXISTS)
|
||||
self.assertEqual(len(counters), 3)
|
||||
self.assertEqual(counters[0].name, 'instance')
|
||||
self.assertEqual(counters[1].name, 'memory')
|
||||
self.assertEqual(counters[2].name, 'vcpus')
|
||||
|
||||
self._check_counters(ic.process_notification(INSTANCE_EXISTS))
|
||||
|
||||
def test_instance_delete(self):
|
||||
ic = notifications.InstanceNotifications()
|
||||
counters = ic.process_notification(INSTANCE_DELETE_START)
|
||||
self.assertEqual(len(counters), 3)
|
||||
self.assertEqual(counters[0].name, 'instance')
|
||||
self.assertEqual(counters[1].name, 'memory')
|
||||
self.assertEqual(counters[2].name, 'vcpus')
|
||||
self._check_counters(ic.process_notification(INSTANCE_DELETE_START))
|
||||
|
Loading…
Reference in New Issue
Block a user