[cedar-backup-svn] SF.net SVN: cedar-backup:[924] cedar-backup2/trunk
Brought to you by:
pronovic
|
From: <pro...@us...> - 2008-10-06 02:29:57
|
Revision: 924
http://cedar-backup.svn.sourceforge.net/cedar-backup/?rev=924&view=rev
Author: pronovic
Date: 2008-10-06 02:29:46 +0000 (Mon, 06 Oct 2008)
Log Message:
-----------
Add <ignore_failures> option to peer configuration.
Modified Paths:
--------------
cedar-backup2/trunk/CedarBackup2/actions/stage.py
cedar-backup2/trunk/CedarBackup2/peer.py
cedar-backup2/trunk/test/peertests.py
Modified: cedar-backup2/trunk/CedarBackup2/actions/stage.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/actions/stage.py 2008-10-06 02:11:17 UTC (rev 923)
+++ cedar-backup2/trunk/CedarBackup2/actions/stage.py 2008-10-06 02:29:46 UTC (rev 924)
@@ -253,7 +253,7 @@
configPeers = config.peers.localPeers
if configPeers is not None:
for peer in configPeers:
- localPeer = LocalPeer(peer.name, peer.collectDir)
+ localPeer = LocalPeer(peer.name, peer.collectDir, peer.ignoreFailureMode)
localPeers.append(localPeer)
logger.debug("Found local peer: [%s]" % localPeer.name)
return localPeers
@@ -283,7 +283,7 @@
localUser = _getLocalUser(config)
rcpCommand = _getRcpCommand(config, peer)
remotePeer = RemotePeer(peer.name, peer.collectDir, config.options.workingDir,
- remoteUser, rcpCommand, localUser)
+ remoteUser, rcpCommand, localUser, peer.ignoreFailureMode)
remotePeers.append(remotePeer)
logger.debug("Found remote peer: [%s]" % remotePeer.name)
return remotePeers
Modified: cedar-backup2/trunk/CedarBackup2/peer.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/peer.py 2008-10-06 02:11:17 UTC (rev 923)
+++ cedar-backup2/trunk/CedarBackup2/peer.py 2008-10-06 02:29:46 UTC (rev 924)
@@ -63,6 +63,7 @@
from CedarBackup2.filesystem import FilesystemList
from CedarBackup2.util import resolveCommand, executeCommand
from CedarBackup2.util import splitCommandLine, encodePath
+from CedarBackup2.config import VALID_FAILURE_MODES
########################################################################
@@ -110,7 +111,7 @@
# Constructor
##############
- def __init__(self, name, collectDir):
+ def __init__(self, name, collectDir, ignoreFailureMode=None):
"""
Initializes a local backup peer.
@@ -125,13 +126,18 @@
@param collectDir: Path to the peer's collect directory
@type collectDir: String representing an absolute local path on disk
+ @param ignoreFailureMode: Ignore failure mode for this peer
+ @type ignoreFailureMode: One of VALID_FAILURE_MODES
+
@raise ValueError: If the name is empty.
@raise ValueError: If collect directory is not an absolute path.
"""
self._name = None
self._collectDir = None
+ self._ignoreFailureMode = None
self.name = name
self.collectDir = collectDir
+ self.ignoreFailureMode = ignoreFailureMode
#############
@@ -172,8 +178,26 @@
"""
return self._collectDir
+ def _setIgnoreFailureMode(self, value):
+ """
+ Property target used to set the ignoreFailure mode.
+ If not C{None}, the mode must be one of the values in L{VALID_FAILURE_MODES}.
+ @raise ValueError: If the value is not valid.
+ """
+ if value is not None:
+ if value not in VALID_FAILURE_MODES:
+ raise ValueError("Ignore failure mode must be one of %s." % VALID_FAILURE_MODES)
+ self._ignoreFailureMode = value
+
+ def _getIgnoreFailureMode(self):
+ """
+ Property target used to get the ignoreFailure mode.
+ """
+ return self._ignoreFailureMode
+
name = property(_getName, _setName, None, "Name of the peer.")
collectDir = property(_getCollectDir, _setCollectDir, None, "Path to the peer's collect directory (an absolute local path).")
+ ignoreFailureMode = property(_getIgnoreFailureMode, _setIgnoreFailureMode, None, "Ignore failure mode for peer.")
#################
@@ -437,7 +461,8 @@
##############
def __init__(self, name=None, collectDir=None, workingDir=None, remoteUser=None,
- rcpCommand=None, localUser=None, rshCommand=None, cbackCommand=None):
+ rcpCommand=None, localUser=None, rshCommand=None, cbackCommand=None,
+ ignoreFailureMode=None):
"""
Initializes a remote backup peer.
@@ -471,6 +496,9 @@
@param cbackCommand: A chack-compatible command to use for executing managed actions
@type cbackCommand: String representing a system command including required arguments
+ @param ignoreFailureMode: Ignore failure mode for this peer
+ @type ignoreFailureMode: One of VALID_FAILURE_MODES
+
@raise ValueError: If collect directory is not an absolute path
"""
self._name = None
@@ -483,6 +511,7 @@
self._rshCommand = None
self._rshCommandList = None
self._cbackCommand = None
+ self._ignoreFailureMode = None
self.name = name
self.collectDir = collectDir
self.workingDir = workingDir
@@ -491,6 +520,7 @@
self.rcpCommand = rcpCommand
self.rshCommand = rshCommand
self.cbackCommand = cbackCommand
+ self.ignoreFailureMode = ignoreFailureMode
#############
@@ -671,6 +701,23 @@
"""
return self._cbackCommand
+ def _setIgnoreFailureMode(self, value):
+ """
+ Property target used to set the ignoreFailure mode.
+ If not C{None}, the mode must be one of the values in L{VALID_FAILURE_MODES}.
+ @raise ValueError: If the value is not valid.
+ """
+ if value is not None:
+ if value not in VALID_FAILURE_MODES:
+ raise ValueError("Ignore failure mode must be one of %s." % VALID_FAILURE_MODES)
+ self._ignoreFailureMode = value
+
+ def _getIgnoreFailureMode(self):
+ """
+ Property target used to get the ignoreFailure mode.
+ """
+ return self._ignoreFailureMode
+
name = property(_getName, _setName, None, "Name of the peer (a valid DNS hostname).")
collectDir = property(_getCollectDir, _setCollectDir, None, "Path to the peer's collect directory (an absolute local path).")
workingDir = property(_getWorkingDir, _setWorkingDir, None, "Path to the peer's working directory (an absolute local path).")
@@ -679,6 +726,7 @@
rcpCommand = property(_getRcpCommand, _setRcpCommand, None, "An rcp-compatible copy command to use for copying files.")
rshCommand = property(_getRshCommand, _setRshCommand, None, "An rsh-compatible command to use for remote shells to the peer.")
cbackCommand = property(_getCbackCommand, _setCbackCommand, None, "A chack-compatible command to use for executing managed actions.")
+ ignoreFailureMode = property(_getIgnoreFailureMode, _setIgnoreFailureMode, None, "Ignore failure mode for peer.")
#################
Modified: cedar-backup2/trunk/test/peertests.py
===================================================================
--- cedar-backup2/trunk/test/peertests.py 2008-10-06 02:11:17 UTC (rev 923)
+++ cedar-backup2/trunk/test/peertests.py 2008-10-06 02:29:46 UTC (rev 924)
@@ -99,7 +99,7 @@
import tarfile
import getpass
from CedarBackup2.testutil import findResources, buildPath, removedir, extractTar
-from CedarBackup2.testutil import getMaskAsMode, getLogin, runningAsRoot
+from CedarBackup2.testutil import getMaskAsMode, getLogin, runningAsRoot, failUnlessAssignRaises
from CedarBackup2.testutil import platformSupportsPermissions, platformWindows
from CedarBackup2.peer import LocalPeer, RemotePeer
from CedarBackup2.peer import DEF_RCP_COMMAND, DEF_RSH_COMMAND
@@ -178,7 +178,11 @@
"""Calls buildPath on components and then returns file mode for the file."""
return stat.S_IMODE(os.stat(self.buildPath(components)).st_mode)
+ def failUnlessAssignRaises(self, exception, object, property, value):
+ """Equivalent of L{failUnlessRaises}, but used for property assignments instead."""
+ failUnlessAssignRaises(self, exception, object, property, value)
+
###########################
# Test basic functionality
###########################
@@ -197,9 +201,11 @@
"""
name = "peer1"
collectDir = "/absolute/path/name"
- peer = LocalPeer(name, collectDir)
+ ignoreFailureMode = "all"
+ peer = LocalPeer(name, collectDir, ignoreFailureMode)
self.failUnlessEqual(name, peer.name)
self.failUnlessEqual(collectDir, peer.collectDir)
+ self.failUnlessEqual(ignoreFailureMode, peer.ignoreFailureMode)
def testBasic_003(self):
"""
@@ -212,7 +218,24 @@
self.failUnlessEqual(name, peer.name)
self.failUnlessEqual(collectDir, peer.collectDir)
+ def testBasic_004(self):
+ """
+ Make sure assignment works for all valid failure modes.
+ """
+ name = "peer1"
+ collectDir = "/absolute/path/name"
+ ignoreFailureMode = "all"
+ peer = LocalPeer(name, collectDir, ignoreFailureMode)
+ self.failUnlessEqual("all", peer.ignoreFailureMode)
+ peer.ignoreFailureMode = "none"
+ self.failUnlessEqual("none", peer.ignoreFailureMode)
+ peer.ignoreFailureMode = "daily"
+ self.failUnlessEqual("daily", peer.ignoreFailureMode)
+ peer.ignoreFailureMode = "weekly"
+ self.failUnlessEqual("weekly", peer.ignoreFailureMode)
+ self.failUnlessAssignRaises(ValueError, peer, "ignoreFailureMode", "bogus")
+
###############################
# Test checkCollectIndicator()
###############################
@@ -694,7 +717,11 @@
"""Calls buildPath on components and then returns file mode for the file."""
return stat.S_IMODE(os.stat(self.buildPath(components)).st_mode)
+ def failUnlessAssignRaises(self, exception, object, property, value):
+ """Equivalent of L{failUnlessRaises}, but used for property assignments instead."""
+ failUnlessAssignRaises(self, exception, object, property, value)
+
############################
# Tests basic functionality
############################
@@ -734,6 +761,7 @@
self.failUnlessEqual(None, peer.cbackCommand)
self.failUnlessEqual(DEF_RCP_COMMAND, peer._rcpCommandList)
self.failUnlessEqual(DEF_RSH_COMMAND, peer._rshCommandList)
+ self.failUnlessEqual(None, peer.ignoreFailureMode)
def testBasic_003(self):
"""
@@ -833,7 +861,21 @@
self.failUnlessEqual(None, peer.rshCommand)
self.failUnlessEqual(cbackCommand, peer.cbackCommand)
+ def testBasic_008(self):
+ """
+ Make sure assignment works for all valid failure modes.
+ """
+ peer = RemotePeer(name="name", remoteUser="user", ignoreFailureMode="all")
+ self.failUnlessEqual("all", peer.ignoreFailureMode)
+ peer.ignoreFailureMode = "none"
+ self.failUnlessEqual("none", peer.ignoreFailureMode)
+ peer.ignoreFailureMode = "daily"
+ self.failUnlessEqual("daily", peer.ignoreFailureMode)
+ peer.ignoreFailureMode = "weekly"
+ self.failUnlessEqual("weekly", peer.ignoreFailureMode)
+ self.failUnlessAssignRaises(ValueError, peer, "ignoreFailureMode", "bogus")
+
###############################
# Test checkCollectIndicator()
###############################
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|