Skip to content

Commit

Permalink
Merge pull request #66 from isi-mfurer/helix3
Browse files Browse the repository at this point in the history
[Helix 3] Fix minor bugs and longstanding annoyances
  • Loading branch information
isi-mfurer authored Nov 26, 2019
2 parents cb9e70b + c73648a commit 5053317
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pike/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
'test',
'transport',
]
__version_info__ = (0, 2, 21)
__version_info__ = (0, 2, 22)
__version__ = "{0}.{1}.{2}".format(*__version_info__)
12 changes: 10 additions & 2 deletions pike/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def __init__(self, request, message=None):
Exception.__init__(self, message)
self.request = request

class CallbackError(Exception):
"""
the callback was not suitable
"""

class ResponseError(Exception):
def __init__(self, response):
Exception.__init__(self, response.command, response.status)
Expand Down Expand Up @@ -222,6 +227,8 @@ def then(self, notify):
when its result becomes available. If it is already available,
it will be called immediately.
"""
if not callable(notify):
raise CallbackError("{0} is not a callable object".format(notify))
if self.response is not None:
notify(self)
else:
Expand Down Expand Up @@ -1462,7 +1469,7 @@ def close_request(self, handle):

def close_submit(self, close_req):
resp_future = self.connection.submit(close_req.parent.parent)[0]
resp_future.then(close_req.handle.dispose())
resp_future.then(lambda f: close_req.handle.dispose())
return resp_future

def close(self, handle):
Expand Down Expand Up @@ -1596,6 +1603,7 @@ def change_notify_request(
cnotify_req.file_id = handle.file_id
cnotify_req.buffer_length = buffer_length
cnotify_req.flags = flags
cnotify_req.completion_filter = completion_filter
return cnotify_req

def change_notify(
Expand All @@ -1609,7 +1617,7 @@ def change_notify(
handle,
completion_filter,
flags,
buffer_length=4096).parent.parent)[0][0]
buffer_length=4096).parent.parent)[0]

# Send an echo request and get a response
def echo(self):
Expand Down
38 changes: 18 additions & 20 deletions pike/test/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,28 @@
@pike.test.RequireDialect(0x210)
@pike.test.RequireCapabilities(pike.smb2.SMB2_GLOBAL_CAP_LEASING)
class LeaseTest(pike.test.PikeTest):
def __init__(self, *args, **kwargs):
super(LeaseTest, self).__init__(*args, **kwargs)
self.share_all = pike.smb2.FILE_SHARE_READ | pike.smb2.FILE_SHARE_WRITE | pike.smb2.FILE_SHARE_DELETE
self.lease1 = array.array('B',map(random.randint, [0]*16, [255]*16))
self.lease2 = array.array('B',map(random.randint, [0]*16, [255]*16))
self.r = pike.smb2.SMB2_LEASE_READ_CACHING
self.rw = self.r | pike.smb2.SMB2_LEASE_WRITE_CACHING
self.rh = self.r | pike.smb2.SMB2_LEASE_HANDLE_CACHING
self.rwh = self.rw | self.rh
share_all = pike.smb2.FILE_SHARE_READ | pike.smb2.FILE_SHARE_WRITE | pike.smb2.FILE_SHARE_DELETE
lease1 = array.array('B',map(random.randint, [0]*16, [255]*16))
lease2 = array.array('B',map(random.randint, [0]*16, [255]*16))
r = pike.smb2.SMB2_LEASE_READ_CACHING
rw = r | pike.smb2.SMB2_LEASE_WRITE_CACHING
rh = r | pike.smb2.SMB2_LEASE_HANDLE_CACHING
rwh = rw | rh

# Upgrade lease from RW to RWH, then break it to R
def test_lease_upgrade_break(self):
chan, tree = self.tree_connect()

# Request rw lease
handle1 = chan.create(tree,
'lease.txt',
share=self.share_all,
oplock_level=pike.smb2.SMB2_OPLOCK_LEVEL_LEASE,
lease_key = self.lease1,
lease_state = self.rw).result()

self.assertEqual(handle1.lease.lease_state, self.rw)

handle2 = chan.create(tree,
'lease.txt',
share=self.share_all,
Expand All @@ -79,7 +77,7 @@ def test_lease_upgrade_break(self):

# On break, voluntarily give up handle caching
handle2.lease.on_break(lambda state: state & ~pike.smb2.SMB2_LEASE_HANDLE_CACHING)

# Break our lease
handle3 = chan.create(tree,
'lease.txt',
Expand Down Expand Up @@ -107,35 +105,35 @@ def test_lease_break_close_ack(self):
oplock_level=pike.smb2.SMB2_OPLOCK_LEVEL_LEASE,
lease_key = self.lease1,
lease_state = self.rw).result()

# Upgrade to rwh
handle2 = chan.create(tree,
'lease.txt',
share=self.share_all,
oplock_level=pike.smb2.SMB2_OPLOCK_LEVEL_LEASE,
lease_key = self.lease1,
lease_state = self.rwh).result()

# Break our lease
handle3_future = chan.create(tree,
'lease.txt',
share=self.share_all,
oplock_level=pike.smb2.SMB2_OPLOCK_LEVEL_LEASE,
lease_key = self.lease2,
lease_state = self.rwh)

# Wait for break
handle1.lease.future.wait()

# Close second handle
chan.close(handle2)

# Now ack break
handle1.lease.on_break(lambda state: state)

# Wait for handle3
handle3 = handle3_future.result()

chan.close(handle1)
chan.close(handle3)

Expand Down

0 comments on commit 5053317

Please sign in to comment.