Created
March 31, 2015 21:52
-
-
Save clayg/24e882c4ee9f786e5312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/test/unit/obj/test_reconstructor.py b/test/unit/obj/test_reconstructor.py | |
index d23d75b..9d35932 100755 | |
--- a/test/unit/obj/test_reconstructor.py | |
+++ b/test/unit/obj/test_reconstructor.py | |
@@ -67,9 +67,6 @@ def make_ec_archive_bodies(policy, test_body): | |
return ec_archive_bodies | |
-testdir = object_ring_0 = object_ring_1 = None | |
- | |
- | |
def _ips(): | |
return ['127.0.0.1'] | |
object_reconstructor.whataremyips = _ips | |
@@ -108,17 +105,6 @@ def _create_test_rings(path): | |
f) | |
-def setup(): | |
- global testdir, object_ring_0, object_ring_1 | |
- if testdir is None: | |
- testdir = tempfile.mkdtemp() | |
- _create_test_rings(testdir) | |
- object_ring_0 = ring.Ring(testdir, ring_name='object') # noqa | |
- object_ring_1 = ring.Ring(testdir, ring_name='object-1') # noqa | |
- POLICIES[0].object_ring = object_ring_0 | |
- POLICIES[0].object_ring = object_ring_1 | |
- | |
- | |
def count_stats(logger, key, metric): | |
count = 0 | |
for record in logger.log_dict[key]: | |
@@ -133,24 +119,24 @@ def count_stats(logger, key, metric): | |
# them or things will likely explode | |
@patch_policies([ | |
StoragePolicy.from_conf( | |
- REPL_POLICY, {'idx': 0, 'name': 'zero', 'is_default': True, | |
- 'object_ring': object_ring_0}), | |
+ REPL_POLICY, {'idx': 0, 'name': 'zero', 'is_default': True}), | |
StoragePolicy.from_conf( | |
EC_POLICY, {'idx': 1, 'name': 'one', 'is_default': False, | |
'ec_type': 'jerasure_rs_vand', 'ec_ndata': 2, | |
- 'ec_nparity': 1, 'object_ring': object_ring_1}) | |
+ 'ec_nparity': 1}) | |
]) | |
class TestGlobalSetupObjectReconstructor(unittest.TestCase): | |
def setUp(self): | |
- # call module level setup on every test case to recreate fresh rings | |
- # they are deleted in the testcase tearDown. Can't be done in the | |
- # test case setup because we need the rings deinfed before the | |
- # patching of policies | |
- setup() | |
+ self.testdir = tempfile.mkdtemp() | |
+ _create_test_rings(self.testdir) | |
+ object_ring_0 = ring.Ring(self.testdir, ring_name='object') # noqa | |
+ object_ring_1 = ring.Ring(self.testdir, ring_name='object-1') # noqa | |
+ POLICIES[0].object_ring = object_ring_0 | |
+ POLICIES[1].object_ring = object_ring_1 | |
utils.HASH_PATH_SUFFIX = 'endcap' | |
utils.HASH_PATH_PREFIX = '' | |
- self.devices = os.path.join(testdir, 'node') | |
+ self.devices = os.path.join(self.testdir, 'node') | |
os.makedirs(self.devices) | |
os.mkdir(os.path.join(self.devices, 'sda1')) | |
self.objects = os.path.join(self.devices, 'sda1', | |
@@ -169,7 +155,7 @@ class TestGlobalSetupObjectReconstructor(unittest.TestCase): | |
os.mkdir(self.parts_1[part]) | |
self.conf = dict( | |
- swift_dir=testdir, devices=self.devices, mount_check='false', | |
+ swift_dir=self.testdir, devices=self.devices, mount_check='false', | |
timeout='300', stats_interval='1') | |
self.logger = debug_logger('test-reconstructor') | |
self.reconstructor = object_reconstructor.ObjectReconstructor( | |
@@ -267,12 +253,7 @@ class TestGlobalSetupObjectReconstructor(unittest.TestCase): | |
break | |
def tearDown(self): | |
- # remove all on disk test stuff and clear the testdir global | |
- # so that the module level setup recreates everything when | |
- # called by the testcase setup() | |
- global testdir | |
- rmtree(testdir, ignore_errors=1) | |
- testdir = None | |
+ rmtree(self.testdir, ignore_errors=1) | |
def _create_diskfile(self, policy=None, part=0, object_name='o', | |
frag_index=0, timestamp=None, test_data=None): | |
@@ -701,7 +682,7 @@ class TestGlobalSetupObjectReconstructor(unittest.TestCase): | |
def test_get_response(self): | |
part = self.part_nums[0] | |
- node = object_ring_0.get_part_nodes(int(part))[0] | |
+ node = POLICIES[0].object_ring.get_part_nodes(int(part))[0] | |
for stat_code in (200, 400): | |
with mock_http_connect(stat_code): | |
resp = self.reconstructor._get_response(node, part, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment