From 6d984c3097252f9f97ef10e48be390fdf756b391 Mon Sep 17 00:00:00 2001 From: Ken Pepple Date: Tue, 15 Mar 2011 16:08:22 -0700 Subject: wrap errors getting image ids from local image store --- nova/image/local.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'nova/image') diff --git a/nova/image/local.py b/nova/image/local.py index c4ac3baaa..ef92a35b5 100644 --- a/nova/image/local.py +++ b/nova/image/local.py @@ -20,8 +20,9 @@ import os.path import random import shutil -from nova import flags from nova import exception +from nova import flags +from nova import log as logging from nova.image import service @@ -29,6 +30,8 @@ FLAGS = flags.FLAGS flags.DEFINE_string('images_path', '$state_path/images', 'path to decrypted images') +LOG = logging.getLogger('nova.image.local') + class LocalImageService(service.BaseImageService): """Image service storing images to local disk. @@ -47,7 +50,14 @@ class LocalImageService(service.BaseImageService): def _ids(self): """The list of all image ids.""" - return [int(i, 16) for i in os.listdir(self._path)] + images = [] + for i in os.listdir(self._path): + try: + images.append(int(i, 16)) + except: + LOG.debug( + _("%s is not in correct directory naming format" % i)) + return images def index(self, context): return [dict(image_id=i['id'], name=i.get('name')) -- cgit From 60c7ce60826becb1ebe7f75a0a0d28b2893d70c0 Mon Sep 17 00:00:00 2001 From: Ken Pepple Date: Tue, 15 Mar 2011 18:54:51 -0700 Subject: revised per code review --- nova/image/local.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'nova/image') diff --git a/nova/image/local.py b/nova/image/local.py index ef92a35b5..c304a2212 100644 --- a/nova/image/local.py +++ b/nova/image/local.py @@ -51,12 +51,15 @@ class LocalImageService(service.BaseImageService): def _ids(self): """The list of all image ids.""" images = [] - for i in os.listdir(self._path): + for image_dir in os.listdir(self._path): try: - images.append(int(i, 16)) + images.append(int(image_dir, 16)) + except ValueError: + LOG.error( + _("%s is not in correct directory naming format"\ + % image_dir)) except: - LOG.debug( - _("%s is not in correct directory naming format" % i)) + raise return images def index(self, context): -- cgit From 6d6d0f686a7f8d47263b7ed725bdae0f322b2a4e Mon Sep 17 00:00:00 2001 From: Ken Pepple Date: Thu, 17 Mar 2011 11:34:14 -0700 Subject: better implementation of try..except..else --- nova/image/local.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nova/image') diff --git a/nova/image/local.py b/nova/image/local.py index c304a2212..609d6c42a 100644 --- a/nova/image/local.py +++ b/nova/image/local.py @@ -53,13 +53,13 @@ class LocalImageService(service.BaseImageService): images = [] for image_dir in os.listdir(self._path): try: - images.append(int(image_dir, 16)) + unhexed_image_id = int(image_dir, 16) except ValueError: LOG.error( _("%s is not in correct directory naming format"\ % image_dir)) - except: - raise + else: + images.append(unhexed_image_id) return images def index(self, context): -- cgit