mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-25 13:07:37 +00:00
Merge pull request #833 from tahoe-lafs/3446.test-helper-python-3
Port test_helper.py to Python 3 Fixes ticket:3446
This commit is contained in:
commit
5e6201aede
0
newsfragments/3446.minor
Normal file
0
newsfragments/3446.minor
Normal file
@ -203,7 +203,7 @@ class CHKUploadHelper(Referenceable, upload.CHKUploader):
|
||||
def _finished(self, ur):
|
||||
assert interfaces.IUploadResults.providedBy(ur), ur
|
||||
vcapstr = ur.get_verifycapstr()
|
||||
precondition(isinstance(vcapstr, str), vcapstr)
|
||||
precondition(isinstance(vcapstr, bytes), vcapstr)
|
||||
v = uri.from_string(vcapstr)
|
||||
f_times = self._fetcher.get_times()
|
||||
|
||||
@ -492,9 +492,9 @@ class Helper(Referenceable):
|
||||
# helper at random.
|
||||
|
||||
name = "helper"
|
||||
VERSION = { "http://allmydata.org/tahoe/protocols/helper/v1" :
|
||||
VERSION = { b"http://allmydata.org/tahoe/protocols/helper/v1" :
|
||||
{ },
|
||||
"application-version": str(allmydata.__full_version__),
|
||||
b"application-version": allmydata.__full_version__.encode("utf-8"),
|
||||
}
|
||||
MAX_UPLOAD_STATUSES = 10
|
||||
|
||||
|
@ -1816,15 +1816,15 @@ class Uploader(service.MultiService, log.PrefixingLogMixin):
|
||||
|
||||
def _got_helper(self, helper):
|
||||
self.log("got helper connection, getting versions")
|
||||
default = { "http://allmydata.org/tahoe/protocols/helper/v1" :
|
||||
default = { b"http://allmydata.org/tahoe/protocols/helper/v1" :
|
||||
{ },
|
||||
"application-version": b"unknown: no get_version()",
|
||||
b"application-version": b"unknown: no get_version()",
|
||||
}
|
||||
d = add_version_to_remote_reference(helper, default)
|
||||
d.addCallback(self._got_versioned_helper)
|
||||
|
||||
def _got_versioned_helper(self, helper):
|
||||
needed = "http://allmydata.org/tahoe/protocols/helper/v1"
|
||||
needed = b"http://allmydata.org/tahoe/protocols/helper/v1"
|
||||
if needed not in helper.version:
|
||||
raise InsufficientVersionError(needed, helper.version)
|
||||
self._helper = helper
|
||||
|
@ -2,13 +2,15 @@
|
||||
Interfaces for Tahoe-LAFS.
|
||||
|
||||
Ported to Python 3.
|
||||
|
||||
Note that for RemoteInterfaces, the __remote_name__ needs to be a native string because of https://github.com/warner/foolscap/blob/43f4485a42c9c28e2c79d655b3a9e24d4e6360ca/src/foolscap/remoteinterface.py#L67
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
from future.utils import PY2, native_str
|
||||
if PY2:
|
||||
# Don't import object/str/dict/etc. types, so we don't break any
|
||||
# interfaces. Not importing open() because it triggers bogus flake8 error.
|
||||
@ -105,7 +107,7 @@ ReadData = ListOf(ShareData)
|
||||
|
||||
|
||||
class RIStorageServer(RemoteInterface):
|
||||
__remote_name__ = b"RIStorageServer.tahoe.allmydata.com"
|
||||
__remote_name__ = native_str("RIStorageServer.tahoe.allmydata.com")
|
||||
|
||||
def get_version():
|
||||
"""
|
||||
@ -2836,17 +2838,17 @@ class RIControlClient(RemoteInterface):
|
||||
|
||||
# debug stuff
|
||||
|
||||
def upload_random_data_from_file(size=int, convergence=str):
|
||||
def upload_random_data_from_file(size=int, convergence=bytes):
|
||||
return str
|
||||
|
||||
def download_to_tempfile_and_delete(uri=str):
|
||||
def download_to_tempfile_and_delete(uri=bytes):
|
||||
return None
|
||||
|
||||
def get_memory_usage():
|
||||
"""Return a dict describes the amount of memory currently in use. The
|
||||
keys are 'VmPeak', 'VmSize', and 'VmData'. The values are integers,
|
||||
measuring memory consupmtion in bytes."""
|
||||
return DictOf(str, int)
|
||||
return DictOf(bytes, int)
|
||||
|
||||
def speed_test(count=int, size=int, mutable=Any()):
|
||||
"""Write 'count' tempfiles to disk, all of the given size. Measure
|
||||
@ -2871,11 +2873,11 @@ class RIControlClient(RemoteInterface):
|
||||
return DictOf(str, float)
|
||||
|
||||
|
||||
UploadResults = Any() #DictOf(str, str)
|
||||
UploadResults = Any() #DictOf(bytes, bytes)
|
||||
|
||||
|
||||
class RIEncryptedUploadable(RemoteInterface):
|
||||
__remote_name__ = b"RIEncryptedUploadable.tahoe.allmydata.com"
|
||||
__remote_name__ = native_str("RIEncryptedUploadable.tahoe.allmydata.com")
|
||||
|
||||
def get_size():
|
||||
return Offset
|
||||
@ -2884,33 +2886,33 @@ class RIEncryptedUploadable(RemoteInterface):
|
||||
return (int, int, int, long)
|
||||
|
||||
def read_encrypted(offset=Offset, length=ReadSize):
|
||||
return ListOf(str)
|
||||
return ListOf(bytes)
|
||||
|
||||
def close():
|
||||
return None
|
||||
|
||||
|
||||
class RICHKUploadHelper(RemoteInterface):
|
||||
__remote_name__ = b"RIUploadHelper.tahoe.allmydata.com"
|
||||
__remote_name__ = native_str("RIUploadHelper.tahoe.allmydata.com")
|
||||
|
||||
def get_version():
|
||||
"""
|
||||
Return a dictionary of version information.
|
||||
"""
|
||||
return DictOf(str, Any())
|
||||
return DictOf(bytes, Any())
|
||||
|
||||
def upload(reader=RIEncryptedUploadable):
|
||||
return UploadResults
|
||||
|
||||
|
||||
class RIHelper(RemoteInterface):
|
||||
__remote_name__ = b"RIHelper.tahoe.allmydata.com"
|
||||
__remote_name__ = native_str("RIHelper.tahoe.allmydata.com")
|
||||
|
||||
def get_version():
|
||||
"""
|
||||
Return a dictionary of version information.
|
||||
"""
|
||||
return DictOf(str, Any())
|
||||
return DictOf(bytes, Any())
|
||||
|
||||
def upload_chk(si=StorageIndex):
|
||||
"""See if a file with a given storage index needs uploading. The
|
||||
@ -2931,7 +2933,7 @@ class RIHelper(RemoteInterface):
|
||||
|
||||
|
||||
class RIStatsProvider(RemoteInterface):
|
||||
__remote_name__ = b"RIStatsProvider.tahoe.allmydata.com"
|
||||
__remote_name__ = native_str("RIStatsProvider.tahoe.allmydata.com")
|
||||
"""
|
||||
Provides access to statistics and monitoring information.
|
||||
"""
|
||||
@ -2944,16 +2946,16 @@ class RIStatsProvider(RemoteInterface):
|
||||
stats are instantaneous measures (potentially time averaged
|
||||
internally)
|
||||
"""
|
||||
return DictOf(str, DictOf(str, ChoiceOf(float, int, long, None)))
|
||||
return DictOf(bytes, DictOf(bytes, ChoiceOf(float, int, long, None)))
|
||||
|
||||
|
||||
class RIStatsGatherer(RemoteInterface):
|
||||
__remote_name__ = b"RIStatsGatherer.tahoe.allmydata.com"
|
||||
__remote_name__ = native_str("RIStatsGatherer.tahoe.allmydata.com")
|
||||
"""
|
||||
Provides a monitoring service for centralised collection of stats
|
||||
"""
|
||||
|
||||
def provide(provider=RIStatsProvider, nickname=str):
|
||||
def provide(provider=RIStatsProvider, nickname=bytes):
|
||||
"""
|
||||
@param provider: a stats collector instance that should be polled
|
||||
periodically by the gatherer to collect stats.
|
||||
@ -2965,7 +2967,7 @@ class RIStatsGatherer(RemoteInterface):
|
||||
class IStatsProducer(Interface):
|
||||
def get_stats():
|
||||
"""
|
||||
returns a dictionary, with str keys representing the names of stats
|
||||
returns a dictionary, with bytes keys representing the names of stats
|
||||
to be monitored, and numeric values.
|
||||
"""
|
||||
|
||||
|
@ -1,3 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
import os
|
||||
from twisted.internet import defer
|
||||
from twisted.trial import unittest
|
||||
@ -18,7 +27,7 @@ from .common import (
|
||||
|
||||
MiB = 1024*1024
|
||||
|
||||
DATA = "I need help\n" * 1000
|
||||
DATA = b"I need help\n" * 1000
|
||||
|
||||
class CHKUploadHelper_fake(offloaded.CHKUploadHelper):
|
||||
def start_encrypted(self, eu):
|
||||
@ -33,8 +42,8 @@ class CHKUploadHelper_fake(offloaded.CHKUploadHelper):
|
||||
"segment_size": segsize,
|
||||
"size": size,
|
||||
}
|
||||
ueb_hash = "fake"
|
||||
v = uri.CHKFileVerifierURI(self._storage_index, "x"*32,
|
||||
ueb_hash = b"fake"
|
||||
v = uri.CHKFileVerifierURI(self._storage_index, b"x"*32,
|
||||
needed_shares, total_shares, size)
|
||||
_UR = upload.UploadResults
|
||||
ur = _UR(file_size=size,
|
||||
@ -56,7 +65,7 @@ class CHKUploadHelper_fake(offloaded.CHKUploadHelper):
|
||||
|
||||
class Helper_fake_upload(offloaded.Helper):
|
||||
def _make_chk_upload_helper(self, storage_index, lp):
|
||||
si_s = si_b2a(storage_index)
|
||||
si_s = str(si_b2a(storage_index), "utf-8")
|
||||
incoming_file = os.path.join(self._chk_incoming, si_s)
|
||||
encoding_file = os.path.join(self._chk_encoding, si_s)
|
||||
uh = CHKUploadHelper_fake(storage_index, self,
|
||||
@ -69,7 +78,7 @@ class Helper_fake_upload(offloaded.Helper):
|
||||
class Helper_already_uploaded(Helper_fake_upload):
|
||||
def _check_chk(self, storage_index, lp):
|
||||
res = upload.HelperUploadResults()
|
||||
res.uri_extension_hash = hashutil.uri_extension_hash("")
|
||||
res.uri_extension_hash = hashutil.uri_extension_hash(b"")
|
||||
|
||||
# we're pretending that the file they're trying to upload was already
|
||||
# present in the grid. We return some information about the file, so
|
||||
@ -127,14 +136,14 @@ class AssistedUpload(unittest.TestCase):
|
||||
lambda h: self.tub,
|
||||
EMPTY_CLIENT_CONFIG,
|
||||
)
|
||||
self.s.secret_holder = client.SecretHolder("lease secret", "converge")
|
||||
self.s.secret_holder = client.SecretHolder(b"lease secret", b"converge")
|
||||
self.s.startService()
|
||||
|
||||
t.setServiceParent(self.s)
|
||||
self.s.tub = t
|
||||
# we never actually use this for network traffic, so it can use a
|
||||
# bogus host/port
|
||||
t.setLocation("bogus:1234")
|
||||
t.setLocation(b"bogus:1234")
|
||||
|
||||
def setUpHelper(self, basedir, helper_class=Helper_fake_upload):
|
||||
fileutil.make_dirs(basedir)
|
||||
@ -162,11 +171,11 @@ class AssistedUpload(unittest.TestCase):
|
||||
def _ready(res):
|
||||
assert u._helper
|
||||
|
||||
return upload_data(u, DATA, convergence="some convergence string")
|
||||
return upload_data(u, DATA, convergence=b"some convergence string")
|
||||
d.addCallback(_ready)
|
||||
def _uploaded(results):
|
||||
the_uri = results.get_uri()
|
||||
assert "CHK" in the_uri
|
||||
assert b"CHK" in the_uri
|
||||
d.addCallback(_uploaded)
|
||||
|
||||
def _check_empty(res):
|
||||
@ -195,11 +204,11 @@ class AssistedUpload(unittest.TestCase):
|
||||
# this must be a multiple of 'required_shares'==k
|
||||
segsize = mathutil.next_multiple(segsize, k)
|
||||
|
||||
key = hashutil.convergence_hash(k, n, segsize, DATA, "test convergence string")
|
||||
key = hashutil.convergence_hash(k, n, segsize, DATA, b"test convergence string")
|
||||
assert len(key) == 16
|
||||
encryptor = aes.create_encryptor(key)
|
||||
SI = hashutil.storage_index_hash(key)
|
||||
SI_s = si_b2a(SI)
|
||||
SI_s = str(si_b2a(SI), "utf-8")
|
||||
encfile = os.path.join(self.basedir, "CHK_encoding", SI_s)
|
||||
f = open(encfile, "wb")
|
||||
f.write(aes.encrypt_data(encryptor, DATA))
|
||||
@ -212,11 +221,11 @@ class AssistedUpload(unittest.TestCase):
|
||||
|
||||
def _ready(res):
|
||||
assert u._helper
|
||||
return upload_data(u, DATA, convergence="test convergence string")
|
||||
return upload_data(u, DATA, convergence=b"test convergence string")
|
||||
d.addCallback(_ready)
|
||||
def _uploaded(results):
|
||||
the_uri = results.get_uri()
|
||||
assert "CHK" in the_uri
|
||||
assert b"CHK" in the_uri
|
||||
d.addCallback(_uploaded)
|
||||
|
||||
def _check_empty(res):
|
||||
@ -239,11 +248,11 @@ class AssistedUpload(unittest.TestCase):
|
||||
def _ready(res):
|
||||
assert u._helper
|
||||
|
||||
return upload_data(u, DATA, convergence="some convergence string")
|
||||
return upload_data(u, DATA, convergence=b"some convergence string")
|
||||
d.addCallback(_ready)
|
||||
def _uploaded(results):
|
||||
the_uri = results.get_uri()
|
||||
assert "CHK" in the_uri
|
||||
assert b"CHK" in the_uri
|
||||
d.addCallback(_uploaded)
|
||||
|
||||
def _check_empty(res):
|
||||
|
@ -93,6 +93,7 @@ PORTED_TEST_MODULES = [
|
||||
"allmydata.test.test_happiness",
|
||||
"allmydata.test.test_hashtree",
|
||||
"allmydata.test.test_hashutil",
|
||||
"allmydata.test.test_helper",
|
||||
"allmydata.test.test_humanreadable",
|
||||
"allmydata.test.test_immutable",
|
||||
"allmydata.test.test_iputil",
|
||||
|
Loading…
x
Reference in New Issue
Block a user