summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-05-11 16:28:31 +0000
committerGerrit Code Review <review@openstack.org>2012-05-11 16:28:31 +0000
commit15e774deb83c039bf6d07386fa5ce6b76e12e034 (patch)
tree05381efff4a82b58982818ad8080f9af206115cd
parent8374ba0f03f5038be2868da988f5d06468a68544 (diff)
parent2549018c81ad6fcc67a3dc89dec18d2310ce2235 (diff)
Merge "Provide a transition to new .info files."
-rw-r--r--nova/tests/test_imagecache.py17
-rw-r--r--nova/virt/libvirt/utils.py14
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)