Fix compatibilities issues with recent swift devel

Server does not set x-trans-id anymore
swift.common includes a more generic FileLikeIter object
This commit is contained in:
Tristan Cacqueray 2013-11-08 05:13:40 -05:00
parent 3d9e44c2b9
commit b62a7ba55e
3 changed files with 20 additions and 7 deletions

View File

@ -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:

View File

@ -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))

View File

@ -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))