Home | Trees | Indices | Help |
---|
|
1 # 2 # Copyright (c) 2013, EMC Corporation 3 # All rights reserved. 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions are met: 7 # 8 # 1. Redistributions of source code must retain the above copyright notice, 9 # this list of conditions and the following disclaimer. 10 # 2. Redistributions in binary form must reproduce the above copyright notice, 11 # this list of conditions and the following disclaimer in the documentation 12 # and/or other materials provided with the distribution. 13 # 14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 # POSSIBILITY OF SUCH DAMAGE. 25 # 26 # Module Name: 27 # 28 # durable.py 29 # 30 # Abstract: 31 # 32 # Durable handle tests 33 # 34 # Authors: Arlene Berry (arlene.berry@emc.com) 35 # 36 37 import pike.model 38 import pike.smb2 39 import pike.test 40 import pike.ntstatus 41 import random 42 import array 43 44 @pike.test.RequireCapabilities(pike.smb2.SMB2_GLOBAL_CAP_LEASING)46 share_all = pike.smb2.FILE_SHARE_READ | pike.smb2.FILE_SHARE_WRITE | pike.smb2.FILE_SHARE_DELETE 47 lease1 = array.array('B',map(random.randint, [0]*16, [255]*16)) 48 lease2 = array.array('B',map(random.randint, [0]*16, [255]*16)) 49 r = pike.smb2.SMB2_LEASE_READ_CACHING 50 rw = r | pike.smb2.SMB2_LEASE_WRITE_CACHING 51 rh = r | pike.smb2.SMB2_LEASE_HANDLE_CACHING 52 rwh = rw | rh 5319254 - def create(self, chan, tree, durable, lease=rwh, lease_key=lease1, disposition=pike.smb2.FILE_SUPERSEDE):55 return chan.create(tree, 56 'durable.txt', 57 access=pike.smb2.FILE_READ_DATA | pike.smb2.FILE_WRITE_DATA | pike.smb2.DELETE, 58 share=self.share_all, 59 disposition=disposition, 60 oplock_level=pike.smb2.SMB2_OPLOCK_LEVEL_LEASE, 61 lease_key = lease_key, 62 lease_state = lease, 63 durable=durable).result()6466 chan, tree = self.tree_connect() 67 68 handle1 = self.create(chan, tree, durable=durable) 69 70 self.assertEqual(handle1.lease.lease_state, self.rwh) 71 72 chan.close(handle1)7375 chan, tree = self.tree_connect() 76 77 handle1 = self.create(chan, tree, durable=durable) 78 79 self.assertEqual(handle1.lease.lease_state, self.rwh) 80 81 # Close the connection 82 chan.connection.close() 83 84 chan2, tree2 = self.tree_connect() 85 86 # Request reconnect 87 handle2 = self.create(chan2, tree2, durable=handle1) 88 89 self.assertEqual(handle2.lease.lease_state, self.rwh) 90 91 chan2.close(handle2)9294 chan, tree = self.tree_connect() 95 96 handle1 = self.create(chan, tree, durable=durable) 97 98 self.assertEqual(handle1.lease.lease_state, self.rwh) 99 100 # Close the connection 101 chan.connection.close() 102 103 chan2, tree2 = self.tree_connect(client=pike.model.Client()) 104 105 with self.assert_error(pike.ntstatus.STATUS_OBJECT_NAME_NOT_FOUND): 106 handle2 = self.create(chan2, tree2, durable=handle1) 107 108 chan2.connection.close() 109 110 chan3, tree3 = self.tree_connect() 111 112 handle3 = self.create(chan3, tree3, durable=handle1) 113 114 chan3.close(handle3)115117 chan, tree = self.tree_connect() 118 119 handle1 = self.create(chan, tree, durable=durable, lease=self.rw) 120 self.assertEqual(handle1.lease.lease_state, self.rw) 121 122 # Close the connection 123 chan.connection.close() 124 125 chan2, tree2 = self.tree_connect(client=pike.model.Client()) 126 127 # Invalidate handle from separate client 128 handle2 = self.create(chan2, 129 tree2, 130 durable=durable, 131 lease=self.rw, 132 lease_key=self.lease2, 133 disposition=pike.smb2.FILE_OPEN) 134 self.assertEqual(handle2.lease.lease_state, self.rw) 135 chan2.close(handle2) 136 137 chan2.connection.close() 138 139 chan3, tree3 = self.tree_connect() 140 141 # Reconnect should now fail 142 with self.assert_error(pike.ntstatus.STATUS_OBJECT_NAME_NOT_FOUND): 143 handle3 = self.create(chan3, tree3, durable=handle1)144 145 # Request a durable handle 146 @pike.test.RequireDialect(pike.smb2.DIALECT_SMB2_1)148 self.durable_test(True)149 150 # Reconnect a durable handle after a TCP disconnect 151 @pike.test.RequireDialect(pike.smb2.DIALECT_SMB2_1)153 self.durable_reconnect_test(True)154 155 # Reconnecting a durable handle after a TCP disconnect 156 # fails with STATUS_OBJECT_NAME_NOT_FOUND if the client 157 # guid does not match 158 @pike.test.RequireDialect(pike.smb2.DIALECT_SMB2_1)160 self.durable_reconnect_fails_client_guid_test(True)161 162 # Breaking the lease of a disconnected durable handle 163 # (without HANDLE) invalidates it, so a subsequent 164 # reconnect will fail. 165 @pike.test.RequireDialect(pike.smb2.DIALECT_SMB2_1)167 self.durable_invalidate_test(True)168 169 # Request a durable handle via V2 context structure 170 @pike.test.RequireDialect(pike.smb2.DIALECT_SMB3_0)172 self.durable_test(0)173 174 # Reconnect a durable handle via V2 context structure 175 @pike.test.RequireDialect(pike.smb2.DIALECT_SMB3_0)177 self.durable_reconnect_test(0)178 179 # Reconnecting a durable handle (v2) after a TCP disconnect 180 # fails with STATUS_OBJECT_NAME_NOT_FOUND if the client 181 # guid does not match 182 @pike.test.RequireDialect(pike.smb2.DIALECT_SMB3_0)184 self.durable_reconnect_fails_client_guid_test(0)185 186 # Breaking the lease of a disconnected durable handle v2 187 # (without HANDLE) invalidates it, so a subsequent 188 # reconnect will fail. 189 @pike.test.RequireDialect(pike.smb2.DIALECT_SMB3_0)191 self.durable_invalidate_test(0)
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Jun 29 08:51:24 2017 | http://epydoc.sourceforge.net |