diff options
| author | Michael Still <mikal@stillhq.com> | 2012-05-11 14:54:34 +1000 |
|---|---|---|
| committer | Michael Still <mikal@stillhq.com> | 2012-05-11 14:54:54 +1000 |
| commit | 2549018c81ad6fcc67a3dc89dec18d2310ce2235 (patch) | |
| tree | 0930c0aaf368388be7734feaa1c50a9e337bbc4a | |
| parent | bf6673a5952ed59ed55d504938d195083e23a2ce (diff) | |
Provide a transition to new .info files.
Change-Id: I2fb6ef93c0652a797dba72cf75fb78baaa9c9c5a
| -rw-r--r-- | nova/tests/test_imagecache.py | 17 | ||||
| -rw-r--r-- | nova/virt/libvirt/utils.py | 14 |
2 files changed, 30 insertions, 1 deletions
diff --git a/nova/tests/test_imagecache.py b/nova/tests/test_imagecache.py index 79d561001..2f611cb59 100644 --- a/nova/tests/test_imagecache.py +++ b/nova/tests/test_imagecache.py @@ -71,6 +71,23 @@ class ImageCacheManagerTestCase(test.TestCase): self.assertEquals(csum_input.rstrip(), '{"sha1": "%s"}' % csum_output) + def test_read_stored_checksum_legacy_essex(self): + with utils.tempdir() as tmpdir: + self.flags(instances_path=tmpdir) + self.flags(image_info_filename_pattern=('$instances_path/' + '%(image)s.info')) + + fname = os.path.join(tmpdir, 'aaa') + old_fname = fname + '.sha1' + f = open(old_fname, 'w') + f.write('fdghkfhkgjjksfdgjksjkghsdf') + f.close() + + csum_output = imagecache.read_stored_checksum(fname) + self.assertEquals(csum_output, 'fdghkfhkgjjksfdgjksjkghsdf') + self.assertFalse(os.path.exists(old_fname)) + self.assertTrue(os.path.exists(virtutils.get_info_filename(fname))) + def test_list_base_images(self): listing = ['00000001', 'ephemeral_0_20_None', diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index f4c6d20a5..cfc47b202 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -342,7 +342,19 @@ def read_stored_info(base_path, field=None): info_file = get_info_filename(base_path) if not os.path.exists(info_file): - d = {} + # Special case to handle essex checksums being converted + old_filename = base_path + '.sha1' + if field == 'sha1' and os.path.exists(old_filename): + hash_file = open(old_filename) + hash_value = hash_file.read() + hash_file.close() + + write_stored_info(base_path, field=field, value=hash_value) + os.remove(old_filename) + d = {field: hash_value} + + else: + d = {} else: LOG.info(_('Reading image info file: %s'), info_file) |
