From 8ea7bd718da2f0b69cd607291affdc2e75ad60a1 Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Sat, 21 Jun 2014 19:45:21 +0530 Subject: [PATCH] Support Storage Policy - Rev 5 * Sync to Swift 2.0.0rc1 release. * Use separate conf files for functional tests * Define swiftonfile as policy with index 2 Signed-off-by: Prashanth Pai --- .functests | 12 ++++++------ etc/swift.conf-gluster | 21 ++++++++++++++++----- test/functional/__init__.py | 16 +++++++--------- test/functional/conf/swift.conf | 21 +++++++++++++++++++++ {etc => test/functional/conf}/test.conf | 0 test/functional/swift_on_file_tests.py | 4 +--- test/functional/tests.py | 14 +++++++++++++- tox.ini | 2 +- 8 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 test/functional/conf/swift.conf rename {etc => test/functional/conf}/test.conf (100%) diff --git a/.functests b/.functests index 9add968..7294cf1 100755 --- a/.functests +++ b/.functests @@ -80,15 +80,15 @@ print "Invoking SAIO's remakerings script" remakerings print "Copying conf files into /etc/swift. This will replace swift.conf and test.conf" -cp etc/object-server.conf-gluster /etc/swift/object-server/5.conf -cp etc/swift.conf-gluster /etc/swift/swift.conf -cp etc/test.conf /etc/swift/test.conf +\cp etc/object-server.conf-gluster /etc/swift/object-server/5.conf +\cp test/functional/conf/swift.conf /etc/swift/swift.conf +\cp test/functional/conf/test.conf /etc/swift/test.conf print "Generating additional object-rings for swiftonfile SP" cd /etc/swift -swift-ring-builder object-1.builder create 1 1 1 -swift-ring-builder object-1.builder add r1z1-127.0.0.1:6050/test 1 -swift-ring-builder object-1.builder rebalance +swift-ring-builder object-2.builder create 1 1 1 +swift-ring-builder object-2.builder add r1z1-127.0.0.1:6050/test 1 +swift-ring-builder object-2.builder rebalance cd - export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf diff --git a/etc/swift.conf-gluster b/etc/swift.conf-gluster index 4e9fd0b..02fa8d3 100644 --- a/etc/swift.conf-gluster +++ b/etc/swift.conf-gluster @@ -24,15 +24,26 @@ swift_hash_path_prefix = changeme # storage-policy:0. [storage-policy:0] name = Policy-0 -# default = yes -# Default has beeen turned off here and set for policy-1 for running SoF -# functional tests. +default = yes + +# the following section would declare a policy called 'silver', the number of +# replicas will be determined by how the ring is built. In this example the +# 'silver' policy could have a lower or higher # of replicas than the +# 'Policy-0' policy above. The ring filename will be 'object-1.ring.gz'. You +# may only specify one storage policy section as the default. If you changed +# this section to specify 'silver' as the default, when a client created a new +# container w/o a policy specified, it will get the 'silver' policy because +# this config has specified it as the default. However if a legacy container +# (one created with a pre-policy version of swift) is accessed, it is known +# implicitly to be assigned to the policy with index 0 as opposed to the +# current default. +#[storage-policy:1] +#name = silver # The following section defines a policy called 'sof' to be used by swiftonfile # object-server implementation. -[storage-policy:1] +[storage-policy:2] name = sof -default = yes # The swift-constraints section sets the basic constraints on data # saved in the swift cluster. These constraints are automatically diff --git a/test/functional/__init__.py b/test/functional/__init__.py index 3e6f968..fb9f421 100644 --- a/test/functional/__init__.py +++ b/test/functional/__init__.py @@ -38,7 +38,7 @@ from test.functional.swift_test_client import Connection, ResponseError # on file systems that don't support extended attributes. from test.unit import debug_logger, FakeMemcache -from swift.common import constraints, utils, ring +from swift.common import constraints, utils, ring, storage_policy from swift.common.wsgi import monkey_patch_mimetools from swift.common.middleware import catch_errors, gatekeeper, healthcheck, \ proxy_logging, container_sync, bulk, tempurl, slo, dlo, ratelimit, \ @@ -152,6 +152,8 @@ def in_process_setup(the_object_server=object_server): orig_swift_conf_name = utils.SWIFT_CONF_FILE utils.SWIFT_CONF_FILE = swift_conf constraints.reload_constraints() + storage_policy.SWIFT_CONF_FILE = swift_conf + storage_policy.reload_storage_policies() global config if constraints.SWIFT_CONSTRAINTS_LOADED: # Use the swift constraints that are loaded for the test framework @@ -345,7 +347,7 @@ def get_cluster_info(): # test.conf data pass else: - eff_constraints.update(cluster_info['swift']) + eff_constraints.update(cluster_info.get('swift', {})) # Finally, we'll allow any constraint present in the swift-constraints # section of test.conf to override everything. Note that only those @@ -714,18 +716,14 @@ class FunctionalStoragePolicyCollection(object): def requires_policies(f): @functools.wraps(f) def wrapper(self, *args, **kwargs): - rv = None if skip: raise SkipTest try: self.policies = FunctionalStoragePolicyCollection.from_info() - assert len(self.policies) > 1 except AssertionError: + raise SkipTest("Unable to determine available policies") + if len(self.policies) < 2: raise SkipTest("Multiple policies not enabled") - try: - rv = f(self, *args, **kwargs) - except: - raise - return rv + return f(self, *args, **kwargs) return wrapper diff --git a/test/functional/conf/swift.conf b/test/functional/conf/swift.conf new file mode 100644 index 0000000..604cdb0 --- /dev/null +++ b/test/functional/conf/swift.conf @@ -0,0 +1,21 @@ +[swift-hash] +# random unique strings that can never change (DO NOT LOSE) +swift_hash_path_prefix = changeme +swift_hash_path_suffix = changeme + +[storage-policy:0] +name = gold + +[storage-policy:1] +name = silver + +# SwiftOnFile +[storage-policy:2] +name = sof +default = yes + +[swift-constraints] +max_object_name_length = 221 +max_account_name_length = 255 +max_container_name_length = 255 + diff --git a/etc/test.conf b/test/functional/conf/test.conf similarity index 100% rename from etc/test.conf rename to test/functional/conf/test.conf diff --git a/test/functional/swift_on_file_tests.py b/test/functional/swift_on_file_tests.py index eb71ced..bad7fd6 100644 --- a/test/functional/swift_on_file_tests.py +++ b/test/functional/swift_on_file_tests.py @@ -32,9 +32,7 @@ class TestSwiftOnFileEnv: cls.conn.authenticate() cls.account = Account(cls.conn, tf.config.get('account', tf.config['username'])) - cls.root_dir = os.path.join('/mnt/gluster-object', - cls.account.conn.storage_url.split( - '/')[2].split('_')[1]) + cls.root_dir = os.path.join('/mnt/gluster-object/test') cls.account.delete_containers() cls.file_size = 8 diff --git a/test/functional/tests.py b/test/functional/tests.py index 74d6068..4d9179e 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -270,6 +270,19 @@ class TestAccount(Base): self.assertEqual(sorted(containers, cmp=locale.strcoll), containers) + def testQuotedWWWAuthenticateHeader(self): + conn = Connection(tf.config) + conn.authenticate() + inserted_html = 'Hello World' + hax = 'AUTH_haxx"\nContent-Length: %d\n\n%s' % (len(inserted_html), + inserted_html) + quoted_hax = urllib.quote(hax) + conn.connection.request('GET', '/v1/' + quoted_hax, None, {}) + resp = conn.connection.getresponse() + resp_headers = resp.getheaders() + expected = ('www-authenticate', 'Swift realm="%s"' % quoted_hax) + self.assert_(expected in resp_headers) + class TestAccountUTF8(Base2, TestAccount): set_up = False @@ -2199,7 +2212,6 @@ class TestTempurlEnv(object): cls.tempurl_enabled = 'tempurl' in cluster_info if not cls.tempurl_enabled: return - cls.tempurl_methods = cluster_info['tempurl']['methods'] cls.tempurl_key = Utils.create_name() cls.tempurl_key2 = Utils.create_name() diff --git a/tox.ini b/tox.ini index 6e3c136..bb954bf 100644 --- a/tox.ini +++ b/tox.ini @@ -21,7 +21,7 @@ setenv = VIRTUAL_ENV={envdir} deps = # GitHub's .zip URL won't work! pip supports installing from git repos. # https://pip.pypa.io/en/latest/reference/pip_install.html#git - git+https://github.com/openstack/swift.git@feature/ec + git+https://github.com/openstack/swift.git@2.0.0.rc1 -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt changedir = {toxinidir}/test/unit