class TestHttpStore(base.StoreClearingUnitTest): def setUp(self): super(TestHttpStore, self).setUp() self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store({}) self.conf = utils.TestConfigOpts({ 'default_store': 'http', 'known_stores': "glance.store.http.Store", }) configure_registry_client(self.conf) def test_http_get(self): uri = "http://netloc/path/to/file.tar.gz" expected_returns = [ 'I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n' ] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_https_get(self): uri = "https://netloc/path/to/file.tar.gz" expected_returns = [ 'I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n' ] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(NotImplementedError, self.store.delete, loc) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, uri) def test_http_schedule_delete_swallows_error(self): uri = "https://netloc/path/to/file.tar.gz" ctx = context.RequestContext() stub_out_registry_image_update(self.stubs, self.conf) try: schedule_delete_from_backend(uri, self.conf, ctx, 'image_id') except exception.StoreDeleteNotSupported: self.fail('StoreDeleteNotSupported should be swallowed')
class TestHttpStore(base.StoreClearingUnitTest): def setUp(self): super(TestHttpStore, self).setUp() self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store({}) self.conf = utils.TestConfigOpts({ 'default_store': 'http', 'known_stores': "glance.store.http.Store", }) configure_registry_client(self.conf) def test_http_get(self): uri = "http://netloc/path/to/file.tar.gz" expected_returns = ['I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n'] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_https_get(self): uri = "https://netloc/path/to/file.tar.gz" expected_returns = ['I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n'] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(NotImplementedError, self.store.delete, loc) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, uri) def test_http_schedule_delete_swallows_error(self): uri = "https://netloc/path/to/file.tar.gz" ctx = context.RequestContext() stub_out_registry_image_update(self.stubs, self.conf) try: schedule_delete_from_backend(uri, self.conf, ctx, 'image_id') except exception.StoreDeleteNotSupported: self.fail('StoreDeleteNotSupported should be swallowed')
class TestHttpStore(unittest.TestCase): def setUp(self): self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store({}) def test_http_get(self): uri = "http://netloc/path/to/file.tar.gz" expected_returns = [ 'I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n' ] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_https_get(self): uri = "https://netloc/path/to/file.tar.gz" expected_returns = [ 'I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n' ] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(NotImplementedError, self.store.delete, loc) create_stores(utils.TestConfigOpts({})) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, uri)
class TestHttpStore(unittest.TestCase): def setUp(self): self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store({}) def test_http_get(self): uri = "http://netloc/path/to/file.tar.gz" expected_returns = ['I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n'] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_https_get(self): uri = "https://netloc/path/to/file.tar.gz" expected_returns = ['I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n'] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(NotImplementedError, self.store.delete, loc) create_stores({}) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, uri)
class TestHttpStore(unittest.TestCase): def setUp(self): self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store({}) def test_http_get(self): uri = "http://netloc/path/to/file.tar.gz" expected_returns = [ "I ", "am", " a", " t", "ea", "po", "t,", " s", "ho", "rt", " a", "nd", " s", "to", "ut", "\n", ] loc = get_location_from_uri(uri) image_file = self.store.get(loc) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_https_get(self): uri = "https://netloc/path/to/file.tar.gz" expected_returns = [ "I ", "am", " a", " t", "ea", "po", "t,", " s", "ho", "rt", " a", "nd", " s", "to", "ut", "\n", ] loc = get_location_from_uri(uri) image_file = self.store.get(loc) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(NotImplementedError, self.store.delete, loc) create_stores({}) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, uri)
class TestHttpStore(base.StoreClearingUnitTest): def setUp(self): global FAKE_RESPONSE_STACK FAKE_RESPONSE_STACK = [] self.config(default_store='http', known_stores=['glance.store.http.Store']) super(TestHttpStore, self).setUp() self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store() configure_registry_client() def test_http_get(self): uri = "http://netloc/path/to/file.tar.gz" expected_returns = ['I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n'] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_get_redirect(self): # Add two layers of redirects to the response stack, which will # return the default 200 OK with the expected data after resolving # both redirects. redirect_headers_1 = {"location": "http://example.com/teapot.img"} redirect_resp_1 = utils.FakeHTTPResponse(status=302, headers=redirect_headers_1) redirect_headers_2 = {"location": "http://example.com/teapot_real.img"} redirect_resp_2 = utils.FakeHTTPResponse(status=301, headers=redirect_headers_2) FAKE_RESPONSE_STACK.append(redirect_resp_1) FAKE_RESPONSE_STACK.append(redirect_resp_2) uri = "http://netloc/path/to/file.tar.gz" expected_returns = ['I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n'] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_get_max_redirects(self): # Add more than MAX_REDIRECTS redirects to the response stack redirect_headers = {"location": "http://example.com/teapot.img"} redirect_resp = utils.FakeHTTPResponse(status=302, headers=redirect_headers) for i in xrange(MAX_REDIRECTS + 2): FAKE_RESPONSE_STACK.append(redirect_resp) uri = "http://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(exception.MaxRedirectsExceeded, self.store.get, loc) def test_http_get_redirect_invalid(self): redirect_headers = {"location": "http://example.com/teapot.img"} redirect_resp = utils.FakeHTTPResponse(status=307, headers=redirect_headers) FAKE_RESPONSE_STACK.append(redirect_resp) uri = "http://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(exception.BadStoreUri, self.store.get, loc) def test_http_get_not_found(self): not_found_resp = utils.FakeHTTPResponse(status=404, data="404 Not Found") FAKE_RESPONSE_STACK.append(not_found_resp) uri = "http://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(exception.BadStoreUri, self.store.get, loc) def test_https_get(self): uri = "https://netloc/path/to/file.tar.gz" expected_returns = ['I ', 'am', ' a', ' t', 'ea', 'po', 't,', ' s', 'ho', 'rt', ' a', 'nd', ' s', 'to', 'ut', '\n'] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) ctx = context.RequestContext() self.assertRaises(NotImplementedError, self.store.delete, loc) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, ctx, uri) def test_http_schedule_delete_swallows_error(self): uri = "https://netloc/path/to/file.tar.gz" ctx = context.RequestContext() stub_out_registry_image_update(self.stubs) try: safe_delete_from_backend(ctx, uri, 'image_id') except exception.StoreDeleteNotSupported: self.fail('StoreDeleteNotSupported should be swallowed')
class TestHttpStore(base.StoreClearingUnitTest): def setUp(self): self.config(default_store="http", known_stores=["glance.store.http.Store"]) super(TestHttpStore, self).setUp() self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store() configure_registry_client() def test_http_get(self): uri = "http://netloc/path/to/file.tar.gz" expected_returns = [ "I ", "am", " a", " t", "ea", "po", "t,", " s", "ho", "rt", " a", "nd", " s", "to", "ut", "\n", ] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_https_get(self): uri = "https://netloc/path/to/file.tar.gz" expected_returns = [ "I ", "am", " a", " t", "ea", "po", "t,", " s", "ho", "rt", " a", "nd", " s", "to", "ut", "\n", ] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(NotImplementedError, self.store.delete, loc) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, uri) def test_http_schedule_delete_swallows_error(self): uri = "https://netloc/path/to/file.tar.gz" ctx = context.RequestContext() stub_out_registry_image_update(self.stubs) try: schedule_delete_from_backend(uri, ctx, "image_id") except exception.StoreDeleteNotSupported: self.fail("StoreDeleteNotSupported should be swallowed")
class TestHttpStore(unittest.TestCase): def setUp(self): self.stubs = stubout.StubOutForTesting() stub_out_http_backend(self.stubs) Store.CHUNKSIZE = 2 self.store = Store({}) def test_http_get(self): uri = "http://netloc/path/to/file.tar.gz" expected_returns = [ "I ", "am", " a", " t", "ea", "po", "t,", " s", "ho", "rt", " a", "nd", " s", "to", "ut", "\n", ] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_https_get(self): uri = "https://netloc/path/to/file.tar.gz" expected_returns = [ "I ", "am", " a", " t", "ea", "po", "t,", " s", "ho", "rt", " a", "nd", " s", "to", "ut", "\n", ] loc = get_location_from_uri(uri) (image_file, image_size) = self.store.get(loc) self.assertEqual(image_size, 31) chunks = [c for c in image_file] self.assertEqual(chunks, expected_returns) def test_http_delete_raise_error(self): uri = "https://netloc/path/to/file.tar.gz" loc = get_location_from_uri(uri) self.assertRaises(NotImplementedError, self.store.delete, loc) create_stores(utils.TestConfigOpts({})) self.assertRaises(exception.StoreDeleteNotSupported, delete_from_backend, uri) def test_http_schedule_delete_swallows_error(self): stub_out_registry_image_update(self.stubs) uri = "https://netloc/path/to/file.tar.gz" ctx = context.RequestContext() conf = utils.TestConfigOpts({}) create_stores(conf) try: schedule_delete_from_backend(uri, conf, ctx, "image_id") except exception.StoreDeleteNotSupported: self.fail("StoreDeleteNotSupported should be swallowed")