Package pike :: Package test :: Module queryondiskid
[hide private]
[frames] | no frames]

Source Code for Module pike.test.queryondiskid

  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  #        queryondiskid.py 
 29  # 
 30  # Abstract: 
 31  # 
 32  #        Query On Disk Id CreateContext tests 
 33  # 
 34  # Authors: Masen Furer <masen.furer@emc.com> 
 35  # 
 36   
 37  import array 
 38  import struct 
 39  import pike.model 
 40  import pike.smb2 
 41  import pike.test 
 42   
 43  share_all = pike.smb2.FILE_SHARE_READ | \ 
 44              pike.smb2.FILE_SHARE_WRITE | \ 
 45              pike.smb2.FILE_SHARE_DELETE 
 46  access_rwd = pike.smb2.GENERIC_READ | \ 
 47               pike.smb2.GENERIC_WRITE | \ 
 48               pike.smb2.DELETE 
 49  null_fid = array.array('B', [0]*32) 
 50   
51 -class TestQueryOnDiskID(pike.test.PikeTest):
52 test_files = [ "qfid_file.bin", "qfid_same_file.bin", 53 "qfid_diff_file1.bin", "qfid_diff_file2.bin" ] 54
55 - def extract_file_id(self, response):
56 """ 57 Pull out the Query On Disk ID file_id field and return it 58 """ 59 create_res = qfid_res = None 60 for child in response: 61 if isinstance(child, pike.smb2.CreateResponse): 62 create_res = child 63 break 64 self.assertIsNotNone(create_res, 65 "response didn't contain a " 66 "CreateResponse: {0}".format(response)) 67 for child in create_res: 68 if isinstance(child, pike.smb2.QueryOnDiskIDResponse): 69 qfid_res = child 70 break 71 self.assertIsNotNone(qfid_res, 72 "CreateResponse didn't contain a " 73 "QueryOnDiskIDResponse: {0}".format(create_res)) 74 return qfid_res.file_id
75
76 - def test_qfid_functional(self):
77 """ 78 Sending a QFid request should ellicit a success response 79 """ 80 81 chan, tree = self.tree_connect() 82 open_future = chan.create(tree, 83 "qfid_file.bin", 84 access=access_rwd, 85 disposition=pike.smb2.FILE_SUPERSEDE, 86 options=pike.smb2.FILE_DELETE_ON_CLOSE, 87 query_on_disk_id=True) 88 fh = open_future.result() 89 fid = self.extract_file_id(open_future.request_future.result()) 90 self.assertNotEqual(fid, 91 null_fid, 92 "On disk file_id was null")
93
94 - def test_qfid_same_file(self):
95 """ 96 Opening the same file from different sessions should return the same id 97 """ 98 99 chan1, tree1 = self.tree_connect() 100 chan2, tree2 = self.tree_connect() 101 open_future1 = chan1.create(tree1, 102 "qfid_same_file.bin", 103 access=access_rwd, 104 share=share_all, 105 disposition=pike.smb2.FILE_SUPERSEDE, 106 options=pike.smb2.FILE_DELETE_ON_CLOSE, 107 query_on_disk_id=True) 108 fh1 = open_future1.result() 109 fid1 = self.extract_file_id(open_future1.request_future.result()) 110 open_future2 = chan2.create(tree2, 111 "qfid_same_file.bin", 112 access=access_rwd, 113 share=share_all, 114 disposition=pike.smb2.FILE_OPEN, 115 query_on_disk_id=True) 116 fh2 = open_future2.result() 117 fid2 = self.extract_file_id(open_future2.request_future.result()) 118 self.assertNotEqual(fid1, 119 null_fid, 120 "On disk file_id was null") 121 self.assertEqual(fid1, fid2, 122 "On disk file_id for same file didn't match")
123
124 - def test_qfid_diff_file(self):
125 """ 126 Opening a different file from different sessions should NOT return 127 the same id 128 """ 129 130 chan1, tree1 = self.tree_connect() 131 chan2, tree2 = self.tree_connect() 132 open_future1 = chan1.create(tree1, 133 "qfid_diff_file1.bin", 134 access=access_rwd, 135 disposition=pike.smb2.FILE_SUPERSEDE, 136 options=pike.smb2.FILE_DELETE_ON_CLOSE, 137 query_on_disk_id=True) 138 fh1 = open_future1.result() 139 fid1 = self.extract_file_id(open_future1.request_future.result()) 140 open_future2 = chan2.create(tree2, 141 "qfid_diff_file2.bin", 142 access=access_rwd, 143 disposition=pike.smb2.FILE_SUPERSEDE, 144 options=pike.smb2.FILE_DELETE_ON_CLOSE, 145 query_on_disk_id=True) 146 fh2 = open_future2.result() 147 fid2 = self.extract_file_id(open_future2.request_future.result()) 148 self.assertNotEqual(fid1, 149 null_fid, 150 "On disk file_id was null") 151 self.assertNotEqual(fid1, fid2, 152 "On disk file_id for different files was the same")
153
154 - def test_qfid_same_file_seq(self):
155 """ 156 Opening the same file name after closing the first file should return 157 the same on disk id 158 """ 159 160 chan, tree = self.tree_connect() 161 open_future = chan.create(tree, 162 "qfid_file.bin", 163 access=access_rwd, 164 disposition=pike.smb2.FILE_SUPERSEDE, 165 query_on_disk_id=True) 166 fh = open_future.result() 167 fid = self.extract_file_id(open_future.request_future.result()) 168 self.assertNotEqual(fid, 169 null_fid, 170 "On disk file_id was null") 171 first_fid = fid 172 chan.close(fh) 173 174 open_future = chan.create(tree, 175 "qfid_file.bin", 176 access=access_rwd, 177 disposition=pike.smb2.FILE_OPEN, 178 options=pike.smb2.FILE_DELETE_ON_CLOSE, 179 query_on_disk_id=True) 180 fh = open_future.result() 181 fid = self.extract_file_id(open_future.request_future.result()) 182 self.assertNotEqual(fid, 183 null_fid, 184 "On disk file_id was null") 185 self.assertEqual(fid, first_fid, 186 "Subsequent open returns different file id")
187
189 """ 190 Opening the same file name after deleting the first file should return 191 a different on disk id 192 """ 193 194 chan, tree = self.tree_connect() 195 open_future = chan.create(tree, 196 "qfid_file.bin", 197 access=access_rwd, 198 disposition=pike.smb2.FILE_SUPERSEDE, 199 options=pike.smb2.FILE_DELETE_ON_CLOSE, 200 query_on_disk_id=True) 201 fh = open_future.result() 202 fid = self.extract_file_id(open_future.request_future.result()) 203 self.assertNotEqual(fid, 204 null_fid, 205 "On disk file_id was null") 206 first_fid = fid 207 chan.close(fh) 208 209 open_future = chan.create(tree, 210 "qfid_file.bin", 211 access=access_rwd, 212 disposition=pike.smb2.FILE_CREATE, 213 options=pike.smb2.FILE_DELETE_ON_CLOSE, 214 query_on_disk_id=True) 215 fh = open_future.result() 216 fid = self.extract_file_id(open_future.request_future.result()) 217 self.assertNotEqual(fid, 218 null_fid, 219 "On disk file_id was null") 220 self.assertNotEqual(fid, first_fid, 221 "Subsequent open after delete returns same file id")
222