Skip to content

Commit

Permalink
fix remote tests
Browse files Browse the repository at this point in the history
... and break the RPC API
  • Loading branch information
ThomasWaldmann committed Jul 26, 2016
1 parent c06d13a commit 2c0333e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion borg/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def wrapper(self, args, **kwargs):
if argument(args, fake):
return method(self, args, repository=None, **kwargs)
elif location.proto == 'ssh':
repository = RemoteRepository(location, create=create, lock_wait=self.lock_wait, lock=lock, args=args)
repository = RemoteRepository(location, create=create, exclusive=argument(args, exclusive),
lock_wait=self.lock_wait, lock=lock, args=args)
else:
repository = Repository(location.path, create=create, exclusive=argument(args, exclusive),
lock_wait=self.lock_wait, lock=lock)
Expand Down
9 changes: 5 additions & 4 deletions borg/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def serve(self):
def negotiate(self, versions):
return RPC_PROTOCOL_VERSION

def open(self, path, create=False, lock_wait=None, lock=True):
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=False):
path = os.fsdecode(path)
if path.startswith('/~'):
path = path[1:]
Expand All @@ -124,7 +124,8 @@ def open(self, path, create=False, lock_wait=None, lock=True):
break
else:
raise PathNotAllowed(path)
self.repository = Repository(path, create, lock_wait=lock_wait, lock=lock, append_only=self.append_only)
self.repository = Repository(path, create, lock_wait=lock_wait, lock=lock, append_only=self.append_only,
exclusive=exclusive)
self.repository.__enter__() # clean exit handled by serve() method
return self.repository.id

Expand All @@ -136,7 +137,7 @@ class RPCError(Exception):
def __init__(self, name):
self.name = name

def __init__(self, location, create=False, lock_wait=None, lock=True, args=None):
def __init__(self, location, create=False, exclusive=False, lock_wait=None, lock=True, args=None):
self.location = self._location = location
self.preload_ids = []
self.msgid = 0
Expand Down Expand Up @@ -172,7 +173,7 @@ def __init__(self, location, create=False, lock_wait=None, lock=True, args=None)
if version != RPC_PROTOCOL_VERSION:
raise Exception('Server insisted on using unsupported protocol version %d' % version)
try:
self.id = self.call('open', self.location.path, create, lock_wait, lock)
self.id = self.call('open', self.location.path, create, lock_wait, lock, exclusive)
except Exception:
self.close()
raise
Expand Down
6 changes: 4 additions & 2 deletions borg/testsuite/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def test_crash_before_compact(self):
class RemoteRepositoryTestCase(RepositoryTestCase):

def open(self, create=False):
return RemoteRepository(Location('__testsuite__:' + os.path.join(self.tmppath, 'repository')), create=create)
return RemoteRepository(Location('__testsuite__:' + os.path.join(self.tmppath, 'repository')),
exclusive=True, create=create)

def test_invalid_rpc(self):
self.assert_raises(InvalidRPCMethod, lambda: self.repository.call('__init__', None))
Expand Down Expand Up @@ -383,7 +384,8 @@ class MockArgs:
class RemoteRepositoryCheckTestCase(RepositoryCheckTestCase):

def open(self, create=False):
return RemoteRepository(Location('__testsuite__:' + os.path.join(self.tmppath, 'repository')), create=create)
return RemoteRepository(Location('__testsuite__:' + os.path.join(self.tmppath, 'repository')),
exclusive=True, create=create)

def test_crash_before_compact(self):
# skip this test, we can't mock-patch a Repository class in another process!
Expand Down

0 comments on commit 2c0333e

Please sign in to comment.