Store image properties with instance system_metadata
In implementing adding 'image_meta' to instance notifications, this was committed: https://review.openstack.org/#/c/7309 commit 53adfd289bf7226f1c6f59c17608e42f3083f130 However, it's buggy because an instance could have been deleted after we built from it... and bin/instance-usage-audit uses an admin context with which we cannot query glance. This stores image properties with instances in nova as system_metadata and notifications will use that data. Fixes bug 997833 Change-Id: I50575969b5cb28adaae9a713e749dc486772c417
This commit is contained in:
@@ -116,7 +116,9 @@ class BaseTestCase(test.TestCase):
|
||||
|
||||
def fake_show(meh, context, id):
|
||||
return {'id': 1, 'min_disk': None, 'min_ram': None,
|
||||
'properties': {'kernel_id': 1, 'ramdisk_id': 1}}
|
||||
'properties': {'kernel_id': 'fake_kernel_id',
|
||||
'ramdisk_id': 'fake_ramdisk_id',
|
||||
'something_else': 'meow'}}
|
||||
|
||||
self.stubs.Set(fake_image._FakeImageService, 'show', fake_show)
|
||||
self.stubs.Set(rpc, 'call', rpc_call_wrapper)
|
||||
@@ -1815,7 +1817,8 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
self.compute_api = compute.API()
|
||||
self.fake_image = {
|
||||
'id': 1,
|
||||
'properties': {'kernel_id': 1, 'ramdisk_id': 1},
|
||||
'properties': {'kernel_id': 'fake_kernel_id',
|
||||
'ramdisk_id': 'fake_ramdisk_id'},
|
||||
}
|
||||
|
||||
def _run_instance(self):
|
||||
@@ -1913,6 +1916,22 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
finally:
|
||||
db.instance_destroy(self.context, ref[0]['id'])
|
||||
|
||||
def test_create_instance_sets_system_metadata(self):
|
||||
"""Make sure image properties are copied into system metadata."""
|
||||
(ref, resv_id) = self.compute_api.create(
|
||||
self.context,
|
||||
instance_type=instance_types.get_default_instance_type(),
|
||||
image_href=None)
|
||||
try:
|
||||
sys_metadata = db.instance_system_metadata_get(self.context,
|
||||
ref[0]['uuid'])
|
||||
self.assertEqual(sys_metadata,
|
||||
{'image_kernel_id': 'fake_kernel_id',
|
||||
'image_ramdisk_id': 'fake_ramdisk_id',
|
||||
'image_something_else': 'meow'})
|
||||
finally:
|
||||
db.instance_destroy(self.context, ref[0]['id'])
|
||||
|
||||
def test_create_instance_associates_security_groups(self):
|
||||
"""Make sure create associates security groups"""
|
||||
group = self._create_group()
|
||||
|
||||
@@ -83,6 +83,12 @@ class UsageInfoTestCase(test.TestCase):
|
||||
"""Ensure 'exists' notification generates appropriate usage data."""
|
||||
instance_id = self._create_instance()
|
||||
instance = db.instance_get(self.context, instance_id)
|
||||
# Set some system metadata
|
||||
sys_metadata = {'image_md_key1': 'val1',
|
||||
'image_md_key2': 'val2',
|
||||
'other_data': 'meow'}
|
||||
db.instance_system_metadata_update(self.context, instance['uuid'],
|
||||
sys_metadata, False)
|
||||
compute_utils.notify_usage_exists(self.context, instance)
|
||||
self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
|
||||
msg = test_notifier.NOTIFICATIONS[0]
|
||||
@@ -101,7 +107,8 @@ class UsageInfoTestCase(test.TestCase):
|
||||
'audit_period_ending', 'image_meta'):
|
||||
self.assertTrue(attr in payload,
|
||||
msg="Key %s not in payload" % attr)
|
||||
self.assertEquals(payload['image_meta']['id'], 1)
|
||||
self.assertEquals(payload['image_meta'],
|
||||
{'md_key1': 'val1', 'md_key2': 'val2'})
|
||||
image_ref_url = "%s/images/1" % utils.generate_glance_url()
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
self.compute.terminate_instance(self.context, instance['uuid'])
|
||||
|
||||
Reference in New Issue
Block a user