diff options
-rw-r--r-- | glance_store/_drivers/cinder.py | 2 | ||||
-rw-r--r-- | glance_store/_drivers/filesystem.py | 6 | ||||
-rw-r--r-- | glance_store/_drivers/gridfs.py | 4 | ||||
-rw-r--r-- | glance_store/_drivers/rbd.py | 2 | ||||
-rw-r--r-- | glance_store/_drivers/s3.py | 6 | ||||
-rw-r--r-- | glance_store/_drivers/sheepdog.py | 8 | ||||
-rw-r--r-- | glance_store/_drivers/vmware_datastore.py | 75 | ||||
-rw-r--r-- | glance_store/backend.py | 19 | ||||
-rw-r--r-- | glance_store/common/config.py | 2 | ||||
-rw-r--r-- | glance_store/common/utils.py | 2 | ||||
-rw-r--r-- | glance_store/exceptions.py | 5 | ||||
-rw-r--r-- | glance_store/tests/base.py | 2 | ||||
-rw-r--r-- | glance_store/tests/utils.py | 1 | ||||
-rw-r--r-- | requirements.txt | 10 | ||||
-rw-r--r-- | tests/unit/test_filesystem_store.py | 2 | ||||
-rw-r--r-- | tests/unit/test_s3_store.py | 2 | ||||
-rw-r--r-- | tests/unit/test_sheepdog_store.py | 2 | ||||
-rw-r--r-- | tests/unit/test_swift_store.py | 4 | ||||
-rw-r--r-- | tests/unit/test_vmware_store.py | 54 |
19 files changed, 66 insertions, 142 deletions
diff --git a/glance_store/_drivers/cinder.py b/glance_store/_drivers/cinder.py index a2b4a15..856f100 100644 --- a/glance_store/_drivers/cinder.py +++ b/glance_store/_drivers/cinder.py @@ -17,7 +17,7 @@ import logging from cinderclient import exceptions as cinder_exception from cinderclient import service_catalog from cinderclient.v2 import client as cinderclient -from oslo.config import cfg +from oslo_config import cfg from glance_store.common import utils import glance_store.driver diff --git a/glance_store/_drivers/filesystem.py b/glance_store/_drivers/filesystem.py index f84be13..42f59ff 100644 --- a/glance_store/_drivers/filesystem.py +++ b/glance_store/_drivers/filesystem.py @@ -25,10 +25,10 @@ import os import stat import urlparse -from oslo.config import cfg from oslo.serialization import jsonutils -from oslo.utils import excutils -from oslo.utils import units +from oslo_config import cfg +from oslo_utils import excutils +from oslo_utils import units import glance_store from glance_store.common import utils diff --git a/glance_store/_drivers/gridfs.py b/glance_store/_drivers/gridfs.py index 10754ba..7fdb6b1 100644 --- a/glance_store/_drivers/gridfs.py +++ b/glance_store/_drivers/gridfs.py @@ -19,8 +19,8 @@ from __future__ import absolute_import import logging import urlparse -from oslo.config import cfg -from oslo.utils import excutils +from oslo_config import cfg +from oslo_utils import excutils import glance_store.driver from glance_store import exceptions diff --git a/glance_store/_drivers/rbd.py b/glance_store/_drivers/rbd.py index 7daa4e0..6a45320 100644 --- a/glance_store/_drivers/rbd.py +++ b/glance_store/_drivers/rbd.py @@ -23,7 +23,7 @@ import logging import math import urllib -from oslo.config import cfg +from oslo_config import cfg from glance_store.common import utils from glance_store import driver diff --git a/glance_store/_drivers/s3.py b/glance_store/_drivers/s3.py index ae7c3c6..0e3589e 100644 --- a/glance_store/_drivers/s3.py +++ b/glance_store/_drivers/s3.py @@ -25,9 +25,9 @@ import urlparse import boto.exception import eventlet -from oslo.config import cfg -from oslo.utils import netutils -from oslo.utils import units +from oslo_config import cfg +from oslo_utils import netutils +from oslo_utils import units import six import glance_store diff --git a/glance_store/_drivers/sheepdog.py b/glance_store/_drivers/sheepdog.py index a40acb7..2b772db 100644 --- a/glance_store/_drivers/sheepdog.py +++ b/glance_store/_drivers/sheepdog.py @@ -18,10 +18,10 @@ import hashlib import logging -from oslo.concurrency import processutils -from oslo.config import cfg -from oslo.utils import excutils -from oslo.utils import units +from oslo_concurrency import processutils +from oslo_config import cfg +from oslo_utils import excutils +from oslo_utils import units import glance_store import glance_store.driver diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py index ad2e375..0e1b649 100644 --- a/glance_store/_drivers/vmware_datastore.py +++ b/glance_store/_drivers/vmware_datastore.py @@ -21,10 +21,11 @@ import logging import os import socket -from oslo.config import cfg -from oslo.utils import excutils -from oslo.utils import units from oslo.vmware import api +from oslo.vmware import constants +from oslo_config import cfg +from oslo_utils import excutils +from oslo_utils import units import six.moves.urllib.parse as urlparse import glance_store @@ -38,7 +39,6 @@ LOG = logging.getLogger(__name__) MAX_REDIRECTS = 5 DEFAULT_STORE_IMAGE_DIR = '/openstack_glance' -DEFAULT_ESX_DATACENTER_PATH = 'ha-datacenter' DS_URL_PREFIX = '/folder' STORE_SCHEME = 'vsphere' @@ -57,7 +57,7 @@ _VMWARE_OPTS = [ 'VMware ESX/VC server.'), secret=True), cfg.StrOpt('vmware_datacenter_path', - default=DEFAULT_ESX_DATACENTER_PATH, + default=constants.ESX_DATACENTER_PATH, help=_('Inventory path to a datacenter. ' 'If the vmware_server_host specified is an ESX/ESXi, ' 'the vmware_datacenter_path is optional. If specified, ' @@ -119,15 +119,6 @@ class _Reader(object): self.checksum.update(result) return result - def rewind(self): - try: - self.data.seek(0) - self._size = 0 - self.checksum = hashlib.md5() - except IOError: - with excutils.save_and_reraise_exception(): - LOG.exception(_LE('Failed to rewind image content')) - @property def size(self): return self._size @@ -341,36 +332,32 @@ class Store(glance_store.Store): 'datastore_name': self.datastore_name, 'image_id': image_id}, self.conf) # NOTE(arnaud): use a decorator when the config is not tied to self - for i in range(self.api_retry_count + 1): - cookie = self._build_vim_cookie_header( - self.session.vim.client.options.transport.cookiejar) - headers = dict(headers.items() + {'Cookie': cookie}.items()) - try: - conn = self._get_http_conn('PUT', loc, headers, - content=image_file) - res = conn.getresponse() - except Exception: - with excutils.save_and_reraise_exception(): - LOG.exception(_LE('Failed to upload content of image ' - '%(image)s'), {'image': image_id}) - - if res.status == httplib.UNAUTHORIZED: - self.reset_session(force=True) - image_file.rewind() - continue - - if res.status == httplib.CONFLICT: - raise exceptions.Duplicate(_("Image file %(image_id)s already " - "exists!") % - {'image_id': image_id}) - - if res.status not in (httplib.CREATED, httplib.OK): - msg = (_LE('Failed to upload content of image %(image)s') % - {'image': image_id}) - LOG.error(msg) - raise exceptions.UnexpectedStatus(status=res.status, - body=res.read()) - break + cookie = self._build_vim_cookie_header( + self.session.vim.client.options.transport.cookiejar) + headers = dict(headers.items() + {'Cookie': cookie}.items()) + try: + conn = self._get_http_conn('PUT', loc, headers, + content=image_file) + res = conn.getresponse() + except Exception: + with excutils.save_and_reraise_exception(): + LOG.exception(_LE('Failed to upload content of image ' + '%(image)s'), {'image': image_id}) + + if res.status == httplib.CONFLICT: + raise exceptions.Duplicate(_("Image file %(image_id)s already " + "exists!") % + {'image_id': image_id}) + + if res.status not in (httplib.CREATED, httplib.OK): + msg = (_LE('Failed to upload content of image %(image)s. ' + 'The request returned an unexpected status: %(status)s.' + '\nThe response body:\n%(body)s') % + {'image': image_id, + 'status': res.status, + 'body': res.body}) + LOG.error(msg) + raise exceptions.BackendException(msg) return (loc.get_uri(), image_file.size, image_file.checksum.hexdigest(), {}) diff --git a/glance_store/backend.py b/glance_store/backend.py index 8cb315b..1f543ec 100644 --- a/glance_store/backend.py +++ b/glance_store/backend.py @@ -30,20 +30,13 @@ LOG = logging.getLogger(__name__) _ = i18n._ -_DEPRECATED_STORE_OPTS = [ - cfg.DeprecatedOpt('known_stores', group='DEFAULT'), - cfg.DeprecatedOpt('default_store', group='DEFAULT') -] - _STORE_OPTS = [ cfg.ListOpt('stores', default=['file', 'http'], - help=_('List of stores enabled'), - deprecated_opts=[_DEPRECATED_STORE_OPTS[0]]), + help=_('List of stores enabled')), cfg.StrOpt('default_store', default='file', help=_("Default scheme to use to store image data. The " "scheme must be registered by one of the stores " - "defined by the 'stores' config option."), - deprecated_opts=[_DEPRECATED_STORE_OPTS[1]]) + "defined by the 'stores' config option.")) ] _STORE_CFG_GROUP = 'glance_store' @@ -59,13 +52,7 @@ def _list_opts(): driver_cls = _load_store(None, store_entry, False) if driver_cls and driver_cls not in handled_drivers: if getattr(driver_cls, 'OPTIONS', None) is not None: - # NOTE(flaper87): To be removed in k-2. This should - # give deployers enough time to migrate their systems - # and move configs under the new section. - for opt in driver_cls.OPTIONS: - opt.deprecated_opts = [cfg.DeprecatedOpt(opt.name, - group='DEFAULT')] - driver_opts.append(opt) + driver_opts += driver_cls.OPTIONS handled_drivers.append(driver_cls) # NOTE(zhiyan): This separated approach could list diff --git a/glance_store/common/config.py b/glance_store/common/config.py index 7ec3824..cda9ac0 100644 --- a/glance_store/common/config.py +++ b/glance_store/common/config.py @@ -22,7 +22,7 @@ import logging.config import logging.handlers import os -from oslo.config import cfg +from oslo_config import cfg from paste import deploy from glance.version import version_info as version diff --git a/glance_store/common/utils.py b/glance_store/common/utils.py index 6c0a2d4..48618dc 100644 --- a/glance_store/common/utils.py +++ b/glance_store/common/utils.py @@ -25,7 +25,7 @@ try: from eventlet import sleep except ImportError: from time import sleep -from oslo.utils import encodeutils +from oslo_utils import encodeutils import six diff --git a/glance_store/exceptions.py b/glance_store/exceptions.py index 87ac242..b41df97 100644 --- a/glance_store/exceptions.py +++ b/glance_store/exceptions.py @@ -88,11 +88,6 @@ class StorageFull(GlanceStoreException): message = _("There is not enough disk space on the image storage media.") -class StorageQuotaFull(GlanceStoreException): - message = _("The size of the data %(image_size)s will exceed the limit. " - "%(remaining)s bytes remaining.") - - class StorageWriteDenied(GlanceStoreException): message = _("Permission to write image storage media denied.") diff --git a/glance_store/tests/base.py b/glance_store/tests/base.py index 867efe9..0f07e35 100644 --- a/glance_store/tests/base.py +++ b/glance_store/tests/base.py @@ -18,7 +18,7 @@ import os import shutil import fixtures -from oslo.config import cfg +from oslo_config import cfg from oslotest import base import glance_store as store diff --git a/glance_store/tests/utils.py b/glance_store/tests/utils.py index 33c4712..b301822 100644 --- a/glance_store/tests/utils.py +++ b/glance_store/tests/utils.py @@ -41,6 +41,7 @@ class FakeHTTPResponse(object): self.read = self.data.read self.status = status self.headers = headers or {'content-length': len(data)} + self.body = None def getheader(self, name, default=None): return self.headers.get(name.lower(), default) diff --git a/requirements.txt b/requirements.txt index 381c84b..c8cb91c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,13 @@ -oslo.config>=1.2.0 +oslo.config>=1.6.0 # Apache-2.0 oslo.i18n>=0.1.0 oslo.serialization>=1.0.0 # Apache-2.0 -oslo.utils>=1.0.0 # Apache-2.0 -oslo.concurrency>=0.1.0 # Apache-2.0 +oslo.utils>=1.2.0 # Apache-2.0 +oslo.concurrency>=1.4.1 # Apache-2.0 stevedore>=0.12 python-cinderclient>=1.0.6 -# Required by openstack.common libraries -eventlet>=0.13.0 -iso8601>=0.1.8 +eventlet>=0.13.0 #s3 six>=1.4.1 # py2.6 compat diff --git a/tests/unit/test_filesystem_store.py b/tests/unit/test_filesystem_store.py index 0da59cf..ee979de 100644 --- a/tests/unit/test_filesystem_store.py +++ b/tests/unit/test_filesystem_store.py @@ -26,7 +26,7 @@ import StringIO import uuid import fixtures -from oslo.utils import units +from oslo_utils import units import six from glance_store._drivers.filesystem import ChunkedFile diff --git a/tests/unit/test_s3_store.py b/tests/unit/test_s3_store.py index 5078f86..27ec952 100644 --- a/tests/unit/test_s3_store.py +++ b/tests/unit/test_s3_store.py @@ -22,7 +22,7 @@ import xml.etree.ElementTree import boto.s3.connection import mock -from oslo.utils import units +from oslo_utils import units from glance_store._drivers import s3 from glance_store import exceptions diff --git a/tests/unit/test_sheepdog_store.py b/tests/unit/test_sheepdog_store.py index 91307cd..04ac568 100644 --- a/tests/unit/test_sheepdog_store.py +++ b/tests/unit/test_sheepdog_store.py @@ -16,7 +16,7 @@ import StringIO import mock -from oslo.concurrency import processutils +from oslo_concurrency import processutils from glance_store._drivers import sheepdog from glance_store.tests import base diff --git a/tests/unit/test_swift_store.py b/tests/unit/test_swift_store.py index 957a570..992236d 100644 --- a/tests/unit/test_swift_store.py +++ b/tests/unit/test_swift_store.py @@ -24,8 +24,8 @@ import tempfile import uuid import httpretty -from oslo.config import cfg -from oslo.utils import units +from oslo_config import cfg +from oslo_utils import units from oslotest import moxstubout import six import StringIO diff --git a/tests/unit/test_vmware_store.py b/tests/unit/test_vmware_store.py index d11a54d..685dd30 100644 --- a/tests/unit/test_vmware_store.py +++ b/tests/unit/test_vmware_store.py @@ -19,8 +19,8 @@ import hashlib import uuid import mock -from oslo.utils import units from oslo.vmware import api +from oslo_utils import units import six import glance_store._drivers.vmware_datastore as vm_store @@ -245,22 +245,6 @@ class TestStore(base.StoreBaseTest): self.assertEqual(expected_checksum, reader.checksum.hexdigest()) self.assertEqual(1, reader.size) - def test_rewind(self): - content = 'XXX' - image = six.StringIO(content) - expected_checksum = hashlib.md5(content).hexdigest() - reader = vm_store._Reader(image) - reader.read(1) - ret = reader.read() - self.assertEqual('XX', ret) - self.assertEqual(expected_checksum, reader.checksum.hexdigest()) - self.assertEqual(len(content), reader.size) - reader.rewind() - ret = reader.read() - self.assertEqual(content, ret) - self.assertEqual(expected_checksum, reader.checksum.hexdigest()) - self.assertEqual(len(content), reader.size) - def test_chunkreader_image_fits_in_blocksize(self): """ Test that the image file reader returns the expected chunk of data @@ -345,7 +329,7 @@ class TestStore(base.StoreBaseTest): self.fail() @mock.patch.object(api, 'VMwareAPISession') - def test_retry_count(self, mock_api_session): + def test_unexpected_status(self, mock_api_session): expected_image_id = str(uuid.uuid4()) expected_size = FIVE_KB expected_contents = "*" * expected_size @@ -353,37 +337,9 @@ class TestStore(base.StoreBaseTest): self.session = mock.Mock() with mock.patch('httplib.HTTPConnection') as HttpConn: HttpConn.return_value = FakeHTTPConnection(status=401) - try: - self.store.add(expected_image_id, image, expected_size) - except exceptions.NotAuthenticated: - pass - self.assertEqual( - self.store.conf.glance_store.vmware_api_retry_count + 1, - mock_api_session.call_count) - - @mock.patch.object(api, 'VMwareAPISession') - def test_session_reused(self, mock_api_session): - expected_image_id = str(uuid.uuid4()) - expected_size = FIVE_KB - expected_contents = "*" * expected_size - hash_code = hashlib.md5(expected_contents) - loc = location.get_location_from_uri( - "vsphere://127.0.0.1/folder/openstack_glance/%s?" - "dsName=ds1&dcPath=dc1" % FAKE_UUID, conf=self.conf) - with mock.patch('hashlib.md5') as md5: - md5.return_value = hash_code - image = six.StringIO(expected_contents) - with mock.patch('httplib.HTTPConnection') as HttpConn: - HttpConn.return_value = FakeHTTPConnection() - self.store.add(expected_image_id, image, expected_size) - HttpConn.return_value = FakeHTTPConnection(status=401) - self.store.add(expected_image_id, image, expected_size) - HttpConn.return_value = FakeHTTPConnection() - self.store.add(expected_image_id, image, expected_size) - self.store.delete(loc) - self.assertEqual( - self.store.conf.glance_store.vmware_api_retry_count + 1, - mock_api_session.call_count) + self.assertRaises(exceptions.BackendException, + self.store.add, + expected_image_id, image, expected_size) @mock.patch.object(api, 'VMwareAPISession') def test_reset_session(self, mock_api_session): |