diff options
-rw-r--r-- | glance_store/_drivers/cinder.py | 6 | ||||
-rw-r--r-- | glance_store/_drivers/filesystem.py | 7 | ||||
-rw-r--r-- | glance_store/_drivers/swift/store.py | 6 | ||||
-rw-r--r-- | glance_store/backend.py | 13 | ||||
-rw-r--r-- | glance_store/driver.py | 7 | ||||
-rw-r--r-- | test-requirements.txt | 1 | ||||
-rw-r--r-- | tests/unit/test_swift_store.py | 97 |
7 files changed, 88 insertions, 49 deletions
diff --git a/glance_store/_drivers/cinder.py b/glance_store/_drivers/cinder.py index a50e548..a2b4a15 100644 --- a/glance_store/_drivers/cinder.py +++ b/glance_store/_drivers/cinder.py @@ -86,7 +86,7 @@ def get_cinderclient(conf, context): glance_store = conf.glance_store c = cinderclient.Client(context.user, - context.auth_tok, + context.auth_token, project_id=context.tenant, auth_url=url, insecure=glance_store.cinder_api_insecure, @@ -94,8 +94,8 @@ def get_cinderclient(conf, context): cacert=glance_store.cinder_ca_certificates_file) # noauth extracts user_id:project_id from auth_token - c.client.auth_token = context.auth_tok or '%s:%s' % (context.user, - context.tenant) + c.client.auth_token = context.auth_token or '%s:%s' % (context.user, + context.tenant) c.client.management_url = url return c diff --git a/glance_store/_drivers/filesystem.py b/glance_store/_drivers/filesystem.py index 2edcf37..f84be13 100644 --- a/glance_store/_drivers/filesystem.py +++ b/glance_store/_drivers/filesystem.py @@ -36,7 +36,6 @@ import glance_store.driver from glance_store import exceptions from glance_store import i18n import glance_store.location -from glance_store.openstack.common import processutils LOG = logging.getLogger(__name__) @@ -428,10 +427,8 @@ class Store(glance_store.driver.Store): """ #Calculate total available space - df = processutils.execute("df", "-k", - mount_point)[0].strip("'\n'") - total_available_space = int(df.split('\n')[1].split()[3]) * units.Ki - + stvfs_result = os.statvfs(mount_point) + total_available_space = stvfs_result.f_bavail * stvfs_result.f_bsize return max(0, total_available_space) def _find_best_datadir(self, image_size): diff --git a/glance_store/_drivers/swift/store.py b/glance_store/_drivers/swift/store.py index 42a56d6..39dbfbf 100644 --- a/glance_store/_drivers/swift/store.py +++ b/glance_store/_drivers/swift/store.py @@ -398,12 +398,6 @@ class BaseStore(driver.Store): return (resp_headers, resp_body) - def validate_location(self, uri): - pieces = urlparse.urlparse(uri) - if pieces.scheme in ['swift+config']: - reason = (_("Location credentials are invalid")) - raise exceptions.BadStoreUri(message=reason) - def get(self, location, connection=None, offset=0, chunk_size=None, context=None): location = location.store_location diff --git a/glance_store/backend.py b/glance_store/backend.py index e300de7..8cb315b 100644 --- a/glance_store/backend.py +++ b/glance_store/backend.py @@ -325,7 +325,10 @@ def store_add_to_backend(image_id, data, size, store, context=None): the checksum of the data the storage systems metadata dictionary for the location """ - (location, size, checksum, metadata) = store.add(image_id, data, size) + (location, size, checksum, metadata) = store.add(image_id, + data, + size, + context=context) if metadata is not None: if not isinstance(metadata, dict): msg = (_("The storage driver %(driver)s returned invalid " @@ -368,11 +371,7 @@ def set_acls(location_uri, public=False, read_tenants=[], try: store.set_acls(loc, public=public, read_tenants=read_tenants, - write_tenants=write_tenants) + write_tenants=write_tenants, + context=context) except NotImplementedError: LOG.debug(_("Skipping store.set_acls... not implemented.")) - - -def validate_location(uri, context=None): - store = get_store_from_uri(uri) - store.validate_location(uri) diff --git a/glance_store/driver.py b/glance_store/driver.py index 0bdf36e..d1d28f8 100644 --- a/glance_store/driver.py +++ b/glance_store/driver.py @@ -96,13 +96,6 @@ class Store(object): """ # NOTE(flaper87): This should probably go away - def validate_location(self, location): - """ - Takes a location and validates it for the presence - of any account references - """ - pass - def get(self, location, offset=0, chunk_size=None, context=None): """ Takes a `glance_store.location.Location` object that indicates diff --git a/test-requirements.txt b/test-requirements.txt index a0c3a00..779d3a3 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,6 +6,7 @@ mock>=1.0 # Unit testing coverage>=3.6 +httpretty>=0.8.0,!=0.8.1,!=0.8.2,!=0.8.3 fixtures>=0.3.14 python-subunit>=0.0.18 testrepository>=0.0.18 diff --git a/tests/unit/test_swift_store.py b/tests/unit/test_swift_store.py index ba4146b..6f4133d 100644 --- a/tests/unit/test_swift_store.py +++ b/tests/unit/test_swift_store.py @@ -23,10 +23,12 @@ import mock import tempfile import uuid +import httpretty from oslo.config import cfg from oslo.utils import units from oslotest import moxstubout import six +import StringIO import swiftclient from glance_store._drivers.swift import store as swift @@ -240,27 +242,6 @@ class SwiftTests(object): image_size = self.store.get_size(loc) self.assertEqual(image_size, 5120) - def test_validate_location_for_invalid_uri(self): - """ - Test that validate location raises when the location contains - any account reference. - """ - uri = "swift+config://store_1/glance/%s" - self.assertRaises(exceptions.BadStoreUri, - self.store.validate_location, - uri) - - def test_validate_location_for_valid_uri(self): - """ - Test that validate location verifies that the location does not - contain any account reference - """ - uri = "swift://user:key@auth_address/glance/%s" - try: - self.assertIsNone(self.store.validate_location(uri)) - except Exception: - self.fail('Location uri validation failed') - def test_get_size_with_multi_tenant_on(self): """Test that single tenant uris work with multi tenant on.""" uri = ("swift://%s:key@auth_address/glance/%s" % @@ -1042,6 +1023,80 @@ class TestMultiTenantStoreConnections(base.StoreBaseTest): self.assertTrue(connection.snet) +class TestMultiTenantStoreContext(base.StoreBaseTest): + + _CONF = cfg.CONF + + def setUp(self): + """Establish a clean test environment.""" + super(TestMultiTenantStoreContext, self).setUp() + conf = SWIFT_CONF.copy() + + self.store = Store(self.conf) + self.config(**conf) + self.store.configure() + self.register_store_schemes(self.store) + self.service_catalog = [{ + "name": "Object Storage", + "type": "object-store", + "endpoints": [{ + "publicURL": "http://127.0.0.1:0", + "region": "region1", + "versionId": "1.0", + }] + }] + self.addCleanup(self.conf.reset) + + @httpretty.activate + def test_download_context(self): + """Verify context (ie token) is passed to swift on download.""" + self.config(swift_store_multi_tenant=True) + store = Store(self.conf) + store.configure() + uri = "swift+http://127.0.0.1:0/glance_123/123" + loc = location.get_location_from_uri(uri, conf=self.conf) + ctx = context.RequestContext( + service_catalog=self.service_catalog, user='tenant:user1', + tenant='tenant', auth_token='0123') + httpretty.register_uri(httpretty.GET, + "http://127.0.0.1:0/glance_123/123", + status=200) + store.get(loc, context=ctx) + self.assertEqual( + '0123', httpretty.last_request().headers['X-Auth-Token']) + + @httpretty.activate + def test_upload_context(self): + """Verify context (ie token) is passed to swift on upload.""" + def put_callback(request, uri, headers): + self.assertEqual('Some data', request.body) + self.assertEqual('0123', request.headers['X-Auth-Token']) + return (201, headers, "") + + def head_callback(request, uri, headers): + self.assertEqual('0123', request.headers['X-Auth-Token']) + return (200, headers, "") + + httpretty.register_uri(httpretty.HEAD, + "http://127.0.0.1:0/glance_123", + head_callback) + httpretty.register_uri(httpretty.PUT, + "http://127.0.0.1:0/glance_123/123", + put_callback) + + self.config(swift_store_multi_tenant=True) + store = Store(self.conf) + store.configure() + pseudo_file = StringIO.StringIO('Some data') + ctx = context.RequestContext( + service_catalog=self.service_catalog, user='tenant:user1', + tenant='tenant', auth_token='0123') + store.add('123', pseudo_file, pseudo_file.len, + context=ctx) + self.assertEqual( + '0123', httpretty.last_request().headers['X-Auth-Token']) + + class FakeGetEndpoint(object): def __init__(self, response): self.response = response |