fdd4bcf
From fc2421b04022ac6bbe9d5014362ec5f99f94c5e0 Mon Sep 17 00:00:00 2001
fdd4bcf
From: Peter Portante <peter.portante@redhat.com>
fdd4bcf
Date: Tue, 25 Sep 2012 13:27:59 -0400
fdd4bcf
Subject: [PATCH] Backport commit a2ac5efaa64f57fbbe059066c6c4636dfd0715c2,
fdd4bcf
 'swift constraints are now settable via config', excluding
fdd4bcf
 PEP8 changes that did not involve the constraints.
fdd4bcf
fdd4bcf
---
fdd4bcf
 etc/swift.conf-sample                |   73 ++++++++++++++++++++++++++++++++++
fdd4bcf
 swift/common/constraints.py          |   37 ++++++++++++-----
fdd4bcf
 test/functional/tests.py             |   62 ++++++++++++++++++++++++----
fdd4bcf
 test/unit/common/test_constraints.py |    9 +++-
fdd4bcf
 test/unit/obj/test_server.py         |    7 ++-
fdd4bcf
 test/unit/proxy/test_server.py       |   50 ++++++++++++++---------
fdd4bcf
 6 files changed, 196 insertions(+), 42 deletions(-)
fdd4bcf
fdd4bcf
diff --git a/etc/swift.conf-sample b/etc/swift.conf-sample
fdd4bcf
index 7e1c31d..2f4192a 100644
fdd4bcf
--- a/etc/swift.conf-sample
fdd4bcf
+++ b/etc/swift.conf-sample
fdd4bcf
@@ -1,3 +1,76 @@
fdd4bcf
 [swift-hash]
fdd4bcf
+
fdd4bcf
+# swift_hash_path_suffix is used as part of the hashing algorithm
fdd4bcf
+# when determining data placement in the cluster. This value should
fdd4bcf
+# remain secret and MUST NOT change once a cluster has been deployed.
fdd4bcf
+
fdd4bcf
 swift_hash_path_suffix = changeme
fdd4bcf
 
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# The swift-constraints section sets the basic constraints on data
fdd4bcf
+# saved in the swift cluster.
fdd4bcf
+
fdd4bcf
+[swift-constraints]
fdd4bcf
+
fdd4bcf
+# max_file_size is the largest "normal" object that can be saved in
fdd4bcf
+# the cluster. This is also the limit on the size of each segment of
fdd4bcf
+# a "large" object when using the large object manifest support.
fdd4bcf
+# This value is set in bytes. Setting it to lower than 1MiB will cause
fdd4bcf
+# some tests to fail. It is STRONGLY recommended to leave this value at
fdd4bcf
+# the default (5 * 2**30 + 2).
fdd4bcf
+
fdd4bcf
+#max_file_size = 5368709122
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# max_meta_name_length is the max number of bytes in the utf8 encoding
fdd4bcf
+# of the name portion of a metadata header.
fdd4bcf
+
fdd4bcf
+#max_meta_name_length = 128
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# max_meta_value_length is the max number of bytes in the utf8 encoding
fdd4bcf
+# of a metadata value
fdd4bcf
+
fdd4bcf
+#max_meta_value_length = 256
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# max_meta_count is the max number of metadata keys that can be stored
fdd4bcf
+# on a single account, container, or object
fdd4bcf
+
fdd4bcf
+#max_meta_count = 90
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# max_meta_overall_size is the max number of bytes in the utf8 encoding
fdd4bcf
+# of the metadata (keys + values)
fdd4bcf
+
fdd4bcf
+#max_meta_overall_size = 4096
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# max_object_name_length is the max number of bytes in the utf8 encoding
fdd4bcf
+# of an object name
fdd4bcf
+
fdd4bcf
+#max_object_name_length = 1024
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# container_listing_limit is the default (and max) number of items
fdd4bcf
+# returned for a container listing request
fdd4bcf
+
fdd4bcf
+#container_listing_limit = 10000
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# account_listing_limit is the default (and max) number of items returned
fdd4bcf
+# for an account listing request
fdd4bcf
+#account_listing_limit = 10000
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# max_account_name_length is the max number of bytes in the utf8 encoding
fdd4bcf
+# of an account name
fdd4bcf
+
fdd4bcf
+#max_account_name_length = 256
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+# max_container_name_length is the max number of bytes in the utf8 encoding
fdd4bcf
+# of a container name
fdd4bcf
+
fdd4bcf
+#max_container_name_length = 256
fdd4bcf
diff --git a/swift/common/constraints.py b/swift/common/constraints.py
fdd4bcf
index 235dcca..0fe5078 100644
fdd4bcf
--- a/swift/common/constraints.py
fdd4bcf
+++ b/swift/common/constraints.py
fdd4bcf
@@ -14,29 +14,46 @@
fdd4bcf
 # limitations under the License.
fdd4bcf
 
fdd4bcf
 import os
fdd4bcf
+from ConfigParser import ConfigParser, NoSectionError, NoOptionError, \
fdd4bcf
+    RawConfigParser
fdd4bcf
 
fdd4bcf
 from webob.exc import HTTPBadRequest, HTTPLengthRequired, \
fdd4bcf
     HTTPRequestEntityTooLarge
fdd4bcf
 
fdd4bcf
+constraints_conf = ConfigParser()
fdd4bcf
+constraints_conf.read('/etc/swift/swift.conf')
fdd4bcf
+
fdd4bcf
+
fdd4bcf
+def constraints_conf_int(name, default):
fdd4bcf
+    try:
fdd4bcf
+        return int(constraints_conf.get('swift-constraints', name))
fdd4bcf
+    except (NoSectionError, NoOptionError):
fdd4bcf
+        return default
fdd4bcf
+
fdd4bcf
 
fdd4bcf
 #: Max file size allowed for objects
fdd4bcf
-MAX_FILE_SIZE = 5 * 1024 * 1024 * 1024 + 2
fdd4bcf
+MAX_FILE_SIZE = constraints_conf_int('max_file_size',
fdd4bcf
+                                     5368709122)  # 5 * 1024 * 1024 * 1024 + 2
fdd4bcf
 #: Max length of the name of a key for metadata
fdd4bcf
-MAX_META_NAME_LENGTH = 128
fdd4bcf
+MAX_META_NAME_LENGTH = constraints_conf_int('max_meta_name_length', 128)
fdd4bcf
 #: Max length of the value of a key for metadata
fdd4bcf
-MAX_META_VALUE_LENGTH = 256
fdd4bcf
+MAX_META_VALUE_LENGTH = constraints_conf_int('max_meta_value_length', 256)
fdd4bcf
 #: Max number of metadata items
fdd4bcf
-MAX_META_COUNT = 90
fdd4bcf
+MAX_META_COUNT = constraints_conf_int('max_meta_count', 90)
fdd4bcf
 #: Max overall size of metadata
fdd4bcf
-MAX_META_OVERALL_SIZE = 4096
fdd4bcf
+MAX_META_OVERALL_SIZE = constraints_conf_int('max_meta_overall_size', 4096)
fdd4bcf
 #: Max object name length
fdd4bcf
-MAX_OBJECT_NAME_LENGTH = 1024
fdd4bcf
+MAX_OBJECT_NAME_LENGTH = constraints_conf_int('max_object_name_length', 1024)
fdd4bcf
 #: Max object list length of a get request for a container
fdd4bcf
-CONTAINER_LISTING_LIMIT = 10000
fdd4bcf
+CONTAINER_LISTING_LIMIT = constraints_conf_int('container_listing_limit',
fdd4bcf
+                                               10000)
fdd4bcf
 #: Max container list length of a get request for an account
fdd4bcf
-ACCOUNT_LISTING_LIMIT = 10000
fdd4bcf
-MAX_ACCOUNT_NAME_LENGTH = 256
fdd4bcf
-MAX_CONTAINER_NAME_LENGTH = 256
fdd4bcf
+ACCOUNT_LISTING_LIMIT = constraints_conf_int('account_listing_limit', 10000)
fdd4bcf
+#: Max account name length
fdd4bcf
+MAX_ACCOUNT_NAME_LENGTH = constraints_conf_int('max_account_name_length', 256)
fdd4bcf
+#: Max container name length
fdd4bcf
+MAX_CONTAINER_NAME_LENGTH = constraints_conf_int('max_container_name_length',
fdd4bcf
+                                                 256)
fdd4bcf
 
fdd4bcf
 
fdd4bcf
 def check_metadata(req, target_type):
fdd4bcf
diff --git a/test/functional/tests.py b/test/functional/tests.py
fdd4bcf
index b25b4fd..3b18fc4 100644
fdd4bcf
--- a/test/functional/tests.py
fdd4bcf
+++ b/test/functional/tests.py
fdd4bcf
@@ -27,12 +27,55 @@ import threading
fdd4bcf
 import uuid
fdd4bcf
 import unittest
fdd4bcf
 import urllib
fdd4bcf
+from ConfigParser import ConfigParser
fdd4bcf
 
fdd4bcf
 from test import get_config
fdd4bcf
 from swift import Account, AuthenticationFailed, Connection, Container, \
fdd4bcf
      File, ResponseError
fdd4bcf
-
fdd4bcf
+from swift.common.constraints import MAX_FILE_SIZE, MAX_META_NAME_LENGTH, \
fdd4bcf
+    MAX_META_VALUE_LENGTH, MAX_META_COUNT, MAX_META_OVERALL_SIZE, \
fdd4bcf
+    MAX_OBJECT_NAME_LENGTH, CONTAINER_LISTING_LIMIT, ACCOUNT_LISTING_LIMIT, \
fdd4bcf
+    MAX_ACCOUNT_NAME_LENGTH, MAX_CONTAINER_NAME_LENGTH
fdd4bcf
+
fdd4bcf
+default_constraints = dict((
fdd4bcf
+    ('max_file_size', MAX_FILE_SIZE),
fdd4bcf
+    ('max_meta_name_length', MAX_META_NAME_LENGTH),
fdd4bcf
+    ('max_meta_value_length', MAX_META_VALUE_LENGTH),
fdd4bcf
+    ('max_meta_count', MAX_META_COUNT),
fdd4bcf
+    ('max_meta_overall_size', MAX_META_OVERALL_SIZE),
fdd4bcf
+    ('max_object_name_length', MAX_OBJECT_NAME_LENGTH),
fdd4bcf
+    ('container_listing_limit', CONTAINER_LISTING_LIMIT),
fdd4bcf
+    ('account_listing_limit', ACCOUNT_LISTING_LIMIT),
fdd4bcf
+    ('max_account_name_length', MAX_ACCOUNT_NAME_LENGTH),
fdd4bcf
+    ('max_container_name_length', MAX_CONTAINER_NAME_LENGTH)))
fdd4bcf
+constraints_conf = ConfigParser()
fdd4bcf
+conf_exists = constraints_conf.read('/etc/swift/swift.conf')
fdd4bcf
+# Constraints are set first from the test config, then from
fdd4bcf
+# /etc/swift/swift.conf if it exists. If swift.conf doesn't exist,
fdd4bcf
+# then limit test coverage. This allows SAIO tests to work fine but
fdd4bcf
+# requires remote funtional testing to know something about the cluster
fdd4bcf
+# that is being tested.
fdd4bcf
 config = get_config()
fdd4bcf
+for k in default_constraints:
fdd4bcf
+    if k in config:
fdd4bcf
+        # prefer what's in test.conf
fdd4bcf
+        config[k] = int(config[k])
fdd4bcf
+    elif conf_exists:
fdd4bcf
+        # swift.conf exists, so use what's defined there (or swift defaults)
fdd4bcf
+        # This normally happens when the test is running locally to the cluster
fdd4bcf
+        # as in a SAIO.
fdd4bcf
+        config[k] = default_constraints[k]
fdd4bcf
+    else:
fdd4bcf
+        # .functests don't know what the constraints of the tested cluster are,
fdd4bcf
+        # so the tests can't reliably pass or fail. Therefore, skip those
fdd4bcf
+        # tests.
fdd4bcf
+        config[k] = '%s constraint is not defined' % k
fdd4bcf
+
fdd4bcf
+def load_constraint(name):
fdd4bcf
+    c = config[name]
fdd4bcf
+    if not isinstance(c, int):
fdd4bcf
+        raise SkipTest(c)
fdd4bcf
+    return c
fdd4bcf
 
fdd4bcf
 locale.setlocale(locale.LC_COLLATE, config.get('collate', 'C'))
fdd4bcf
 
fdd4bcf
@@ -233,7 +276,7 @@ class TestAccount(Base):
fdd4bcf
                     'application/xml; charset=utf-8')
fdd4bcf
 
fdd4bcf
     def testListingLimit(self):
fdd4bcf
-        limit = 10000
fdd4bcf
+        limit = load_constraint('account_listing_limit')
fdd4bcf
 
fdd4bcf
         for l in (1, 100, limit/2, limit-1, limit, limit+1, limit*2):
fdd4bcf
             p = {'limit':l}
fdd4bcf
@@ -361,7 +404,7 @@ class TestContainer(Base):
fdd4bcf
     set_up = False
fdd4bcf
 
fdd4bcf
     def testContainerNameLimit(self):
fdd4bcf
-        limit = 256
fdd4bcf
+        limit = load_constraint('max_container_name_length')
fdd4bcf
 
fdd4bcf
         for l in (limit-100, limit-10, limit-1, limit,
fdd4bcf
             limit+1, limit+10, limit+100):
fdd4bcf
@@ -406,6 +449,7 @@ class TestContainer(Base):
fdd4bcf
             self.assert_(cont.files(parms={'prefix': f}) == [f])
fdd4bcf
 
fdd4bcf
     def testPrefixAndLimit(self):
fdd4bcf
+        load_constraint('container_listing_limit')
fdd4bcf
         cont = self.env.account.container(Utils.create_name())
fdd4bcf
         self.assert_(cont.create())
fdd4bcf
 
fdd4bcf
@@ -949,7 +993,7 @@ class TestFile(Base):
fdd4bcf
             self.assert_status(404)
fdd4bcf
 
fdd4bcf
     def testNameLimit(self):
fdd4bcf
-        limit = 1024
fdd4bcf
+        limit = load_constraint('max_object_name_length')
fdd4bcf
 
fdd4bcf
         for l in (1, 10, limit/2, limit-1, limit, limit+1, limit*2):
fdd4bcf
             file = self.env.container.file('a'*l)
fdd4bcf
@@ -997,13 +1041,12 @@ class TestFile(Base):
fdd4bcf
         self.assert_status(400)
fdd4bcf
 
fdd4bcf
     def testMetadataNumberLimit(self):
fdd4bcf
-        number_limit = 90
fdd4bcf
+        number_limit = load_constraint('max_meta_count')
fdd4bcf
+        size_limit = load_constraint('max_meta_overall_size')
fdd4bcf
 
fdd4bcf
         for i in (number_limit-10, number_limit-1, number_limit,
fdd4bcf
             number_limit+1, number_limit+10, number_limit+100):
fdd4bcf
 
fdd4bcf
-            size_limit = 4096
fdd4bcf
-
fdd4bcf
             j = size_limit/(i * 2)
fdd4bcf
 
fdd4bcf
             size = 0
fdd4bcf
@@ -1093,7 +1136,7 @@ class TestFile(Base):
fdd4bcf
             self.assert_(file.read(hdrs={'Range': r}) == data[0:1000])
fdd4bcf
 
fdd4bcf
     def testFileSizeLimit(self):
fdd4bcf
-        limit = 5*2**30 + 2
fdd4bcf
+        limit = load_constraint('max_file_size')
fdd4bcf
         tsecs = 3
fdd4bcf
 
fdd4bcf
         for i in (limit-100, limit-10, limit-1, limit, limit+1, limit+10,
fdd4bcf
@@ -1147,7 +1190,8 @@ class TestFile(Base):
fdd4bcf
         self.assert_status(200)
fdd4bcf
 
fdd4bcf
     def testMetadataLengthLimits(self):
fdd4bcf
-        key_limit, value_limit = 128, 256
fdd4bcf
+        key_limit = load_constraint('max_meta_name_length')
fdd4bcf
+        value_limit = load_constraint('max_meta_value_length')
fdd4bcf
         lengths = [[key_limit, value_limit], [key_limit, value_limit+1], \
fdd4bcf
             [key_limit+1, value_limit], [key_limit, 0], \
fdd4bcf
             [key_limit, value_limit*10], [key_limit*10, value_limit]] 
fdd4bcf
diff --git a/test/unit/common/test_constraints.py b/test/unit/common/test_constraints.py
fdd4bcf
index 478b2a8..4b0c997 100644
fdd4bcf
--- a/test/unit/common/test_constraints.py
fdd4bcf
+++ b/test/unit/common/test_constraints.py
fdd4bcf
@@ -84,8 +84,13 @@ class TestConstraints(unittest.TestCase):
fdd4bcf
             x += 1
fdd4bcf
         self.assertEquals(constraints.check_metadata(Request.blank('/',
fdd4bcf
             headers=headers), 'object'), None)
fdd4bcf
-        headers['X-Object-Meta-9999%s' %
fdd4bcf
-                ('a' * (constraints.MAX_META_NAME_LENGTH - 4))] = \
fdd4bcf
+        # add two more headers in case adding just one falls exactly on the
fdd4bcf
+        # limit (eg one header adds 1024 and the limit is 2048)
fdd4bcf
+        headers['X-Object-Meta-%04d%s' %
fdd4bcf
+                (x, 'a' * (constraints.MAX_META_NAME_LENGTH - 4))] = \
fdd4bcf
+                    'v' * constraints.MAX_META_VALUE_LENGTH
fdd4bcf
+        headers['X-Object-Meta-%04d%s' %
fdd4bcf
+                (x + 1, 'a' * (constraints.MAX_META_NAME_LENGTH - 4))] = \
fdd4bcf
                     'v' * constraints.MAX_META_VALUE_LENGTH
fdd4bcf
         self.assert_(isinstance(constraints.check_metadata(Request.blank('/',
fdd4bcf
             headers=headers), 'object'), HTTPBadRequest))
fdd4bcf
diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py
fdd4bcf
index 075700e..5160830 100644
fdd4bcf
--- a/test/unit/obj/test_server.py
fdd4bcf
+++ b/test/unit/obj/test_server.py
fdd4bcf
@@ -38,6 +38,7 @@ from swift.common import utils
fdd4bcf
 from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \
fdd4bcf
                                NullLogger, storage_directory
fdd4bcf
 from swift.common.exceptions import DiskFileNotExist
fdd4bcf
+from swift.common import constraints
fdd4bcf
 from swift.obj import replicator
fdd4bcf
 from eventlet import tpool
fdd4bcf
 
fdd4bcf
@@ -1355,7 +1356,9 @@ class TestObjectController(unittest.TestCase):
fdd4bcf
 
fdd4bcf
     def test_max_object_name_length(self):
fdd4bcf
         timestamp = normalize_timestamp(time())
fdd4bcf
-        req = Request.blank('/sda1/p/a/c/' + ('1' * 1024),
fdd4bcf
+        max_name_len = constraints.MAX_OBJECT_NAME_LENGTH
fdd4bcf
+        req = Request.blank('/sda1/p/a/c/' + ('1' * max_name_len),
fdd4bcf
+
fdd4bcf
                 environ={'REQUEST_METHOD': 'PUT'},
fdd4bcf
                 headers={'X-Timestamp': timestamp,
fdd4bcf
                          'Content-Length': '4',
fdd4bcf
@@ -1363,7 +1366,7 @@ class TestObjectController(unittest.TestCase):
fdd4bcf
         req.body = 'DATA'
fdd4bcf
         resp = self.object_controller.PUT(req)
fdd4bcf
         self.assertEquals(resp.status_int, 201)
fdd4bcf
-        req = Request.blank('/sda1/p/a/c/' + ('2' * 1025),
fdd4bcf
+        req = Request.blank('/sda1/p/a/c/' + ('2' * (max_name_len + 1)),
fdd4bcf
                 environ={'REQUEST_METHOD': 'PUT'},
fdd4bcf
                 headers={'X-Timestamp': timestamp,
fdd4bcf
                          'Content-Length': '4',
fdd4bcf
diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py
fdd4bcf
index 364370e..d28f604 100644
fdd4bcf
--- a/test/unit/proxy/test_server.py
fdd4bcf
+++ b/test/unit/proxy/test_server.py
fdd4bcf
@@ -45,7 +45,8 @@ from swift.container import server as container_server
fdd4bcf
 from swift.obj import server as object_server
fdd4bcf
 from swift.common import ring
fdd4bcf
 from swift.common.constraints import MAX_META_NAME_LENGTH, \
fdd4bcf
-    MAX_META_VALUE_LENGTH, MAX_META_COUNT, MAX_META_OVERALL_SIZE, MAX_FILE_SIZE
fdd4bcf
+    MAX_META_VALUE_LENGTH, MAX_META_COUNT, MAX_META_OVERALL_SIZE, \
fdd4bcf
+    MAX_FILE_SIZE, MAX_ACCOUNT_NAME_LENGTH, MAX_CONTAINER_NAME_LENGTH
fdd4bcf
 from swift.common.utils import mkdirs, normalize_timestamp, NullLogger
fdd4bcf
 from swift.common.wsgi import monkey_patch_mimetools
fdd4bcf
 
fdd4bcf
@@ -1168,6 +1169,7 @@ class TestObjectController(unittest.TestCase):
fdd4bcf
 
fdd4bcf
     def test_POST_meta_val_len(self):
fdd4bcf
         with save_globals():
fdd4bcf
+            limit = MAX_META_VALUE_LENGTH
fdd4bcf
             self.app.object_post_as_copy = False
fdd4bcf
             controller = proxy_server.ObjectController(self.app, 'account',
fdd4bcf
                 'container', 'object')
fdd4bcf
@@ -1175,42 +1177,44 @@ class TestObjectController(unittest.TestCase):
fdd4bcf
                 fake_http_connect(200, 200, 202, 202, 202)
fdd4bcf
                 #                 acct cont obj  obj  obj
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers={
fdd4bcf
-                                            'Content-Type': 'foo/bar',
fdd4bcf
-                                            'X-Object-Meta-Foo': 'x' * 256})
fdd4bcf
+                                'Content-Type': 'foo/bar',
fdd4bcf
+                                'X-Object-Meta-Foo': 'x' * limit})
fdd4bcf
             self.app.update_request(req)
fdd4bcf
             res = controller.POST(req)
fdd4bcf
             self.assertEquals(res.status_int, 202)
fdd4bcf
             proxy_server.http_connect = fake_http_connect(202, 202, 202)
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers={
fdd4bcf
-                                            'Content-Type': 'foo/bar',
fdd4bcf
-                                            'X-Object-Meta-Foo': 'x' * 257})
fdd4bcf
+                                'Content-Type': 'foo/bar',
fdd4bcf
+                                'X-Object-Meta-Foo': 'x' * (limit + 1)})
fdd4bcf
             self.app.update_request(req)
fdd4bcf
             res = controller.POST(req)
fdd4bcf
             self.assertEquals(res.status_int, 400)
fdd4bcf
 
fdd4bcf
     def test_POST_as_copy_meta_val_len(self):
fdd4bcf
         with save_globals():
fdd4bcf
+            limit = MAX_META_VALUE_LENGTH
fdd4bcf
             controller = proxy_server.ObjectController(self.app, 'account',
fdd4bcf
                 'container', 'object')
fdd4bcf
             proxy_server.http_connect = \
fdd4bcf
                 fake_http_connect(200, 200, 200, 200, 200, 202, 202, 202)
fdd4bcf
                 #                 acct cont objc objc objc obj  obj  obj
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers={
fdd4bcf
-                                            'Content-Type': 'foo/bar',
fdd4bcf
-                                            'X-Object-Meta-Foo': 'x' * 256})
fdd4bcf
+                                'Content-Type': 'foo/bar',
fdd4bcf
+                                'X-Object-Meta-Foo': 'x' * limit})
fdd4bcf
             self.app.update_request(req)
fdd4bcf
             res = controller.POST(req)
fdd4bcf
             self.assertEquals(res.status_int, 202)
fdd4bcf
             proxy_server.http_connect = fake_http_connect(202, 202, 202)
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers={
fdd4bcf
-                                            'Content-Type': 'foo/bar',
fdd4bcf
-                                            'X-Object-Meta-Foo': 'x' * 257})
fdd4bcf
+                                'Content-Type': 'foo/bar',
fdd4bcf
+                                'X-Object-Meta-Foo': 'x' * (limit + 1)})
fdd4bcf
             self.app.update_request(req)
fdd4bcf
             res = controller.POST(req)
fdd4bcf
             self.assertEquals(res.status_int, 400)
fdd4bcf
 
fdd4bcf
     def test_POST_meta_key_len(self):
fdd4bcf
         with save_globals():
fdd4bcf
+            limit = MAX_META_NAME_LENGTH
fdd4bcf
             self.app.object_post_as_copy = False
fdd4bcf
             controller = proxy_server.ObjectController(self.app, 'account',
fdd4bcf
                 'container', 'object')
fdd4bcf
@@ -1219,20 +1223,21 @@ class TestObjectController(unittest.TestCase):
fdd4bcf
                 #                 acct cont obj  obj  obj
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers={
fdd4bcf
                 'Content-Type': 'foo/bar',
fdd4bcf
-                ('X-Object-Meta-' + 'x' * 128): 'x'})
fdd4bcf
+                ('X-Object-Meta-' + 'x' * limit): 'x'})
fdd4bcf
             self.app.update_request(req)
fdd4bcf
             res = controller.POST(req)
fdd4bcf
             self.assertEquals(res.status_int, 202)
fdd4bcf
             proxy_server.http_connect = fake_http_connect(202, 202, 202)
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers={
fdd4bcf
                 'Content-Type': 'foo/bar',
fdd4bcf
-                ('X-Object-Meta-' + 'x' * 129): 'x'})
fdd4bcf
+                ('X-Object-Meta-' + 'x' * (limit + 1)): 'x'})
fdd4bcf
             self.app.update_request(req)
fdd4bcf
             res = controller.POST(req)
fdd4bcf
             self.assertEquals(res.status_int, 400)
fdd4bcf
 
fdd4bcf
     def test_POST_as_copy_meta_key_len(self):
fdd4bcf
         with save_globals():
fdd4bcf
+            limit = MAX_META_NAME_LENGTH
fdd4bcf
             controller = proxy_server.ObjectController(self.app, 'account',
fdd4bcf
                 'container', 'object')
fdd4bcf
             proxy_server.http_connect = \
fdd4bcf
@@ -1240,24 +1245,25 @@ class TestObjectController(unittest.TestCase):
fdd4bcf
                 #                 acct cont objc objc objc obj  obj  obj
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers={
fdd4bcf
                 'Content-Type': 'foo/bar',
fdd4bcf
-                ('X-Object-Meta-' + 'x' * 128): 'x'})
fdd4bcf
+                ('X-Object-Meta-' + 'x' * limit): 'x'})
fdd4bcf
             self.app.update_request(req)
fdd4bcf
             res = controller.POST(req)
fdd4bcf
             self.assertEquals(res.status_int, 202)
fdd4bcf
             proxy_server.http_connect = fake_http_connect(202, 202, 202)
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers={
fdd4bcf
                 'Content-Type': 'foo/bar',
fdd4bcf
-                ('X-Object-Meta-' + 'x' * 129): 'x'})
fdd4bcf
+                ('X-Object-Meta-' + 'x' * (limit + 1)): 'x'})
fdd4bcf
             self.app.update_request(req)
fdd4bcf
             res = controller.POST(req)
fdd4bcf
             self.assertEquals(res.status_int, 400)
fdd4bcf
 
fdd4bcf
     def test_POST_meta_count(self):
fdd4bcf
         with save_globals():
fdd4bcf
+            limit = MAX_META_COUNT
fdd4bcf
             controller = proxy_server.ObjectController(self.app, 'account',
fdd4bcf
                 'container', 'object')
fdd4bcf
             headers = dict(
fdd4bcf
-                (('X-Object-Meta-' + str(i), 'a') for i in xrange(91)))
fdd4bcf
+                (('X-Object-Meta-' + str(i), 'a') for i in xrange(limit + 1)))
fdd4bcf
             headers.update({'Content-Type': 'foo/bar'})
fdd4bcf
             proxy_server.http_connect = fake_http_connect(202, 202, 202)
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers=headers)
fdd4bcf
@@ -1267,10 +1273,13 @@ class TestObjectController(unittest.TestCase):
fdd4bcf
 
fdd4bcf
     def test_POST_meta_size(self):
fdd4bcf
         with save_globals():
fdd4bcf
+            limit = MAX_META_OVERALL_SIZE
fdd4bcf
             controller = proxy_server.ObjectController(self.app, 'account',
fdd4bcf
                 'container', 'object')
fdd4bcf
+            count = limit / 256  # enough to cause the limit to be reched
fdd4bcf
             headers = dict(
fdd4bcf
-                (('X-Object-Meta-' + str(i), 'a' * 256) for i in xrange(1000)))
fdd4bcf
+                (('X-Object-Meta-' + str(i), 'a' * 256)
fdd4bcf
+                    for i in xrange(count + 1)))
fdd4bcf
             headers.update({'Content-Type': 'foo/bar'})
fdd4bcf
             proxy_server.http_connect = fake_http_connect(202, 202, 202)
fdd4bcf
             req = Request.blank('/a/c/o', {}, headers=headers)
fdd4bcf
@@ -3206,13 +3215,14 @@ class TestContainerController(unittest.TestCase):
fdd4bcf
 
fdd4bcf
     def test_PUT_max_container_name_length(self):
fdd4bcf
         with save_globals():
fdd4bcf
+            limit = MAX_CONTAINER_NAME_LENGTH
fdd4bcf
             controller = proxy_server.ContainerController(self.app, 'account',
fdd4bcf
-                                                              '1' * 256)
fdd4bcf
+                                                          '1' * limit)
fdd4bcf
             self.assert_status_map(controller.PUT,
fdd4bcf
                                    (200, 200, 200, 201, 201, 201), 201,
fdd4bcf
                                    missing_container=True)
fdd4bcf
             controller = proxy_server.ContainerController(self.app, 'account',
fdd4bcf
-                                                              '2' * 257)
fdd4bcf
+                                                          '2' * (limit + 1))
fdd4bcf
             self.assert_status_map(controller.PUT, (201, 201, 201), 400,
fdd4bcf
                                    missing_container=True)
fdd4bcf
 
fdd4bcf
@@ -3813,9 +3823,11 @@ class TestAccountController(unittest.TestCase):
fdd4bcf
     def test_PUT_max_account_name_length(self):
fdd4bcf
         with save_globals():
fdd4bcf
             self.app.allow_account_management = True
fdd4bcf
-            controller = proxy_server.AccountController(self.app, '1' * 256)
fdd4bcf
+            limit = MAX_ACCOUNT_NAME_LENGTH
fdd4bcf
+            controller = proxy_server.AccountController(self.app, '1' * limit)
fdd4bcf
             self.assert_status_map(controller.PUT, (201, 201, 201), 201)
fdd4bcf
-            controller = proxy_server.AccountController(self.app, '2' * 257)
fdd4bcf
+            controller = proxy_server.AccountController(
fdd4bcf
+                self.app, '2' * (limit + 1))
fdd4bcf
             self.assert_status_map(controller.PUT, (201, 201, 201), 400)
fdd4bcf
 
fdd4bcf
     def test_PUT_connect_exceptions(self):
fdd4bcf
-- 
fdd4bcf
1.7.7.6
fdd4bcf