From 9bdb77a388f7540978e909a1f69e33bb6f2bb3ca Mon Sep 17 00:00:00 2001 From: indianwhocodes Date: Fri, 2 Sep 2022 08:47:14 -0700 Subject: [PATCH] Fixes Storage-Policy AttributeError in proxy Closes-Bug: #1989140 Change-Id: I99e4a1daf550d492b28c8a82c0b7a81b2f73dffe --- swift/proxy/controllers/base.py | 3 +- test/unit/proxy/controllers/test_base.py | 19 +++++++++++- test/unit/proxy/test_server.py | 37 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index e0b95107e2..629116ab39 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -1840,8 +1840,7 @@ class Controller(object): path_env['PATH_INFO'] = "/v1/%s/%s" % ( str_to_wsgi(account), str_to_wsgi(container)) info = get_container_info(path_env, self.app) - if not info or not is_success(info.get('status')): - info = headers_to_container_info({}, 0) + if not is_success(info.get('status')): info['partition'] = None info['nodes'] = None else: diff --git a/test/unit/proxy/controllers/test_base.py b/test/unit/proxy/controllers/test_base.py index 17eb8c6f17..c2d12eda6f 100644 --- a/test/unit/proxy/controllers/test_base.py +++ b/test/unit/proxy/controllers/test_base.py @@ -834,6 +834,23 @@ class TestFuncs(BaseTest): self.assertEqual(incomplete_expected, headers_from_container_info(incomplete_info)) + def test_container_info_preserves_storage_policy(self): + base = Controller(self.app) + base.account_name = 'a' + base.container_name = 'c' + + fake_info = {'status': 404, 'storage_policy': 1} + + with mock.patch('swift.proxy.controllers.base.' + 'get_container_info', return_value=fake_info): + container_info = \ + base.container_info(base.account_name, base.container_name, + Request.blank('/')) + self.assertEqual(container_info['status'], 404) + self.assertEqual(container_info['storage_policy'], 1) + self.assertEqual(container_info['partition'], None) + self.assertEqual(container_info['nodes'], None) + def test_container_info_needs_req(self): base = Controller(self.app) base.account_name = 'a' @@ -844,7 +861,7 @@ class TestFuncs(BaseTest): container_info = \ base.container_info(base.account_name, base.container_name, Request.blank('/')) - self.assertEqual(container_info['status'], 0) + self.assertEqual(container_info['status'], 503) def test_headers_to_account_info_missing(self): resp = headers_to_account_info({}, 404) diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index a03e8b43e4..986da21c55 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -7415,6 +7415,43 @@ class BaseTestECObjectController(BaseTestObjectController): self.assertEqual(len(error_lines), 0) # sanity self.assertEqual(len(warn_lines), 0) # sanity + def test_GET_ec_deleted(self): + prolis = _test_sockets[0] + prosrv = _test_servers[0] + + container_name = 'ec_deleted' + self.put_container(self.ec_policy.name, container_name) + + # delete container + sock = connect_tcp(('localhost', prolis.getsockname()[1])) + fd = sock.makefile('rwb') + fd.write(('DELETE /v1/a/%s HTTP/1.1\r\n' + 'Host: localhost\r\n' + 'Connection: close\r\n' + '\r\n' % container_name).encode('ascii')) + fd.flush() + headers = readuntil2crlfs(fd) + exp = b'HTTP/1.1 20' + self.assertEqual(headers[:len(exp)], exp) + + # download from deleted container + sock = connect_tcp(('localhost', prolis.getsockname()[1])) + fd = sock.makefile('rwb') + fd.write(('GET /v1/a/%s/no-object-there HTTP/1.1\r\n' + 'Host: localhost\r\n' + 'Connection: close\r\n' + 'X-Storage-Token: t\r\n' + '\r\n' % container_name).encode('ascii')) + fd.flush() + headers = readuntil2crlfs(fd) + exp = b'HTTP/1.1 404' + self.assertEqual(headers[:len(exp)], exp) + + error_lines = prosrv.logger.get_lines_for_level('error') + warn_lines = prosrv.logger.get_lines_for_level('warning') + self.assertEqual(len(error_lines), 0) # sanity + self.assertEqual(len(warn_lines), 0) # sanity + def test_conditional_GET_ec(self): # sanity self.assertEqual('erasure_coding', self.ec_policy.policy_type)