diff options
| author | Ken Pepple <ken.pepple@gmail.com> | 2011-03-15 16:08:22 -0700 |
|---|---|---|
| committer | Ken Pepple <ken.pepple@gmail.com> | 2011-03-15 16:08:22 -0700 |
| commit | 6d984c3097252f9f97ef10e48be390fdf756b391 (patch) | |
| tree | ae05a288224c2908855340710b7576559abe279e | |
| parent | d36b4d5f3797521b1c2d13a0d30fe98a0671768e (diff) | |
wrap errors getting image ids from local image store
| -rw-r--r-- | nova/image/local.py | 14 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_images.py | 7 |
2 files changed, 19 insertions, 2 deletions
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')) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 76f758929..2c4918117 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -151,6 +151,13 @@ class LocalImageServiceTest(test.TestCase, self.stubs.UnsetAll() super(LocalImageServiceTest, self).tearDown() + def test_get_all_ids_with_incorrect_directory_formats(self): + # create some old-style image directories (starting with 'ami-') + for x in [1, 2, 3]: + tempfile.mkstemp(prefix='ami-', dir=self.tempdir) + found_images = self.service._ids() + self.assertEqual(True, isinstance(found_images, list)) + class GlanceImageServiceTest(test.TestCase, BaseImageServiceTests): |
