Skip to content

Instantly share code, notes, and snippets.

@clayg
Created March 20, 2014 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayg/9655076 to your computer and use it in GitHub Desktop.
Save clayg/9655076 to your computer and use it in GitHub Desktop.
diff --git a/swift/container/server.py b/swift/container/server.py
index a7314b8..49deb30 100644
--- a/swift/container/server.py
+++ b/swift/container/server.py
@@ -326,7 +326,7 @@ class ContainerController(object):
# We've just revived a deleted container: the database is
# there, but it was marked deleted. We need to update its
# storage policy index.
- broker.set_storage_policy_index(requested_policy_index)
+ broker.set_storage_policy_index(new_container_policy)
metadata = {}
metadata.update(
(key, (value, timestamp))
diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py
index 81f7c46..224955d 100644
--- a/test/unit/container/test_server.py
+++ b/test/unit/container/test_server.py
@@ -32,7 +32,7 @@ import swift.container
from swift.container import server as container_server
from swift.common.utils import normalize_timestamp, mkdirs, public, replication
from test.unit import fake_http_connect
-from swift.common.storage_policy import StoragePolicy, POLICY_INDEX
+from swift.common.storage_policy import StoragePolicy, POLICY_INDEX, POLICIES
from swift.common.request_helpers import get_sys_meta_prefix
from test.unit import patch_policies
@@ -934,6 +934,39 @@ class TestContainerController(unittest.TestCase):
resp = req.get_response(self.controller)
self.assertEqual(resp.headers['X-Storage-Policy-Index'], '2')
+ def test_default_storage_policy_via_DELETE_then_PUT(self):
+ req = Request.blank(
+ '/sda1/p/a/c',
+ environ={'REQUEST_METHOD': 'PUT'},
+ headers={'X-Timestamp': '100',
+ 'X-Storage-Policy-Index': '2'})
+ resp = req.get_response(self.controller)
+ self.assertEqual(resp.status_int, 201) # sanity check
+
+ req = Request.blank(
+ '/sda1/p/a/c',
+ environ={'REQUEST_METHOD': 'DELETE'},
+ headers={'X-Timestamp': '200'})
+ resp = req.get_response(self.controller)
+ self.assertEqual(resp.status_int, 204) # sanity check
+
+ # at this point, the DB should still exist but be in a deleted state,
+ # so changing the policy index is perfectly acceptable
+ req = Request.blank(
+ '/sda1/p/a/c',
+ environ={'REQUEST_METHOD': 'PUT'},
+ headers={'X-Timestamp': '300'})
+ resp = req.get_response(self.controller)
+ self.assertEqual(resp.status_int, 201) # sanity check
+
+ req = Request.blank(
+ '/sda1/p/a/c',
+ environ={'REQUEST_METHOD': 'HEAD'},
+ headers={'X-Timestamp': '400'})
+ resp = req.get_response(self.controller)
+ self.assertEqual(resp.headers[POLICY_INDEX],
+ str(POLICIES.default.idx))
+
def test_DELETE_object(self):
req = Request.blank(
'/sda1/p/a/c',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment