Changeset 1a65dfa in trunk
- Timestamp:
- 2020-08-27T19:58:03Z (5 years ago)
- Branches:
- master
- Children:
- 1e5f7a9
- Parents:
- 9ce4323
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/test/test_storage.py ¶
r9ce4323 r1a65dfa 793 793 794 794 def write_enabler(self, we_tag): 795 return hashutil.tagged_hash( "we_blah", we_tag)795 return hashutil.tagged_hash(b"we_blah", we_tag) 796 796 797 797 def renew_secret(self, tag): 798 return hashutil.tagged_hash("renew_blah", str(tag)) 798 if isinstance(tag, int): 799 tag = b"%d" % (tag,) 800 assert isinstance(tag, bytes) 801 return hashutil.tagged_hash(b"renew_blah", tag) 799 802 800 803 def cancel_secret(self, tag): 801 return hashutil.tagged_hash("cancel_blah", str(tag)) 804 if isinstance(tag, int): 805 tag = b"%d" % (tag,) 806 assert isinstance(tag, bytes) 807 return hashutil.tagged_hash(b"cancel_blah", tag) 802 808 803 809 def allocate(self, ss, storage_index, we_tag, lease_tag, sharenums, size): … … 820 826 def test_bad_magic(self): 821 827 ss = self.create("test_bad_magic") 822 self.allocate(ss, "si1","we1", next(self._lease_secret), set([0]), 10)823 fn = os.path.join(ss.sharedir, storage_index_to_dir( "si1"), "0")828 self.allocate(ss, b"si1", b"we1", next(self._lease_secret), set([0]), 10) 829 fn = os.path.join(ss.sharedir, storage_index_to_dir(b"si1"), "0") 824 830 f = open(fn, "rb+") 825 831 f.seek(0) 826 f.write( "BAD MAGIC")832 f.write(b"BAD MAGIC") 827 833 f.close() 828 834 read = ss.remote_slot_readv 829 835 e = self.failUnlessRaises(UnknownMutableContainerVersionError, 830 read, "si1", [0], [(0,10)])836 read, b"si1", [0], [(0,10)]) 831 837 self.failUnlessIn(" had magic ", str(e)) 832 838 self.failUnlessIn(" but we wanted ", str(e)) … … 834 840 def test_container_size(self): 835 841 ss = self.create("test_container_size") 836 self.allocate(ss, "si1","we1", next(self._lease_secret),842 self.allocate(ss, b"si1", b"we1", next(self._lease_secret), 837 843 set([0,1,2]), 100) 838 844 read = ss.remote_slot_readv 839 845 rstaraw = ss.remote_slot_testv_and_readv_and_writev 840 secrets = ( self.write_enabler( "we1"),841 self.renew_secret( "we1"),842 self.cancel_secret( "we1") )843 data = "".join([ ("%d" % i) * 10 for i in range(10) ])844 answer = rstaraw( "si1", secrets,846 secrets = ( self.write_enabler(b"we1"), 847 self.renew_secret(b"we1"), 848 self.cancel_secret(b"we1") ) 849 data = b"".join([ (b"%d" % i) * 10 for i in range(10) ]) 850 answer = rstaraw(b"si1", secrets, 845 851 {0: ([], [(0,data)], len(data)+12)}, 846 852 []) … … 851 857 TOOBIG = MutableShareFile.MAX_SIZE + 10 852 858 self.failUnlessRaises(DataTooLargeError, 853 rstaraw, "si1", secrets,859 rstaraw, b"si1", secrets, 854 860 {0: ([], [(TOOBIG,data)], None)}, 855 861 []) 856 862 857 answer = rstaraw( "si1", secrets,863 answer = rstaraw(b"si1", secrets, 858 864 {0: ([], [(0,data)], None)}, 859 865 []) 860 866 self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) 861 867 862 read_answer = read( "si1", [0], [(0,10)])868 read_answer = read(b"si1", [0], [(0,10)]) 863 869 self.failUnlessEqual(read_answer, {0: [data[:10]]}) 864 870 865 871 # Sending a new_length shorter than the current length truncates the 866 872 # data. 867 answer = rstaraw( "si1", secrets,873 answer = rstaraw(b"si1", secrets, 868 874 {0: ([], [], 9)}, 869 875 []) 870 read_answer = read( "si1", [0], [(0,10)])876 read_answer = read(b"si1", [0], [(0,10)]) 871 877 self.failUnlessEqual(read_answer, {0: [data[:9]]}) 872 878 873 879 # Sending a new_length longer than the current length doesn't change 874 880 # the data. 875 answer = rstaraw( "si1", secrets,881 answer = rstaraw(b"si1", secrets, 876 882 {0: ([], [], 20)}, 877 883 []) 878 884 assert answer == (True, {0:[],1:[],2:[]}) 879 read_answer = read( "si1", [0], [(0, 20)])885 read_answer = read(b"si1", [0], [(0, 20)]) 880 886 self.failUnlessEqual(read_answer, {0: [data[:9]]}) 881 887 … … 885 891 886 892 # To test this, we fill the data area with a recognizable pattern. 887 pattern = ''.join([chr(i) for i in range(100)])888 answer = rstaraw( "si1", secrets,893 pattern = u''.join([chr(i) for i in range(100)]).encode("utf-8") 894 answer = rstaraw(b"si1", secrets, 889 895 {0: ([], [(0, pattern)], None)}, 890 896 []) 891 897 assert answer == (True, {0:[],1:[],2:[]}) 892 898 # Then truncate the data... 893 answer = rstaraw( "si1", secrets,899 answer = rstaraw(b"si1", secrets, 894 900 {0: ([], [], 20)}, 895 901 []) … … 897 903 # Just confirm that you get an empty string if you try to read from 898 904 # past the (new) endpoint now. 899 answer = rstaraw( "si1", secrets,905 answer = rstaraw(b"si1", secrets, 900 906 {0: ([], [], None)}, 901 907 [(20, 1980)]) 902 self.failUnlessEqual(answer, (True, {0:[ ''],1:[''],2:['']}))908 self.failUnlessEqual(answer, (True, {0:[b''],1:[b''],2:[b'']})) 903 909 904 910 # Then the extend the file by writing a vector which starts out past 905 911 # the end... 906 answer = rstaraw( "si1", secrets,907 {0: ([], [(50, 'hellothere')], None)},912 answer = rstaraw(b"si1", secrets, 913 {0: ([], [(50, b'hellothere')], None)}, 908 914 []) 909 915 assert answer == (True, {0:[],1:[],2:[]}) 910 916 # Now if you read the stuff between 20 (where we earlier truncated) 911 917 # and 50, it had better be all zeroes. 912 answer = rstaraw( "si1", secrets,918 answer = rstaraw(b"si1", secrets, 913 919 {0: ([], [], None)}, 914 920 [(20, 30)]) 915 self.failUnlessEqual(answer, (True, {0:[ '\x00'*30],1:[''],2:['']}))921 self.failUnlessEqual(answer, (True, {0:[b'\x00'*30],1:[b''],2:[b'']})) 916 922 917 923 # Also see if the server explicitly declares that it supports this … … 922 928 923 929 # If the size is dropped to zero the share is deleted. 924 answer = rstaraw( "si1", secrets,930 answer = rstaraw(b"si1", secrets, 925 931 {0: ([], [(0,data)], 0)}, 926 932 []) 927 933 self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) 928 934 929 read_answer = read( "si1", [0], [(0,10)])935 read_answer = read(b"si1", [0], [(0,10)]) 930 936 self.failUnlessEqual(read_answer, {}) 931 937
Note: See TracChangeset
for help on using the changeset viewer.