Fixing issue #9, removing blksize option from client if not supplied.

This commit is contained in:
Michael P. Soulier 2011-07-23 20:29:06 -04:00
parent a43773e26c
commit 949c998648
3 changed files with 7 additions and 8 deletions

View file

@ -25,8 +25,7 @@ def main():
help='filename to upload') help='filename to upload')
parser.add_option('-b', parser.add_option('-b',
'--blksize', '--blksize',
help='udp packet size to use (default: 512)', help='udp packet size to use (default: 512)')
default=512)
parser.add_option('-o', parser.add_option('-o',
'--output', '--output',
help='output file, - for stdout (default: same as download)') help='output file, - for stdout (default: same as download)')

View file

@ -19,15 +19,11 @@ class TftpClient(TftpSession):
self.iport = port self.iport = port
self.filename = None self.filename = None
self.options = options self.options = options
# FIXME: If the blksize is DEF_BLKSIZE, we should just skip sending
# it.
if self.options.has_key('blksize'): if self.options.has_key('blksize'):
size = self.options['blksize'] size = self.options['blksize']
tftpassert(types.IntType == type(size), "blksize must be an int") tftpassert(types.IntType == type(size), "blksize must be an int")
if size < MIN_BLKSIZE or size > MAX_BLKSIZE: if size < MIN_BLKSIZE or size > MAX_BLKSIZE:
raise TftpException, "Invalid blksize: %d" % size raise TftpException, "Invalid blksize: %d" % size
else:
self.options['blksize'] = DEF_BLKSIZE
def download(self, filename, output, packethook=None, timeout=SOCK_TIMEOUT): def download(self, filename, output, packethook=None, timeout=SOCK_TIMEOUT):
"""This method initiates a tftp download from the configured remote """This method initiates a tftp download from the configured remote

View file

@ -98,6 +98,10 @@ class TftpContext(object):
# Count the number of retry attempts. # Count the number of retry attempts.
self.retry_count = 0 self.retry_count = 0
def getBlocksize(self):
"""Fetch the current blocksize for this session."""
return int(self.options.get('blksize', 512))
def __del__(self): def __del__(self):
"""Simple destructor to try to call housekeeping in the end method if """Simple destructor to try to call housekeeping in the end method if
not called explicitely. Leaking file descriptors is not a good not called explicitely. Leaking file descriptors is not a good
@ -506,7 +510,7 @@ class TftpState(object):
self.context.metrics.resent_bytes += len(dat.data) self.context.metrics.resent_bytes += len(dat.data)
self.context.metrics.add_dup(dat) self.context.metrics.add_dup(dat)
else: else:
blksize = int(self.context.options['blksize']) blksize = self.context.getBlocksize()
buffer = self.context.fileobj.read(blksize) buffer = self.context.fileobj.read(blksize)
log.debug("Read %d bytes into buffer" % len(buffer)) log.debug("Read %d bytes into buffer" % len(buffer))
if len(buffer) < blksize: if len(buffer) < blksize:
@ -590,7 +594,7 @@ class TftpState(object):
self.context.fileobj.write(pkt.data) self.context.fileobj.write(pkt.data)
self.context.metrics.bytes += len(pkt.data) self.context.metrics.bytes += len(pkt.data)
# Check for end-of-file, any less than full data packet. # Check for end-of-file, any less than full data packet.
if len(pkt.data) < int(self.context.options['blksize']): if len(pkt.data) < self.context.getBlocksize():
log.info("End of file detected") log.info("End of file detected")
return None return None