From c521ba7fa679b6e9c790d84ea22f04fb999987db Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 12 Jul 2016 11:17:32 -0700 Subject: [PATCH] Make notifications module use flavor capacity attributes This makes the notifications module use instance.flavor.$resource instead of instance.$resource. Change-Id: Ic31589aea0a2948179f6b3fb9cb759da4e2a2e78 --- nova/notifications/base.py | 10 +++++----- nova/tests/unit/test_notifications.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/nova/notifications/base.py b/nova/notifications/base.py index 34800a958843..d22b98604982 100644 --- a/nova/notifications/base.py +++ b/nova/notifications/base.py @@ -444,14 +444,14 @@ def info_from_instance(context, instance, network_info, architecture=instance.architecture, # Capacity properties - memory_mb=instance.memory_mb, - disk_gb=instance.root_gb + instance.ephemeral_gb, - vcpus=instance.vcpus, + memory_mb=instance.flavor.memory_mb, + disk_gb=instance.flavor.root_gb + instance.flavor.ephemeral_gb, + vcpus=instance.flavor.vcpus, # Note(dhellmann): This makes the disk_gb value redundant, but # we are keeping it for backwards-compatibility with existing # users of notifications. - root_gb=instance.root_gb, - ephemeral_gb=instance.ephemeral_gb, + root_gb=instance.flavor.root_gb, + ephemeral_gb=instance.flavor.ephemeral_gb, # Location properties host=instance.host, diff --git a/nova/tests/unit/test_notifications.py b/nova/tests/unit/test_notifications.py index a99fc25dfb33..ac6a6b52fcac 100644 --- a/nova/tests/unit/test_notifications.py +++ b/nova/tests/unit/test_notifications.py @@ -470,6 +470,24 @@ class NotificationsTestCase(test.TestCase): self.assertIn("progress", info) self.assertEqual(50, info["progress"]) + def test_payload_has_flavor_attributes(self): + # Zero these to make sure they are not used + self.instance.vcpus = self.instance.memory_mb = 0 + self.instance.root_gb = self.instance.ephemeral_gb = 0 + + # Set flavor values and make sure _these_ are present in the output + self.instance.flavor.vcpus = 10 + self.instance.flavor.root_gb = 20 + self.instance.flavor.memory_mb = 30 + self.instance.flavor.ephemeral_gb = 40 + info = notifications.info_from_instance(self.context, self.instance, + self.net_info, None) + self.assertEqual(10, info['vcpus']) + self.assertEqual(20, info['root_gb']) + self.assertEqual(30, info['memory_mb']) + self.assertEqual(40, info['ephemeral_gb']) + self.assertEqual(60, info['disk_gb']) + def test_send_access_ip_update(self): notifications.send_update(self.context, self.instance, self.instance) self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))