Port store image to Python 3
* StoreLocations: add a __eq__() method, Python 3 doesn't use __cmp__() anymore * Fix StoreLocations.__delitem__(): Python 3 now calls it with a slice for "del locations[a:b]" instead of calling __delslice__(). * Fix test_store_location: mark byte strinsg with b'...' prefix. * tox.ini: add test_store_location to Python 3.4 Change-Id: Ibe8dac3d442ee08ae6b347e256947b6b9c5224ae
This commit is contained in:
parent
25319368cc
commit
476688080c
@ -233,31 +233,38 @@ class StoreLocations(collections.MutableSequence):
|
||||
[location])
|
||||
|
||||
def __delitem__(self, i):
|
||||
if isinstance(i, slice):
|
||||
if i.step not in (None, 1):
|
||||
raise NotImplementedError("slice with step")
|
||||
self.__delslice__(i.start, i.stop)
|
||||
return
|
||||
location = None
|
||||
try:
|
||||
location = self.value.__getitem__(i)
|
||||
location = self.value[i]
|
||||
except Exception:
|
||||
return self.value.__delitem__(i)
|
||||
del self.value[i]
|
||||
return
|
||||
self.image_proxy.store_utils.delete_image_location_from_backend(
|
||||
self.image_proxy.context,
|
||||
self.image_proxy.image.image_id,
|
||||
location)
|
||||
self.value.__delitem__(i)
|
||||
del self.value[i]
|
||||
|
||||
def __delslice__(self, i, j):
|
||||
i = max(i, 0)
|
||||
j = max(j, 0)
|
||||
locations = []
|
||||
try:
|
||||
locations = self.value.__getslice__(i, j)
|
||||
locations = self.value[i:j]
|
||||
except Exception:
|
||||
return self.value.__delslice__(i, j)
|
||||
del self.value[i:j]
|
||||
return
|
||||
for location in locations:
|
||||
self.image_proxy.store_utils.delete_image_location_from_backend(
|
||||
self.image_proxy.context,
|
||||
self.image_proxy.image.image_id,
|
||||
location)
|
||||
self.value.__delitem__(i)
|
||||
del self.value[i]
|
||||
|
||||
def __iadd__(self, other):
|
||||
self.extend(other)
|
||||
@ -278,6 +285,9 @@ class StoreLocations(collections.MutableSequence):
|
||||
def __cmp__(self, other):
|
||||
return cmp(self.value, self.__cast(other))
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.value == self.__cast(other)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.value)
|
||||
|
||||
|
@ -226,7 +226,7 @@ class TestStoreImage(utils.BaseTestCase):
|
||||
# in Location proxy layer. Complete test rule for
|
||||
# 'store.check_location_metadata()' testing please
|
||||
# check below cases within 'TestStoreMetaDataChecker'.
|
||||
location_bad = {'url': UUID3, 'metadata': "a invalid metadata"}
|
||||
location_bad = {'url': UUID3, 'metadata': b"a invalid metadata"}
|
||||
|
||||
self.assertRaises(glance_store.BackendException,
|
||||
image1.locations.append, location_bad)
|
||||
@ -315,7 +315,7 @@ class TestStoreImage(utils.BaseTestCase):
|
||||
(image1, image_stub1) = self._add_image(context, UUID2, 'XXXX', 4)
|
||||
(image2, image_stub2) = self._add_image(context, UUID3, 'YYYY', 4)
|
||||
|
||||
location_bad = {'url': UUID3, 'metadata': "a invalid metadata"}
|
||||
location_bad = {'url': UUID3, 'metadata': b"a invalid metadata"}
|
||||
|
||||
self.assertRaises(glance_store.BackendException,
|
||||
image1.locations.extend, [location_bad])
|
||||
@ -417,7 +417,7 @@ class TestStoreImage(utils.BaseTestCase):
|
||||
(image1, image_stub1) = self._add_image(context, UUID2, 'XXXX', 4)
|
||||
(image2, image_stub2) = self._add_image(context, UUID3, 'YYYY', 4)
|
||||
|
||||
location_bad = {'url': UUID3, 'metadata': "a invalid metadata"}
|
||||
location_bad = {'url': UUID3, 'metadata': b"a invalid metadata"}
|
||||
|
||||
self.assertRaises(glance_store.BackendException,
|
||||
image1.locations.insert, 0, location_bad)
|
||||
@ -511,7 +511,7 @@ class TestStoreImage(utils.BaseTestCase):
|
||||
image2 = glance.location.ImageProxy(image_stub2, context,
|
||||
self.store_api, self.store_utils)
|
||||
|
||||
location_bad = {'url': UUID2, 'metadata': "a invalid metadata"}
|
||||
location_bad = {'url': UUID2, 'metadata': b"a invalid metadata"}
|
||||
|
||||
self.assertRaises(glance_store.BackendException,
|
||||
image2.locations.__iadd__, [location_bad])
|
||||
@ -921,7 +921,7 @@ class TestStoreAddToBackend(utils.BaseTestCase):
|
||||
self._good_metadata(m)
|
||||
|
||||
def test_bad_top_level_nonunicode(self):
|
||||
metadata = {'key': 'a string'}
|
||||
metadata = {'key': b'a string'}
|
||||
self._bad_metadata(metadata)
|
||||
|
||||
def test_bad_nonunicode_dict_list(self):
|
||||
|
1
tox.ini
1
tox.ini
@ -50,6 +50,7 @@ commands =
|
||||
glance.tests.unit.test_schema \
|
||||
glance.tests.unit.test_scrubber \
|
||||
glance.tests.unit.test_store_artifact \
|
||||
glance.tests.unit.test_store_image \
|
||||
glance.tests.unit.test_store_location \
|
||||
glance.tests.unit.test_versions
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user