Skip to content

Commit

Permalink
Merge "Rewrite Swift store functional tests"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 12, 2012
2 parents 8f54bf7 + 576500e commit 1574b2b
Show file tree
Hide file tree
Showing 5 changed files with 436 additions and 629 deletions.
12 changes: 7 additions & 5 deletions glance/store/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,15 @@ def swift_url(self):
HTTPS is assumed, unless 'swift+http' is specified.
"""
if self.scheme in ('swift+https', 'swift'):
auth_scheme = 'https://'
if self.auth_or_store_url.startswith('http'):
return self.auth_or_store_url
else:
auth_scheme = 'http://'
if self.scheme in ('swift+https', 'swift'):
auth_scheme = 'https://'
else:
auth_scheme = 'http://'

full_url = ''.join([auth_scheme, self.auth_or_store_url])
return full_url
return ''.join([auth_scheme, self.auth_or_store_url])


class Store(glance.store.base.Store):
Expand Down
72 changes: 72 additions & 0 deletions glance/tests/functional/store/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2012 OpenStack, LLC
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import StringIO

from glance.common import exception
from glance.common import utils
from glance.openstack.common import cfg
import glance.store.location

#NOTE(bcwaldon): importing this to get the default_store option
import glance.api.v1.images


CONF = cfg.CONF


class BaseTestCase(object):

def setUp(self):
pass

def tearDown(self):
CONF.reset()

def config(self, **kw):
for k, v in kw.iteritems():
CONF.set_override(k, v, group=None)

def get_store(self, **kwargs):
raise NotImplementedError('get_store() must be implemented')

def test_lifecycle(self):
"""Add, get and delete an image"""
store = self.get_store()

image_id = utils.generate_uuid()
image_data = StringIO.StringIO('XXX')
image_checksum = 'bc9189406be84ec297464a514221406d'
uri, add_size, add_checksum = store.add(image_id, image_data, 3)

self.assertEqual(3, add_size)
self.assertEqual(image_checksum, add_checksum)

store = self.get_store()
location = glance.store.location.Location(
self.store_name,
store.get_store_location_class(),
uri=uri,
image_id=image_id)

(get_iter, get_size) = store.get(location)
self.assertEqual('3', get_size)
self.assertEqual('XXX', ''.join(get_iter))

store.delete(location)

self.assertRaises(exception.NotFound, store.get, location)

0 comments on commit 1574b2b

Please sign in to comment.