Commit dc2e9a34 by willmcgugan

Fixed some broken tests

parent 3e149d2f
......@@ -174,6 +174,10 @@ class FS(object):
pass
def close(self):
"""Close the filesystem. This will perform any shutdown related
operations required. This method will be called automatically when
an the filesystem object is cleaned up, but it is a good idea to call
it explicitly."""
self.closed = True
def __getstate__(self):
......@@ -190,9 +194,7 @@ class FS(object):
return state
def __setstate__(self,state):
self.__dict__.update(state)
#for (k,v) in state.iteritems():
# self.__dict__[k] = v
self.__dict__.update(state)
lock = state.get("_lock")
if lock is not None:
if lock:
......@@ -202,7 +204,7 @@ class FS(object):
def getmeta(self, meta_name, default=NoDefaultMeta):
"""Retrieve a meta value associated with an FS object. Meta values are
a way of an FS implementation to report potentially useful information
a way for an FS implementation to report potentially useful information
associated with the file system.
A meta key is a lower case string with no spaces. Meta keys may also
......@@ -213,7 +215,7 @@ class FS(object):
* *read_only* True if the file system can not be modified
* *network* True if the file system requires network access
* *unicode_paths* True if the file system can use unicode paths
* *unicode_paths* True if the file system supports unicode paths
* *case_insensitive_paths* True if the file system ignores the case of paths
* *atomic.makedir* True if making a directory is an atomic operation
* *atomic.rename* True if rename is an atomic operation, (and not implemented as a copy followed by a delete)
......@@ -342,6 +344,7 @@ class FS(object):
:param path: A path in the filessystem
:rtype: bool
"""
return self.isfile(path) or self.isdir(path)
......@@ -1031,7 +1034,10 @@ class FS(object):
if syspath is None:
raise NoMMapError(path)
import mmap
try:
import mmap
except ImportError:
raise NoMMapError(msg="mmap not supported")
if read_only:
f = open(syspath, 'rb')
......@@ -1044,7 +1050,7 @@ class FS(object):
f = open(syspath, 'r+b')
access = mmap.ACCESS_WRITE
m = mmap.mmap(f.fileno, 0, access=access)
m = mmap.mmap(f.fileno(), 0, access=access)
return m
......
......@@ -47,7 +47,7 @@ if not hasattr(paramiko.SFTPFile,"__enter__"):
class SFTPFS(FS):
"""A filesystem stored on a remote SFTP server.
This is basically a compatability wrapper for the excellent SFTPClient
This is basically a compatibility wrapper for the excellent SFTPClient
class in the paramiko module.
"""
......@@ -65,7 +65,7 @@ class SFTPFS(FS):
}
def __init__(self, connection, root_path="/", encoding=None, hostkey=None, username='', password=None, pkey=None):
def __init__(self, connection, root_path="/", encoding=None, hostkey=None, username='', password=None, pkey=None, agent_auth=True, no_auth=False):
"""SFTPFS constructor.
The only required argument is 'connection', which must be something
......@@ -78,7 +78,7 @@ class SFTPFS(FS):
* a paramiko.Channel instance in "sftp" mode
The kwd argument 'root_path' specifies the root directory on the remote
machine - access to files outsite this root wil be prevented.
machine - access to files outside this root wil be prevented.
:param connection: a connection string
:param root_path: The root path to open
......@@ -87,6 +87,8 @@ class SFTPFS(FS):
:param username: Name of SFTP user
:param password: Password for SFTP user
:param pkey: Public key
:param agent_auth: attempt to authorise with the user's public keys
:param no_auth: attempt to log in without any kind of authorisation
"""
......@@ -127,20 +129,29 @@ class SFTPFS(FS):
key = self.get_remote_server_key()
if hostkey != key:
raise WrongHostKeyError('Host keys do not match')
connection.start_client()
if not connection.is_authenticated():
if not connection.is_active():
raise RemoteConnectionError('Unable to connect')
if no_auth:
try:
connection.auth_none('')
except paramiko.SSHException:
pass
if not connection.is_authenticated():
try:
if pkey:
connection.auth_publickey(username, pkey)
if pkey:
connection.auth_publickey(username, pkey)
if not connection.is_authenticated() and password:
connection.auth_password(username, password)
if not connection.is_authenticated():
self._agent_auth(connection, username)
connection.auth_password(username, password)
if agent_auth and not connection.is_authenticated():
self._agent_auth(connection, username)
if not connection.is_authenticated():
connection.close()
raise RemoteConnectionError('no auth')
......@@ -163,11 +174,10 @@ class SFTPFS(FS):
agent = paramiko.Agent()
agent_keys = agent.get_keys()
if len(agent_keys) == 0:
return False
if not agent_keys:
return None
for key in agent_keys:
try:
try:
transport.auth_publickey(username, key)
return key
except paramiko.SSHException:
......@@ -383,8 +393,6 @@ class SFTPFS(FS):
return [(p, getinfo(p)) for p in
self._listdir_helper(path, paths, wildcard, full, absolute, False, False)]
@convert_os_errors
def makedir(self,path,recursive=False,allow_recreate=False):
npath = self._normpath(path)
......
......@@ -54,12 +54,12 @@ class TempFS(OSFS):
def __unicode__(self):
return u'<TempFS: %s>' % self._temp_dir
def __setstate__(self, state):
state = super(TempFS, self).__setstate__(state)
self._temp_dir = tempfile.mkdtemp(self.identifier or "TempFS", dir=self.temp_dir)
super(TempFS, self).__init__(self._temp_dir,
dir_mode=self.dir_mode,
thread_synchronize=self.thread_synchronize)
# def __setstate__(self, state):
# state = super(TempFS, self).__setstate__(state)
# self._temp_dir = tempfile.mkdtemp(self.identifier or "TempFS", dir=self.temp_dir)
# super(TempFS, self).__init__(self._temp_dir,
# dir_mode=self.dir_mode,
# thread_synchronize=self.thread_synchronize)
def close(self):
"""Removes the temporary directory.
......
......@@ -691,8 +691,7 @@ class FSTestCases(object):
fs3 = pickle.loads(pickle.dumps(self.fs,-1))
self.assert_(fs3.isfile("test1"))
def test_big_file(self):
return
def test_big_file(self):
chunk_size = 1024 * 256
num_chunks = 4
def chunk_stream():
......
......@@ -38,7 +38,8 @@ class TestRPCFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
raise
self.server_addr = ("localhost",port)
self.serve_more_requests = True
self.server_thread = threading.Thread(target=self.runServer)
self.server_thread = threading.Thread(target=self.runServer)
self.server_thread.daemon = True
self.server_thread.start()
def runServer(self):
......@@ -94,7 +95,7 @@ class TestSFTPFS(TestRPCFS):
def setUp(self):
self.startServer()
self.fs = sftpfs.SFTPFS(self.server_addr)
self.fs = sftpfs.SFTPFS(self.server_addr, no_auth=True)
def bump(self):
# paramiko doesn't like being bumped, just wait for it to timeout.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment