def test_multi_tenant_location_custom_endpoint_type(self):
     self.config(swift_store_endpoint_type='InternalURL')
     fake_get_endpoint = FakeGetEndpoint('https://some_endpoint')
     self.stubs.Set(auth, 'get_endpoint', fake_get_endpoint)
     ctxt = context.RequestContext(user='******',
                                   tenant='tenant',
                                   auth_token='123',
                                   service_catalog={})
     store = swift.MultiTenantStore(self.conf)
     store.configure()
     store._get_endpoint(ctxt)
     self.assertEqual(fake_get_endpoint.endpoint_type, 'InternalURL')
 def test_multi_tenant_location_http(self):
     fake_get_endpoint = FakeGetEndpoint('http://some_endpoint')
     self.stubs.Set(auth, 'get_endpoint', fake_get_endpoint)
     ctxt = context.RequestContext(user='******',
                                   tenant='tenant',
                                   auth_token='123',
                                   service_catalog={})
     store = swift.MultiTenantStore(self.conf)
     store.configure()
     location = store.create_location('image-id', context=ctxt)
     self.assertEqual(location.scheme, 'swift+http')
     self.assertEqual(location.swift_url, 'http://some_endpoint')
 def test_read_acl_public(self):
     """
     Test that we can set a public read acl.
     """
     self.config(swift_store_multi_tenant=True)
     store = Store(self.conf)
     store.configure()
     uri = "swift+http://storeurl/glance/%s" % FAKE_UUID
     loc = location.get_location_from_uri(uri, conf=self.conf)
     ctxt = context.RequestContext()
     store.set_acls(loc, public=True, context=ctxt)
     container_headers = swiftclient.client.head_container(
         'x', 'y', 'glance')
     self.assertEqual(container_headers['X-Container-Read'],
                      ".r:*,.rlistings")
 def test_write_acls(self):
     """
     Test that we can set write acl for tenants.
     """
     self.config(swift_store_multi_tenant=True)
     store = Store(self.conf)
     store.configure()
     uri = "swift+http://storeurl/glance/%s" % FAKE_UUID
     loc = location.get_location_from_uri(uri, conf=self.conf)
     read_tenants = ['frank', 'jim']
     ctxt = context.RequestContext()
     store.set_acls(loc, write_tenants=read_tenants, context=ctxt)
     container_headers = swiftclient.client.head_container(
         'x', 'y', 'glance')
     self.assertEqual(container_headers['X-Container-Write'],
                      'frank:*,jim:*')
Exemplo n.º 5
0
 def test_read_acl_tenants(self):
     """
     Test that we can set read acl for tenants.
     """
     self.config(swift_store_multi_tenant=True)
     store = Store(self.conf)
     store.configure()
     uri = "swift+http://storeurl/glance/%s" % FAKE_UUID
     loc = get_location_from_uri(uri)
     read_tenants = ['matt', 'mark']
     ctxt = context.RequestContext()
     store.set_acls(loc, read_tenants=read_tenants, context=ctxt)
     container_headers = swiftclient.client.head_container(
         'x', 'y', 'glance')
     self.assertEqual(container_headers['X-Container-Read'],
                      'matt:*,mark:*')
 def setUp(self):
     super(TestMultiTenantStoreConnections, self).setUp()
     moxfixture = self.useFixture(moxstubout.MoxStubout())
     self.stubs = moxfixture.stubs
     self.stubs.Set(swiftclient, 'Connection', FakeConnection)
     self.context = context.RequestContext(user='******',
                                           tenant='tenant',
                                           auth_token='0123')
     self.store = swift.MultiTenantStore(self.conf)
     specs = {
         'scheme': 'swift',
         'auth_or_store_url': 'example.com',
         'container': 'cont',
         'obj': 'object'
     }
     self.location = swift.StoreLocation(specs, self.conf)
     self.addCleanup(self.conf.reset)
 def test_multi_tenant_location(self):
     self.config(swift_store_container='container')
     fake_get_endpoint = FakeGetEndpoint('https://some_endpoint')
     self.stubs.Set(auth, 'get_endpoint', fake_get_endpoint)
     ctxt = context.RequestContext(user='******',
                                   tenant='tenant',
                                   auth_token='123',
                                   service_catalog={})
     store = swift.MultiTenantStore(self.conf)
     store.configure()
     location = store.create_location('image-id', context=ctxt)
     self.assertEqual(location.scheme, 'swift+https')
     self.assertEqual(location.swift_url, 'https://some_endpoint')
     self.assertEqual(location.container, 'container_image-id')
     self.assertEqual(location.obj, 'image-id')
     self.assertIsNone(location.user)
     self.assertIsNone(location.key)
     self.assertEqual(fake_get_endpoint.service_type, 'object-store')
Exemplo n.º 8
0
    def test_get_with_http_auth(self):
        """
        Test a retrieval from Swift with an HTTP authurl. This is
        specified either via a Location header with swift+http:// or using
        http:// in the swift_store_auth_address config value
        """
        loc = get_location_from_uri("swift+http://%s:key@auth_address/"
                                    "glance/%s" %
                                    (self.swift_store_user, FAKE_UUID))

        ctxt = context.RequestContext()
        (image_swift, image_size) = self.store.get(loc, context=ctxt)
        self.assertEqual(image_size, 5120)

        expected_data = "*" * FIVE_KB
        data = ""

        for chunk in image_swift:
            data += chunk
        self.assertEqual(expected_data, data)
    def test_get_with_retry(self):
        """
        Test a retrieval where Swift does not get the full image in a single
        request.
        """
        uri = "swift://%s:key@auth_address/glance/%s" % (self.swift_store_user,
                                                         FAKE_UUID)
        loc = location.get_location_from_uri(uri, conf=self.conf)
        ctxt = context.RequestContext()
        (image_swift, image_size) = self.store.get(loc, context=ctxt)
        resp_full = ''.join([chunk for chunk in image_swift.wrapped])
        resp_half = resp_full[:len(resp_full) / 2]
        image_swift.wrapped = swift.swift_retry_iter(resp_half, image_size,
                                                     self.store,
                                                     loc.store_location, ctxt)
        self.assertEqual(image_size, 5120)

        expected_data = "*" * FIVE_KB
        data = ""

        for chunk in image_swift:
            data += chunk
        self.assertEqual(expected_data, data)