From 5cbd5cf303ca085af2a61dbb5b98d1b98099bd7e Mon Sep 17 00:00:00 2001
From: cheng <li.chenga@h3c.com>
Date: Mon, 15 Jan 2018 12:05:39 +0800
Subject: [PATCH] Return HTTPServerError instead of HTTPNotFound

Swift allows autocreate account. It should be treat as server error
instead of 404 when it fails to create account

Change-Id: I726271bc06e3c1b07a4af504c3fd7ddb789bd512
Closes-bug: 1718810
---
 swift/proxy/controllers/base.py      | 2 ++
 swift/proxy/controllers/container.py | 5 +++--
 test/unit/proxy/test_server.py       | 4 ++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py
index e588355235..576bcf68c7 100644
--- a/swift/proxy/controllers/base.py
+++ b/swift/proxy/controllers/base.py
@@ -1839,9 +1839,11 @@ class Controller(object):
         if is_success(resp.status_int):
             self.app.logger.info(_('autocreate account %r'), path)
             clear_info_cache(self.app, req.environ, account)
+            return True
         else:
             self.app.logger.warning(_('Could not autocreate account %r'),
                                     path)
+            return False
 
     def GETorHEAD_base(self, req, server_type, node_iter, partition, path,
                        concurrency=1, client_chunk_size=None):
diff --git a/swift/proxy/controllers/container.py b/swift/proxy/controllers/container.py
index 3a274b8443..0894829a4c 100644
--- a/swift/proxy/controllers/container.py
+++ b/swift/proxy/controllers/container.py
@@ -24,7 +24,7 @@ from swift.proxy.controllers.base import Controller, delay_denial, \
     cors_validation, set_info_cache, clear_info_cache
 from swift.common.storage_policy import POLICIES
 from swift.common.swob import HTTPBadRequest, HTTPForbidden, \
-    HTTPNotFound
+    HTTPNotFound, HTTPServerError
 
 
 class ContainerController(Controller):
@@ -160,7 +160,8 @@ class ContainerController(Controller):
         account_partition, accounts, container_count = \
             self.account_info(self.account_name, req)
         if not accounts and self.app.account_autocreate:
-            self.autocreate_account(req, self.account_name)
+            if not self.autocreate_account(req, self.account_name):
+                return HTTPServerError(request=req)
             account_partition, accounts, container_count = \
                 self.account_info(self.account_name, req)
         if not accounts:
diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py
index 175c5b318e..43b9e38c4d 100644
--- a/test/unit/proxy/test_server.py
+++ b/test/unit/proxy/test_server.py
@@ -7782,7 +7782,7 @@ class TestContainerController(unittest.TestCase):
             # fail to retrieve account info
             test_status_map(
                 (503, 503, 503),  # account_info fails on 503
-                404, missing_container=True)
+                500, missing_container=True)
             # account fail after creation
             test_status_map(
                 (404, 404, 404,   # account_info fails on 404
@@ -7793,7 +7793,7 @@ class TestContainerController(unittest.TestCase):
                 (503, 503, 404,   # account_info fails on 404
                  503, 503, 503,   # PUT account
                  503, 503, 404),  # account_info fail
-                404, missing_container=True)
+                500, missing_container=True)
             # put fails
             test_status_map(
                 (404, 404, 404,   # account_info fails on 404