From b62a7ba55eb6effe35e81841c064df3a03092e3d Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Fri, 8 Nov 2013 05:13:40 -0500 Subject: [PATCH] Fix compatibilities issues with recent swift devel Server does not set x-trans-id anymore swift.common includes a more generic FileLikeIter object --- swsync/containers.py | 6 +++++- swsync/objects.py | 12 ++++++++---- tests/units/test_objects.py | 9 +++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/swsync/containers.py b/swsync/containers.py index 659ef11..e9103e4 100644 --- a/swsync/containers.py +++ b/swsync/containers.py @@ -96,7 +96,11 @@ class Containers(object): container_headers = orig_container_headers.copy() for h in ('x-container-object-count', 'x-trans-id', 'x-container-bytes-used'): - del container_headers[h] + try: + del container_headers[h] + except KeyError: + # Nov2013: swift server does not set x-trans-id header + pass p = dest_storage_cnx[0] url = "%s://%s%s" % (p.scheme, p.netloc, p.path) try: diff --git a/swsync/objects.py b/swsync/objects.py index 60bcfe1..ae95682 100644 --- a/swsync/objects.py +++ b/swsync/objects.py @@ -19,7 +19,12 @@ import logging import eventlet import swift.common.bufferedhttp import swift.common.http -import swift.container.sync +try: + from swift.container.sync import _Iter2FileLikeObject as FileLikeIter +except ImportError: + # Nov2013: swift.common.utils now include a more generic object + from swift.common.utils import FileLikeIter + from swiftclient import client as swiftclient import urllib import urllib2 @@ -93,7 +98,7 @@ def delete_object(dest_cnx, http_conn=dest_cnx, name=object_name) - +import swift.common.utils def sync_object(orig_storage_url, orig_token, dest_storage_url, dest_token, container_name, object_name_etag): object_name = object_name_etag[1] @@ -107,11 +112,10 @@ def sync_object(orig_storage_url, orig_token, dest_storage_url, post_headers = orig_headers post_headers['x-auth-token'] = dest_token sync_to = dest_storage_url + "/" + container_name - iterlike = swift.container.sync._Iter2FileLikeObject try: swiftclient.put_object(sync_to, name=object_name, headers=post_headers, - contents=iterlike(orig_body)) + contents=FileLikeIter(orig_body)) except(swiftclient.ClientException), e: logging.info("error sync object: %s, %s" % ( object_name, e.http_reason)) diff --git a/tests/units/test_objects.py b/tests/units/test_objects.py index 5d14d2e..ce996fc 100644 --- a/tests/units/test_objects.py +++ b/tests/units/test_objects.py @@ -16,6 +16,12 @@ # under the License. import eventlet import swift +try: + from swift.container.sync import _Iter2FileLikeObject as FileLikeIter +except ImportError: + # Nov2013: swift.common.utils now include a more generic object + from swift.common.utils import FileLikeIter + import swiftclient import swsync.objects as swobjects @@ -86,8 +92,7 @@ class TestObject(test_base.TestCase): def put_object(url, name=None, headers=None, contents=None): self.assertEqual('obj1', name) self.assertIn('x-auth-token', headers) - self.assertIsInstance(contents, - swift.container.sync._Iter2FileLikeObject) + self.assertIsInstance(contents, FileLikeIter) contents_read = contents.read() self.assertEqual(len(contents_read), len(body))