diff options
| author | Rick Harris <rconradharris@gmail.com> | 2012-05-03 22:30:32 +0000 |
|---|---|---|
| committer | Brian Elliott <brian.elliott@rackspace.com> | 2012-08-31 16:09:33 +0000 |
| commit | 04e6ad112f541df68b06c17f141be916e5e8bdb2 (patch) | |
| tree | 77fec07b44b60475b1e7f8c2d923f53522f5d4be | |
| parent | a9e84dd614a26f093594a9ccec10740bd3ecd9e6 (diff) | |
| download | nova-04e6ad112f541df68b06c17f141be916e5e8bdb2.tar.gz nova-04e6ad112f541df68b06c17f141be916e5e8bdb2.tar.xz nova-04e6ad112f541df68b06c17f141be916e5e8bdb2.zip | |
Save the original base image ref for snapshots.
Save the base image ref in instance system metadata for tracking
purposes.
(This is modified code originally from Rick Harris.)
Change-Id: I574c597c7ff2e55675ebdaa7b3213b53e61a94b7
| -rw-r--r-- | nova/compute/api.py | 17 | ||||
| -rw-r--r-- | nova/tests/compute/test_compute.py | 10 |
2 files changed, 24 insertions, 3 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index dcc6a7f06..9f99e00dc 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -688,6 +688,16 @@ class API(base.Base): new_value = str(value)[:255] instance['system_metadata']['image_%s' % key] = new_value + # Keep a record of the original base image that this + # image's instance is derived from: + base_image_ref = image['properties'].get('base_image_ref') + if not base_image_ref: + # base image ref property not previously set through a snapshot. + # default to using the image ref as the base: + base_image_ref = base_options['image_ref'] + + instance['system_metadata']['image_base_image_ref'] = base_image_ref + # Use 'default' security_group if none specified. if security_groups is None: security_groups = ['default'] @@ -1173,6 +1183,13 @@ class API(base.Base): 'image_type': image_type, } + # Persist base image ref as a Glance image property + system_meta = self.db.instance_system_metadata_get( + context, instance_uuid) + base_image_ref = system_meta.get('image_base_image_ref') + if base_image_ref: + properties['base_image_ref'] = base_image_ref + sent_meta = {'name': name, 'is_public': False} if image_type == 'backup': diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 822c23e03..403d56f58 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -2508,10 +2508,14 @@ class ComputeAPITestCase(BaseTestCase): try: sys_metadata = db.instance_system_metadata_get(self.context, ref[0]['uuid']) - self.assertEqual(sys_metadata, - {'image_kernel_id': 'fake_kernel_id', + + image_props = {'image_kernel_id': 'fake_kernel_id', 'image_ramdisk_id': 'fake_ramdisk_id', - 'image_something_else': 'meow', }) + 'image_something_else': 'meow', } + for key, value in image_props.iteritems(): + self.assertTrue(key in sys_metadata) + self.assertEqual(value, sys_metadata[key]) + finally: db.instance_destroy(self.context, ref[0]['uuid']) |
