diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-03-12 18:36:54 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-03-12 18:36:54 +0000 |
| commit | 5810e2062d0df0485ba0774a927ae6dfd5da2d4e (patch) | |
| tree | 7686baf13eb386408d74155d18e9404f667787ca /nova/virt | |
| parent | 39a8abf3572cdf5e7233f41f638d0111540eaa90 (diff) | |
| parent | ad53f91e623f05cfe994101d56d6d2cf54cd8412 (diff) | |
Merge "Don't use glance when verifying images."
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/libvirt/imagecache.py | 87 |
1 files changed, 34 insertions, 53 deletions
diff --git a/nova/virt/libvirt/imagecache.py b/nova/virt/libvirt/imagecache.py index 22a4d1e8b..8b01c27c5 100644 --- a/nova/virt/libvirt/imagecache.py +++ b/nova/virt/libvirt/imagecache.py @@ -34,7 +34,6 @@ from nova import compute from nova import context as db_context from nova import db from nova import flags -from nova import image from nova import log as logging from nova.openstack.common import cfg from nova import utils @@ -220,7 +219,7 @@ class ImageCacheManager(object): if m: yield img, False, True - def _verify_checksum(self, img, base_file): + def _verify_checksum(self, img_id, base_file): """Compare the checksum stored on disk with the current file. Note that if the checksum fails to verify this is logged, but no actual @@ -235,11 +234,9 @@ class ImageCacheManager(object): f.close() if current_checksum != stored_checksum: - LOG.error(_('%(container_format)s-%(id)s ' - '(%(base_file)s): ' - 'image verification failed'), - {'container_format': img['container_format'], - 'id': img['id'], + LOG.error(_('%(id)s (%(base_file)s): image verification ' + 'failed'), + {'id': img_id, 'base_file': base_file}) return False @@ -247,10 +244,9 @@ class ImageCacheManager(object): return True else: - LOG.debug(_('%(container_format)s-%(id)s (%(base_file)s): ' - 'image verification skipped, no hash stored'), - {'container_format': img['container_format'], - 'id': img['id'], + LOG.debug(_('%(id)s (%(base_file)s): image verification skipped, ' + 'no hash stored'), + {'id': img_id, 'base_file': base_file}) # NOTE(mikal): If the checksum file is missing, then we should @@ -294,15 +290,14 @@ class ImageCacheManager(object): {'base_file': base_file, 'error': e}) - def _handle_base_image(self, img, base_file): + def _handle_base_image(self, img_id, base_file): """Handle the checks for a single base image.""" image_bad = False image_in_use = False - LOG.info(_('%(container_format)s-%(id)s (%(base_file)s): checking'), - {'container_format': img['container_format'], - 'id': img['id'], + LOG.info(_('%(id)s (%(base_file)s): checking'), + {'id': img_id, 'base_file': base_file}) if base_file in self.unexplained_images: @@ -311,17 +306,16 @@ class ImageCacheManager(object): if (base_file and os.path.exists(base_file) and os.path.isfile(base_file)): # _verify_checksum returns True if the checksum is ok. - image_bad = not self._verify_checksum(img, base_file) + image_bad = not self._verify_checksum(img_id, base_file) instances = [] - if str(img['id']) in self.used_images: - local, remote, instances = self.used_images[str(img['id'])] + if img_id in self.used_images: + local, remote, instances = self.used_images[img_id] if local > 0: - LOG.debug(_('%(container_format)s-%(id)s (%(base_file)s): ' + LOG.debug(_('%(id)s (%(base_file)s): ' 'in use: on this node %(local)d local, ' '%(remote)d on other nodes'), - {'container_format': img['container_format'], - 'id': img['id'], + {'id': img_id, 'base_file': base_file, 'local': local, 'remote': remote}) @@ -330,21 +324,17 @@ class ImageCacheManager(object): self.active_base_files.append(base_file) if not base_file: - LOG.warning(_('%(container_format)s-%(id)s ' - '(%(base_file)s): warning -- an absent ' - 'base file is in use! instances: ' + LOG.warning(_('%(id)s (%(base_file)s): warning -- an ' + 'absent base file is in use! instances: ' '%(instance_list)s'), - {'container_format': - img['container_format'], - 'id': img['id'], + {'id': img_id, 'base_file': base_file, 'instance_list': ' '.join(instances)}) else: - LOG.debug(_('%(container_format)s-%(id)s (%(base_file)s): ' - 'in use on (%(remote)d on other nodes)'), - {'container_format': img['container_format'], - 'id': img['id'], + LOG.debug(_('%(id)s (%(base_file)s): in use on (%(remote)d on ' + 'other nodes)'), + {'id': img_id, 'base_file': base_file, 'remote': remote}) if image_bad: @@ -352,24 +342,18 @@ class ImageCacheManager(object): if base_file: if not image_in_use: - LOG.debug(_('%(container_format)s-%(id)s (%(base_file)s): ' - 'image is not in use'), - {'container_format': img['container_format'], - 'id': img['id'], + LOG.debug(_('%(id)s (%(base_file)s): image is not in use'), + {'id': img_id, 'base_file': base_file}) self.removable_base_files.append(base_file) else: - LOG.debug(_('%(container_format)s-%(id)s (%(base_file)s): ' - 'image is in use'), - {'container_format': img['container_format'], - 'id': img['id'], + LOG.debug(_('%(id)s (%(base_file)s): image is in use'), + {'id': img_id, 'base_file': base_file}) def verify_base_images(self, context): """Verify that base images are in a reasonable state.""" - # TODO(mikal): Write a unit test for this method - # TODO(mikal): Handle "generated" images # NOTE(mikal): The new scheme for base images is as follows -- an # image is streamed from the image service to _base (filename is the @@ -392,14 +376,12 @@ class ImageCacheManager(object): self._list_base_images(base_dir) self._list_running_instances(context) - # Determine what images are in glance. GlanceImageService.detail uses - # _fetch_images which handles pagination for us - image_service = image.get_default_image_service() - for img in image_service.detail(context): - if img['container_format'] != 'ami': - continue - - fingerprint = hashlib.sha1(str(img['id'])).hexdigest() + # Determine what images are on disk because they're in use + for img in self.used_images: + fingerprint = hashlib.sha1(img).hexdigest() + LOG.debug(_('Image id %(id)s yields fingerprint %(fingerprint)s'), + {'id': img, + 'fingerprint': fingerprint}) for result in self._find_base_file(base_dir, fingerprint): base_file, image_small, image_resized = result self._handle_base_image(img, base_file) @@ -407,12 +389,11 @@ class ImageCacheManager(object): if not image_small and not image_resized: self.originals.append(base_file) - # Elements remaining in unexplained_images are not directly from - # glance. That might mean they're from a image that was removed from - # glance, but it might also mean that they're a resized image. + # Elements remaining in unexplained_images might be in use inuse_backing_images = self._list_backing_images() for backing_path in inuse_backing_images: - self.active_base_files.append(backing_path) + if not backing_path in self.active_base_files: + self.active_base_files.append(backing_path) # Anything left is an unknown base image for img in self.unexplained_images: |
