Skip to content

Commit

Permalink
Use python-swiftclient for swift store.
Browse files Browse the repository at this point in the history
- Use python-swiftclient instead of swift.common.client (pinned to
  github hash).
- Fixes bug 1002791.

Change-Id: Ibdc00b75c62445a7f0930ee1806ad469e3d3ffe2
  • Loading branch information
chmouel committed Jun 12, 2012
1 parent 4f688ef commit b99e861
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
16 changes: 8 additions & 8 deletions glance/store/swift.py
Expand Up @@ -33,7 +33,7 @@
import glance.store.location

try:
from swift.common import client as swift_client
import swiftclient
except ImportError:
pass

Expand Down Expand Up @@ -257,7 +257,7 @@ def get(self, location):
(resp_headers, resp_body) = swift_conn.get_object(
container=loc.container, obj=loc.obj,
resp_chunk_size=self.CHUNKSIZE)
except swift_client.ClientException, e:
except swiftclient.ClientException, e:
if e.http_status == httplib.NOT_FOUND:
uri = location.get_store_uri()
raise exception.NotFound(_("Swift could not find image at "
Expand Down Expand Up @@ -316,7 +316,7 @@ def _make_swift_connection(self, auth_url, user, key):
raise exception.BadStoreUri(auth_url, reason)
(tenant_name, user) = tenant_user

return swift_client.Connection(
return swiftclient.Connection(
authurl=full_auth_url, user=user, key=key, snet=snet,
tenant_name=tenant_name, auth_version=auth_version)

Expand Down Expand Up @@ -465,7 +465,7 @@ def add(self, image_id, image_file, image_size):
# GET /images/details

return (location.get_uri(), image_size, obj_etag)
except swift_client.ClientException, e:
except swiftclient.ClientException, e:
if e.http_status == httplib.CONFLICT:
raise exception.Duplicate(_("Swift already has an image at "
"location %s") % location.get_uri())
Expand Down Expand Up @@ -497,7 +497,7 @@ def delete(self, location):
try:
headers = swift_conn.head_object(loc.container, loc.obj)
manifest = headers.get('x-object-manifest')
except swift_client.ClientException, e:
except swiftclient.ClientException, e:
if e.http_status != httplib.NOT_FOUND:
raise
if manifest:
Expand All @@ -514,7 +514,7 @@ def delete(self, location):
else:
swift_conn.delete_object(loc.container, loc.obj)

except swift_client.ClientException, e:
except swiftclient.ClientException, e:
if e.http_status == httplib.NOT_FOUND:
uri = location.get_store_uri()
raise exception.NotFound(_("Swift could not find image at "
Expand Down Expand Up @@ -550,12 +550,12 @@ def create_container_if_missing(container, swift_conn):
"""
try:
swift_conn.head_container(container)
except swift_client.ClientException, e:
except swiftclient.ClientException, e:
if e.http_status == httplib.NOT_FOUND:
if CONF.swift_store_create_container_on_put:
try:
swift_conn.put_container(container)
except swift_client.ClientException, e:
except swiftclient.ClientException, e:
msg = _("Failed to add container to Swift.\n"
"Got error from Swift: %(e)s") % locals()
raise glance.store.BackendException(msg)
Expand Down
8 changes: 4 additions & 4 deletions glance/tests/functional/store_utils.py
Expand Up @@ -120,7 +120,7 @@ def setup_swift(test):
test.disabled = True
return

from swift.common import client as swift_client
import swiftclient

try:
swift_host = test.swift_store_auth_address
Expand All @@ -136,7 +136,7 @@ def setup_swift(test):
test.disabled = True
return

swift_conn = swift_client.Connection(
swift_conn = swiftclient.Connection(
authurl=swift_host, user=user, key=key, snet=False, retries=1)

try:
Expand Down Expand Up @@ -170,10 +170,10 @@ def setup_swift(test):

def teardown_swift(test):
if not test.disabled:
from swift.common import client as swift_client
import swiftclient
try:
test.swift_conn.delete_container(test.swift_store_container)
except swift_client.ClientException, e:
except swiftclient.ClientException, e:
if e.http_status == httplib.CONFLICT:
pass
else:
Expand Down
10 changes: 5 additions & 5 deletions glance/tests/functional/v1/test_swift.py
Expand Up @@ -78,10 +78,10 @@ def tearDown(self):
super(TestSwift, self).tearDown()

def clear_container(self):
from swift.common import client as swift_client
import swiftclient
try:
self.swift_conn.delete_container(self.swift_store_container)
except swift_client.ClientException, e:
except swiftclient.ClientException, e:
if e.http_status == httplib.CONFLICT:
pass
else:
Expand Down Expand Up @@ -203,8 +203,8 @@ def test_large_objects(self):
image_loc = get_location_from_uri(image_loc)
swift_loc = image_loc.store_location

from swift.common import client as swift_client
swift_conn = swift_client.Connection(
import swiftclient
swift_conn = swiftclient.Connection(
authurl=swift_loc.swift_auth_url,
user=swift_loc.user, key=swift_loc.key)

Expand Down Expand Up @@ -235,7 +235,7 @@ def test_large_objects(self):

# Verify the segments no longer exist
for segment in segments:
self.assertRaises(swift_client.ClientException,
self.assertRaises(swiftclient.ClientException,
swift_conn.head_object,
obj_container, segment)

Expand Down
40 changes: 19 additions & 21 deletions glance/tests/unit/test_swift_store.py
Expand Up @@ -24,7 +24,7 @@
import urllib

import stubout
import swift.common.client
import swiftclient

from glance.common import exception
from glance.common import utils
Expand All @@ -33,7 +33,6 @@
import glance.store.swift
from glance.store.location import get_location_from_uri
from glance.tests.unit import base
from glance.tests import utils as test_utils

CONF = cfg.CONF

Expand All @@ -55,10 +54,9 @@


# We stub out as little as possible to ensure that the code paths
# between glance.store.swift and swift.common.client are tested
# between glance.store.swift and swiftclient are tested
# thoroughly
def stub_out_swift_common_client(stubs, swift_store_auth_version):

def stub_out_swiftclient(stubs, swift_store_auth_version):
fixture_containers = ['glance']
fixture_headers = {'glance/%s' % FAKE_UUID:
{'content-length': FIVE_KB,
Expand All @@ -69,7 +67,7 @@ def stub_out_swift_common_client(stubs, swift_store_auth_version):
def fake_head_container(url, token, container, **kwargs):
if container not in fixture_containers:
msg = "No container %s found" % container
raise swift.common.client.ClientException(msg,
raise swiftclient.ClientException(msg,
http_status=httplib.NOT_FOUND)

def fake_put_container(url, token, container, **kwargs):
Expand Down Expand Up @@ -103,7 +101,7 @@ def fake_put_object(url, token, container, name, contents, **kwargs):
if read_len > MAX_SWIFT_OBJECT_SIZE:
msg = ('Image size:%d exceeds Swift max:%d' %
(read_len, MAX_SWIFT_OBJECT_SIZE))
raise swift.common.client.ClientException(
raise swiftclient.ClientException(
msg, http_status=httplib.REQUEST_ENTITY_TOO_LARGE)
fixture_objects[fixture_key] = fixture_object
fixture_headers[fixture_key] = {
Expand All @@ -113,15 +111,15 @@ def fake_put_object(url, token, container, name, contents, **kwargs):
else:
msg = ("Object PUT failed - Object with key %s already exists"
% fixture_key)
raise swift.common.client.ClientException(msg,
raise swiftclient.ClientException(msg,
http_status=httplib.CONFLICT)

def fake_get_object(url, token, container, name, **kwargs):
# GET returns the tuple (list of headers, file object)
fixture_key = "%s/%s" % (container, name)
if not fixture_key in fixture_headers:
msg = "Object GET failed"
raise swift.common.client.ClientException(msg,
raise swiftclient.ClientException(msg,
http_status=httplib.NOT_FOUND)

fixture = fixture_headers[fixture_key]
Expand All @@ -146,15 +144,15 @@ def fake_head_object(url, token, container, name, **kwargs):
return fixture_headers[fixture_key]
except KeyError:
msg = "Object HEAD failed - Object does not exist"
raise swift.common.client.ClientException(msg,
raise swiftclient.ClientException(msg,
http_status=httplib.NOT_FOUND)

def fake_delete_object(url, token, container, name, **kwargs):
# DELETE returns nothing
fixture_key = "%s/%s" % (container, name)
if fixture_key not in fixture_headers.keys():
msg = "Object DELETE failed - Object does not exist"
raise swift.common.client.ClientException(msg,
raise swiftclient.ClientException(msg,
http_status=httplib.NOT_FOUND)
else:
del fixture_headers[fixture_key]
Expand All @@ -169,24 +167,24 @@ def fake_get_auth(url, user, key, snet, auth_version, **kwargs):
# Check the auth version against the configured value
if swift_store_auth_version != auth_version:
msg = 'AUTHENTICATION failed (version mismatch)'
raise swift.common.client.ClientException(msg)
raise swiftclient.ClientException(msg)
return None, None

stubs.Set(swift.common.client,
stubs.Set(swiftclient.client,
'head_container', fake_head_container)
stubs.Set(swift.common.client,
stubs.Set(swiftclient.client,
'put_container', fake_put_container)
stubs.Set(swift.common.client,
stubs.Set(swiftclient.client,
'put_object', fake_put_object)
stubs.Set(swift.common.client,
stubs.Set(swiftclient.client,
'delete_object', fake_delete_object)
stubs.Set(swift.common.client,
stubs.Set(swiftclient.client,
'head_object', fake_head_object)
stubs.Set(swift.common.client,
stubs.Set(swiftclient.client,
'get_object', fake_get_object)
stubs.Set(swift.common.client,
stubs.Set(swiftclient.client,
'get_auth', fake_get_auth)
stubs.Set(swift.common.client,
stubs.Set(swiftclient.client,
'http_connection', fake_http_connection)


Expand Down Expand Up @@ -587,7 +585,7 @@ def setUp(self):
self.config(**conf)
super(TestStoreAuthV1, self).setUp()
self.stubs = stubout.StubOutForTesting()
stub_out_swift_common_client(self.stubs,
stub_out_swiftclient(self.stubs,
conf['swift_store_auth_version'])
self.store = Store()

Expand Down
4 changes: 3 additions & 1 deletion tools/pip-requires
Expand Up @@ -27,7 +27,9 @@ iso8601>=0.1.4
# Trying to hit a moving target causes our local unittests to fail
# when they should remain unaffected.
-e git://github.com/openstack/keystone.git@ab6be05068068b0902db44b1d60f56eea4fe1215#egg=keystone
-e git://github.com/openstack/swift.git@208b8e85a80e46ddb49dc2035cb292570a20c7db#egg=swift

# For Swift storage backend.
-e git://github.com/openstack/python-swiftclient.git@dec11f6ec9#egg=python-swiftclient

# Note you will need gcc buildtools installed and must
# have installed libxml headers for lxml to be successfully
Expand Down

0 comments on commit b99e861

Please sign in to comment.