]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Tue Jun 19 03:05:04 BST 2012 david-sarah@jacaranda.org
authorDaira Hopwood <daira@jacaranda.org>
Thu, 5 Sep 2013 16:37:23 +0000 (17:37 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Thu, 5 Sep 2013 16:37:23 +0000 (17:37 +0100)
  * Add assertions to make sure that set_default_encoding_parameters is always called, rather than using hardcoded 3/7/10 defaults. Also update affected tests. Note that this by itself cannot fix the bug mentioned in ticket:1212#comment:41, but it might make it easier to reproduce. refs #1212

src/allmydata/immutable/upload.py
src/allmydata/test/test_encode.py
src/allmydata/test/test_upload.py

index 013aca97cbc6a9ce2c221531cc9e444f5bfdd33e..75d26be64ccd8a7eead04f26221ec3b9a7ddaad4 100644 (file)
@@ -16,7 +16,7 @@ from allmydata.util import base32, dictutil, idlib, log, mathutil
 from allmydata.util.happinessutil import servers_of_happiness, \
                                          shares_by_server, merge_servers, \
                                          failure_message
-from allmydata.util.assertutil import precondition
+from allmydata.util.assertutil import precondition, _assert
 from allmydata.util.rrefutil import add_version_to_remote_reference
 from allmydata.interfaces import IUploadable, IUploader, IUploadResults, \
      IEncryptedUploadable, RIEncryptedUploadable, IUploadStatus, \
@@ -573,6 +573,8 @@ class EncryptAnUploadable:
     CHUNKSIZE = 50*1024
 
     def __init__(self, original, log_parent=None):
+        precondition(original.default_params_set,
+                     "set_default_encoding_parameters not called on %r before wrapping with EncryptAnUploadable" % (original,))
         self.original = IUploadable(original)
         self._log_number = log_parent
         self._encryptor = None
@@ -1248,9 +1250,7 @@ class AssistedUploader:
 class BaseUploadable:
     # this is overridden by max_segment_size
     default_max_segment_size = DEFAULT_MAX_SEGMENT_SIZE
-    default_encoding_param_k = 3 # overridden by encoding_parameters
-    default_encoding_param_happy = 7
-    default_encoding_param_n = 10
+    default_params_set = False
 
     max_segment_size = None
     encoding_param_k = None
@@ -1276,8 +1276,10 @@ class BaseUploadable:
             self.default_encoding_param_n = default_params["n"]
         if "max_segment_size" in default_params:
             self.default_max_segment_size = default_params["max_segment_size"]
+        self.default_params_set = True
 
     def get_all_encoding_parameters(self):
+        _assert(self.default_params_set, "set_default_encoding_parameters not called on %r" % (self,))
         if self._all_encoding_parameters:
             return defer.succeed(self._all_encoding_parameters)
 
index c06fbbd3e165067200c0bd88e4dc0a50c23bbff5..b3f72d33db02540b15f5a71815521d39addc4a72 100644 (file)
@@ -268,10 +268,8 @@ class Encode(unittest.TestCase):
         # force use of multiple segments
         e = encode.Encoder()
         u = upload.Data(data, convergence="some convergence string")
-        u.max_segment_size = max_segment_size
-        u.encoding_param_k = 25
-        u.encoding_param_happy = 75
-        u.encoding_param_n = 100
+        u.set_default_encoding_parameters({'max_segment_size': max_segment_size,
+                                           'k': 25, 'happy': 75, 'n': 100})
         eu = upload.EncryptAnUploadable(u)
         d = e.set_encrypted_uploadable(eu)
 
index 224b8bd5fb8139adbb78f5c57f5f3dba1513eb2f..098a18d0b60d68f7a7e5c669b27498897873d8f3 100644 (file)
@@ -20,6 +20,7 @@ from allmydata.util.happinessutil import servers_of_happiness, \
                                          shares_by_server, merge_servers
 from allmydata.storage_client import StorageFarmBroker
 from allmydata.storage.server import storage_index_to_dir
+from allmydata.client import Client
 
 MiB = 1024*1024
 
@@ -633,42 +634,52 @@ class ServerSelection(unittest.TestCase):
 class StorageIndex(unittest.TestCase):
     def test_params_must_matter(self):
         DATA = "I am some data"
+        PARAMS = Client.DEFAULT_ENCODING_PARAMETERS
+
         u = upload.Data(DATA, convergence="")
+        u.set_default_encoding_parameters(PARAMS)
         eu = upload.EncryptAnUploadable(u)
         d1 = eu.get_storage_index()
 
         # CHK means the same data should encrypt the same way
         u = upload.Data(DATA, convergence="")
+        u.set_default_encoding_parameters(PARAMS)
         eu = upload.EncryptAnUploadable(u)
         d1a = eu.get_storage_index()
 
         # but if we use a different convergence string it should be different
         u = upload.Data(DATA, convergence="wheee!")
+        u.set_default_encoding_parameters(PARAMS)
         eu = upload.EncryptAnUploadable(u)
         d1salt1 = eu.get_storage_index()
 
         # and if we add yet a different convergence it should be different again
         u = upload.Data(DATA, convergence="NOT wheee!")
+        u.set_default_encoding_parameters(PARAMS)
         eu = upload.EncryptAnUploadable(u)
         d1salt2 = eu.get_storage_index()
 
         # and if we use the first string again it should be the same as last time
         u = upload.Data(DATA, convergence="wheee!")
+        u.set_default_encoding_parameters(PARAMS)
         eu = upload.EncryptAnUploadable(u)
         d1salt1a = eu.get_storage_index()
 
         # and if we change the encoding parameters, it should be different (from the same convergence string with different encoding parameters)
         u = upload.Data(DATA, convergence="")
+        u.set_default_encoding_parameters(PARAMS)
         u.encoding_param_k = u.default_encoding_param_k + 1
         eu = upload.EncryptAnUploadable(u)
         d2 = eu.get_storage_index()
 
         # and if we use a random key, it should be different than the CHK
         u = upload.Data(DATA, convergence=None)
+        u.set_default_encoding_parameters(PARAMS)
         eu = upload.EncryptAnUploadable(u)
         d3 = eu.get_storage_index()
         # and different from another instance
         u = upload.Data(DATA, convergence=None)
+        u.set_default_encoding_parameters(PARAMS)
         eu = upload.EncryptAnUploadable(u)
         d4 = eu.get_storage_index()
 
@@ -765,9 +776,7 @@ class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
         broker = self.g.clients[0].storage_broker
         sh     = self.g.clients[0]._secret_holder
         data = upload.Data("data" * 10000, convergence="")
-        data.encoding_param_k = 3
-        data.encoding_param_happy = 4
-        data.encoding_param_n = 10
+        data.set_default_encoding_parameters({'k': 3, 'happy': 4, 'n': 10})
         uploadable = upload.EncryptAnUploadable(data)
         encoder = encode.Encoder()
         encoder.set_encrypted_uploadable(uploadable)