diff options
-rw-r--r-- | glance_store/_drivers/filesystem.py | 4 | ||||
-rw-r--r-- | glance_store/_drivers/http.py | 2 | ||||
-rw-r--r-- | glance_store/_drivers/rbd.py | 3 | ||||
-rw-r--r-- | glance_store/_drivers/s3.py | 2 | ||||
-rw-r--r-- | glance_store/_drivers/swift/store.py | 2 | ||||
-rw-r--r-- | glance_store/_drivers/vmware_datastore.py | 7 | ||||
-rw-r--r-- | glance_store/backend.py | 3 | ||||
-rw-r--r-- | glance_store/common/utils.py | 2 | ||||
-rw-r--r-- | glance_store/tests/base.py | 3 | ||||
-rw-r--r-- | tests/unit/test_cinder_store.py | 14 |
10 files changed, 23 insertions, 19 deletions
diff --git a/glance_store/_drivers/filesystem.py b/glance_store/_drivers/filesystem.py index 24c3421..e9f849a 100644 --- a/glance_store/_drivers/filesystem.py +++ b/glance_store/_drivers/filesystem.py @@ -256,7 +256,7 @@ class Store(glance_store.driver.Store): :raises: BadStoreConfiguration exception if metadata is not valid. """ try: - with open(metadata_file, 'r') as fptr: + with open(metadata_file, 'rb') as fptr: metadata = jsonutils.load(fptr) if isinstance(metadata, dict): @@ -388,7 +388,7 @@ class Store(glance_store.driver.Store): empty directory path is specified. """ priority = 0 - parts = map(lambda x: x.strip(), datadir.rsplit(":", 1)) + parts = [part.strip() for part in datadir.rsplit(":", 1)] datadir_path = parts[0] if len(parts) == 2 and parts[1]: priority = parts[1] diff --git a/glance_store/_drivers/http.py b/glance_store/_drivers/http.py index a2073de..73946f7 100644 --- a/glance_store/_drivers/http.py +++ b/glance_store/_drivers/http.py @@ -138,7 +138,7 @@ class Store(glance_store.driver.Store): class ResponseIndexable(glance_store.Indexable): def another(self): try: - return self.wrapped.next() + return next(self.wrapped) except StopIteration: return '' diff --git a/glance_store/_drivers/rbd.py b/glance_store/_drivers/rbd.py index 7ff86db..d286487 100644 --- a/glance_store/_drivers/rbd.py +++ b/glance_store/_drivers/rbd.py @@ -25,6 +25,7 @@ import urllib from oslo_config import cfg from oslo_utils import units +import six from glance_store import capabilities from glance_store.common import utils @@ -83,7 +84,7 @@ class StoreLocation(location.StoreLocation): def process_specs(self): # convert to ascii since librbd doesn't handle unicode - for key, value in self.specs.iteritems(): + for key, value in six.iteritems(self.specs): self.specs[key] = str(value) self.fsid = self.specs.get('fsid') self.pool = self.specs.get('pool') diff --git a/glance_store/_drivers/s3.py b/glance_store/_drivers/s3.py index e1d5f3d..5212a9e 100644 --- a/glance_store/_drivers/s3.py +++ b/glance_store/_drivers/s3.py @@ -792,7 +792,7 @@ def get_calling_format(bucket_format=None, def get_mpu_xml(pedict): xml = '<CompleteMultipartUpload>\n' - for pnum, etag in pedict.iteritems(): + for pnum, etag in six.iteritems(pedict): xml += ' <Part>\n' xml += ' <PartNumber>%d</PartNumber>\n' % pnum xml += ' <ETag>%s</ETag>\n' % etag diff --git a/glance_store/_drivers/swift/store.py b/glance_store/_drivers/swift/store.py index 86b8d76..c7f97c0 100644 --- a/glance_store/_drivers/swift/store.py +++ b/glance_store/_drivers/swift/store.py @@ -440,7 +440,7 @@ class BaseStore(driver.Store): class ResponseIndexable(glance_store.Indexable): def another(self): try: - return self.wrapped.next() + return next(self.wrapped) except StopIteration: return '' diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py index 7eff3ff..bbf9037 100644 --- a/glance_store/_drivers/vmware_datastore.py +++ b/glance_store/_drivers/vmware_datastore.py @@ -356,7 +356,7 @@ class Store(glance_store.Store): def _parse_datastore_info_and_weight(self, datastore): weight = 0 - parts = map(lambda x: x.strip(), datastore.rsplit(":", 2)) + parts = [part.strip() for part in datastore.rsplit(":", 2)] if len(parts) < 2: msg = _('vmware_datastores format must be ' 'datacenter_path:datastore_name:weight or ' @@ -490,7 +490,8 @@ class Store(glance_store.Store): 'image_id': image_id}, self.conf) # NOTE(arnaud): use a decorator when the config is not tied to self cookie = self._build_vim_cookie_header(True) - headers = dict(headers.items() + {'Cookie': cookie}.items()) + headers = dict(headers) + headers['Cookie'] = cookie conn_class = self._get_http_conn_class() conn = conn_class(loc.server_host) url = urlparse.quote('%s?%s' % (loc.path, loc.query)) @@ -548,7 +549,7 @@ class Store(glance_store.Store): def another(self): try: - return self.wrapped.next() + return next(self.wrapped) except StopIteration: return '' diff --git a/glance_store/backend.py b/glance_store/backend.py index 916b3d7..df22729 100644 --- a/glance_store/backend.py +++ b/glance_store/backend.py @@ -16,6 +16,7 @@ import logging from oslo_config import cfg +import six from stevedore import driver from stevedore import extension @@ -311,7 +312,7 @@ def check_location_metadata(val, key=''): for v in val: check_location_metadata(v, key='%s[%d]' % (key, ndx)) ndx = ndx + 1 - elif not isinstance(val, unicode): + elif not isinstance(val, six.text_type): raise exceptions.BackendException(_("The image metadata key %(key)s " "has an invalid type of %(type)s. " "Only dict, list, and unicode are " diff --git a/glance_store/common/utils.py b/glance_store/common/utils.py index 48618dc..088cef6 100644 --- a/glance_store/common/utils.py +++ b/glance_store/common/utils.py @@ -133,7 +133,7 @@ class CooperativeReader(object): if self.iterator is None: self.iterator = self.__iter__() try: - return self.iterator.next() + return next(self.iterator) except StopIteration: return '' diff --git a/glance_store/tests/base.py b/glance_store/tests/base.py index 4df57ad..6deba08 100644 --- a/glance_store/tests/base.py +++ b/glance_store/tests/base.py @@ -20,6 +20,7 @@ import shutil import fixtures from oslo_config import cfg from oslotest import base +import six import glance_store as store from glance_store import location @@ -66,7 +67,7 @@ class StoreBaseTest(base.BaseTestCase): test by the fixtures cleanup process. """ group = kw.pop('group', 'glance_store') - for k, v in kw.iteritems(): + for k, v in six.iteritems(kw): self.conf.set_override(k, v, group) def register_store_schemes(self, store, store_entry): diff --git a/tests/unit/test_cinder_store.py b/tests/unit/test_cinder_store.py index c526360..c2b5c15 100644 --- a/tests/unit/test_cinder_store.py +++ b/tests/unit/test_cinder_store.py @@ -14,8 +14,8 @@ # under the License. import mock - from oslo_utils import units +import six import glance_store from glance_store._drivers import cinder @@ -27,7 +27,7 @@ from tests.unit import test_store_capabilities class FakeObject(object): def __init__(self, **kwargs): - for name, value in kwargs.iteritems(): + for name, value in six.iteritems(kwargs): setattr(self, name, value) @@ -52,8 +52,9 @@ class TestCinderStore(base.StoreBaseTest, def test_cinder_get_size(self): fake_client = FakeObject(auth_token=None, management_url=None) - fake_volumes = {'12345678-9012-3455-6789-012345678901': - FakeObject(size=5)} + fake_volume_uuid = '12345678-9012-3455-6789-012345678901' + fake_volume = FakeObject(size=5) + fake_volumes = {fake_volume_uuid: fake_volume} with mock.patch.object(cinder, 'get_cinderclient') as mocked_cc: mocked_cc.return_value = FakeObject(client=fake_client, @@ -68,11 +69,10 @@ class TestCinderStore(base.StoreBaseTest, auth_tok='fake_token', tenant='fake_tenant') - uri = 'cinder://%s' % fake_volumes.keys()[0] + uri = 'cinder://%s' % fake_volume_uuid loc = location.get_location_from_uri(uri, conf=self.conf) image_size = self.store.get_size(loc, context=fake_context) - self.assertEqual(image_size, - fake_volumes.values()[0].size * units.Gi) + self.assertEqual(image_size, fake_volume.size * units.Gi) def test_cinder_delete_raise_error(self): uri = 'cinder://12345678-9012-3455-6789-012345678901' |