diff options
author | venkata edara <redara@redhat.com> | 2017-11-22 13:35:46 +0530 |
---|---|---|
committer | Prashanth Pai <ppai@redhat.com> | 2017-11-22 09:07:11 +0000 |
commit | 488744a005fb399af8d094ad7a62c1917410398c (patch) | |
tree | 714441b43e09061fc339cae6a68de5c26f0fdf52 /test/functional/__init__.py | |
parent | 8af00bf3fa5aa7cd29a53e5e43ea230c196d10b0 (diff) |
Change-Id: I84ebb44c5c3cf2f80c50f2d4ae4bd92b619a4297
Signed-off-by: venkata edara <redara@redhat.com>
Reviewed-on: https://review.gluster.org/18412
Reviewed-by: Prashanth Pai <ppai@redhat.com>
Tested-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'test/functional/__init__.py')
-rw-r--r-- | test/functional/__init__.py | 122 |
1 files changed, 81 insertions, 41 deletions
diff --git a/test/functional/__init__.py b/test/functional/__init__.py index 4d0b71f..3e3c448 100644 --- a/test/functional/__init__.py +++ b/test/functional/__init__.py @@ -39,8 +39,9 @@ from six.moves.http_client import HTTPException from swift.common.middleware.memcache import MemcacheMiddleware from swift.common.storage_policy import parse_storage_policies, PolicyError +from swift.common.utils import set_swift_dir -from test import get_config +from test import get_config, listen_zero from test.functional.swift_test_client import Account, Connection, Container, \ ResponseError # This has the side effect of mocking out the xattr module so that unit tests @@ -106,9 +107,6 @@ skip, skip2, skip3, skip_service_tokens, skip_if_no_reseller_admin = \ orig_collate = '' insecure = False -orig_hash_path_suff_pref = ('', '') -orig_swift_conf_name = None - in_process = False _testdir = _test_servers = _test_coros = _test_socks = None policy_specified = None @@ -259,7 +257,7 @@ def _in_process_setup_ring(swift_conf, conf_src_dir, testdir): device = 'sd%c1' % chr(len(obj_sockets) + ord('a')) utils.mkdirs(os.path.join(_testdir, 'sda1')) utils.mkdirs(os.path.join(_testdir, 'sda1', 'tmp')) - obj_socket = eventlet.listen(('localhost', 0)) + obj_socket = listen_zero() obj_sockets.append(obj_socket) dev['port'] = obj_socket.getsockname()[1] dev['ip'] = '127.0.0.1' @@ -268,16 +266,20 @@ def _in_process_setup_ring(swift_conf, conf_src_dir, testdir): dev['replication_ip'] = dev['ip'] ring_data.save(ring_file_test) else: - # make default test ring, 2 replicas, 4 partitions, 2 devices - _info('No source object ring file, creating 2rep/4part/2dev ring') - obj_sockets = [eventlet.listen(('localhost', 0)) for _ in (0, 1)] - ring_data = ring.RingData( - [[0, 1, 0, 1], [1, 0, 1, 0]], - [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', - 'port': obj_sockets[0].getsockname()[1]}, - {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', - 'port': obj_sockets[1].getsockname()[1]}], - 30) + # make default test ring, 3 replicas, 4 partitions, 3 devices + # which will work for a replication policy or a 2+1 EC policy + _info('No source object ring file, creating 3rep/4part/3dev ring') + obj_sockets = [listen_zero() for _ in (0, 1, 2)] + replica2part2dev_id = [[0, 1, 2, 0], + [1, 2, 0, 1], + [2, 0, 1, 2]] + devs = [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', + 'port': obj_sockets[0].getsockname()[1]}, + {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', + 'port': obj_sockets[1].getsockname()[1]}, + {'id': 2, 'zone': 2, 'device': 'sdc1', 'ip': '127.0.0.1', + 'port': obj_sockets[2].getsockname()[1]}] + ring_data = ring.RingData(replica2part2dev_id, devs, 30) with closing(GzipFile(ring_file_test, 'wb')) as f: pickle.dump(ring_data, f) @@ -287,12 +289,13 @@ def _in_process_setup_ring(swift_conf, conf_src_dir, testdir): return obj_sockets -def _load_encryption(proxy_conf_file, **kwargs): +def _load_encryption(proxy_conf_file, swift_conf_file, **kwargs): """ Load encryption configuration and override proxy-server.conf contents. :param proxy_conf_file: Source proxy conf filename - :returns: Path to the test proxy conf file to use + :param swift_conf_file: Source swift conf filename + :returns: Tuple of paths to the proxy conf file and swift conf file to use :raises InProcessException: raised if proxy conf contents are invalid """ _debug('Setting configuration for encryption') @@ -324,7 +327,43 @@ def _load_encryption(proxy_conf_file, **kwargs): with open(test_conf_file, 'w') as fp: conf.write(fp) - return test_conf_file + return test_conf_file, swift_conf_file + + +def _load_ec_as_default_policy(proxy_conf_file, swift_conf_file, **kwargs): + """ + Override swift.conf [storage-policy:0] section to use a 2+1 EC policy. + + :param proxy_conf_file: Source proxy conf filename + :param swift_conf_file: Source swift conf filename + :returns: Tuple of paths to the proxy conf file and swift conf file to use + """ + _debug('Setting configuration for default EC policy') + + conf = ConfigParser() + conf.read(swift_conf_file) + # remove existing policy sections that came with swift.conf-sample + for section in list(conf.sections()): + if section.startswith('storage-policy'): + conf.remove_section(section) + # add new policy 0 section for an EC policy + conf.add_section('storage-policy:0') + ec_policy_spec = { + 'name': 'ec-test', + 'policy_type': 'erasure_coding', + 'ec_type': 'liberasurecode_rs_vand', + 'ec_num_data_fragments': 2, + 'ec_num_parity_fragments': 1, + 'ec_object_segment_size': 1048576, + 'default': True + } + + for k, v in ec_policy_spec.items(): + conf.set('storage-policy:0', k, str(v)) + + with open(swift_conf_file, 'w') as fp: + conf.write(fp) + return proxy_conf_file, swift_conf_file # Mapping from possible values of the variable @@ -333,7 +372,8 @@ def _load_encryption(proxy_conf_file, **kwargs): # The expected signature for these methods is: # conf_filename_to_use loader(input_conf_filename, **kwargs) conf_loaders = { - 'encryption': _load_encryption + 'encryption': _load_encryption, + 'ec': _load_ec_as_default_policy } @@ -367,6 +407,11 @@ def in_process_setup(the_object_server=object_server): utils.mkdirs(os.path.join(_testdir, 'sda1', 'tmp')) utils.mkdirs(os.path.join(_testdir, 'sdb1')) utils.mkdirs(os.path.join(_testdir, 'sdb1', 'tmp')) + utils.mkdirs(os.path.join(_testdir, 'sdc1')) + utils.mkdirs(os.path.join(_testdir, 'sdc1', 'tmp')) + + swift_conf = _in_process_setup_swift_conf(swift_conf_src, _testdir) + _info('prepared swift.conf: %s' % swift_conf) # Call the associated method for the value of # 'SWIFT_TEST_IN_PROCESS_CONF_LOADER', if one exists @@ -382,21 +427,20 @@ def in_process_setup(the_object_server=object_server): missing_key) try: - # Pass-in proxy_conf - proxy_conf = conf_loader(proxy_conf) + # Pass-in proxy_conf, swift_conf files + proxy_conf, swift_conf = conf_loader(proxy_conf, swift_conf) _debug('Now using proxy conf %s' % proxy_conf) + _debug('Now using swift conf %s' % swift_conf) except Exception as err: # noqa raise InProcessException(err) - swift_conf = _in_process_setup_swift_conf(swift_conf_src, _testdir) obj_sockets = _in_process_setup_ring(swift_conf, conf_src_dir, _testdir) - global orig_swift_conf_name - 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() + # load new swift.conf file + if set_swift_dir(os.path.dirname(swift_conf)): + constraints.reload_constraints() + storage_policy.reload_storage_policies() + global config if constraints.SWIFT_CONSTRAINTS_LOADED: # Use the swift constraints that are loaded for the test framework @@ -407,16 +451,13 @@ def in_process_setup(the_object_server=object_server): else: # In-process swift constraints were not loaded, somethings wrong raise SkipTest - global orig_hash_path_suff_pref - orig_hash_path_suff_pref = utils.HASH_PATH_PREFIX, utils.HASH_PATH_SUFFIX - utils.validate_hash_conf() global _test_socks _test_socks = [] # We create the proxy server listening socket to get its port number so # that we can add it as the "auth_port" value for the functional test # clients. - prolis = eventlet.listen(('localhost', 0)) + prolis = listen_zero() _test_socks.append(prolis) # The following set of configuration values is used both for the @@ -431,6 +472,7 @@ def in_process_setup(the_object_server=object_server): 'allow_account_management': 'true', 'account_autocreate': 'true', 'allow_versions': 'True', + 'allow_versioned_writes': 'True', # Below are values used by the functional test framework, as well as # by the various in-process swift servers 'auth_host': '127.0.0.1', @@ -472,10 +514,10 @@ def in_process_setup(the_object_server=object_server): config['object_post_as_copy'] = str(object_post_as_copy) _debug('Setting object_post_as_copy to %r' % object_post_as_copy) - acc1lis = eventlet.listen(('localhost', 0)) - acc2lis = eventlet.listen(('localhost', 0)) - con1lis = eventlet.listen(('localhost', 0)) - con2lis = eventlet.listen(('localhost', 0)) + acc1lis = listen_zero() + acc2lis = listen_zero() + con1lis = listen_zero() + con2lis = listen_zero() _test_socks += [acc1lis, acc2lis, con1lis, con2lis] + obj_sockets account_ring_path = os.path.join(_testdir, 'account.ring.gz') @@ -569,7 +611,8 @@ def in_process_setup(the_object_server=object_server): node['ip'], node['port'], node['device'], partition, 'PUT', '/' + act, {'X-Timestamp': ts, 'x-trans-id': act}) resp = conn.getresponse() - assert(resp.status == 201) + assert resp.status == 201, 'Unable to create account: %s\n%s' % ( + resp.status, resp.body) create_account('AUTH_test') create_account('AUTH_test2') @@ -870,10 +913,7 @@ def teardown_package(): rmtree(os.path.dirname(_testdir)) except Exception: pass - utils.HASH_PATH_PREFIX, utils.HASH_PATH_SUFFIX = \ - orig_hash_path_suff_pref - utils.SWIFT_CONF_FILE = orig_swift_conf_name - constraints.reload_constraints() + reset_globals() |