def test_simple2(self): # """ Take a lock in 2 different namespaces and release again # """ ns1 = "test-simple2-ns1" ns2 = "test-simple2-ns2" testbackend.createNamespace(ns1) testbackend.createNamespace(ns2) pid1 = lockedexecutable.start(testbackend.theBackend()(ns1)) pid2 = lockedexecutable.start(testbackend.theBackend()(ns2)) lockedexecutable.stop(pid1) lockedexecutable.stop(pid2)
def failscrub_test(self): # """ create a namespace # prepare it with at least 2 snapshots for scrubbing (cfr. backup_test -> testScrubbingAndSnapshotMgmtTarget) # scrub 1 snapshot -> should succeed # take a lock on the namespace # scrub the other snapshot -> should fail # """ PITReplication.testConfiguration() ns = "failscrub-test" testbackend.createNamespace(ns) target = testbackend.theBackend()(ns) def check(allss, toscrubss): self.assertEqual(PITReplication.getVolumeSnapshots(target), allss) self.assertEqual( PITReplication.getScrubSnapshots(target), toscrubss) for ss in PITReplication.getVolumeSnapshots(self.source): PITReplication.backup(self.source, target, endSnapshot=ss) check(['A', 'B', 'C', 'D', 'E', 'F'], []) PITReplication.deleteSnapshots(target, "B") check(['A', 'C', 'D', 'E', 'F'], ["C"]) pid = lockedexecutable.start(target) # self.assertRaises(Exception, # PITReplication.scrubSnapshot, # target, # "C", # 'scrub the other snapshot should fail') lockedexecutable.stop(pid)
def test_cheapInitialIncremental(self): testbackend.createNamespace("foo") backupWithMonitoring(self, self.source, testbackend.theBackend()("foo"), startSnapshot="D", endSnapshot="D")
def failscrub_test(self): # """ create a namespace # prepare it with at least 2 snapshots for scrubbing (cfr. backup_test -> testScrubbingAndSnapshotMgmtTarget) # scrub 1 snapshot -> should succeed # take a lock on the namespace # scrub the other snapshot -> should fail # """ PITReplication.testConfiguration() ns = "failscrub-test" testbackend.createNamespace(ns) target = testbackend.theBackend()(ns) def check(allss, toscrubss): self.assertEqual(PITReplication.getVolumeSnapshots(target), allss) self.assertEqual(PITReplication.getScrubSnapshots(target), toscrubss) for ss in PITReplication.getVolumeSnapshots(self.source): PITReplication.backup(self.source, target, endSnapshot=ss) check(['A', 'B', 'C', 'D', 'E', 'F'], []) PITReplication.deleteSnapshots(target, "B") check(['A', 'C', 'D', 'E', 'F'], ["C"]) pid = lockedexecutable.start(target) # self.assertRaises(Exception, # PITReplication.scrubSnapshot, # target, # "C", # 'scrub the other snapshot should fail') lockedexecutable.stop(pid)
def test_recover(self): # """ Take a lock and kill it # Try to take the lock again, this should succeed # The previous step should take at least 5 sec # """ ns = "test-recover" testbackend.createNamespace(ns) session = 1 pid = lockedexecutable.start(testbackend.theBackend()(ns), session) lockedexecutable.kill(pid) timestamp = time.time() pid = lockedexecutable.start(testbackend.theBackend()(ns)) execution_time = time.time() - timestamp self.assertTrue(execution_time >= 3 * session, 'The previous step should take at least 3 x sessiontimeout (%s) but they take %s s' % (session, execution_time)) lockedexecutable.stop(pid)
def test_mutex(self): # """ why don't we put the name of the of the test on the first line? Take a lock # Try to take the lock again, this should fail (throws exception) # The previous step should take at least 5 sec # """ ns = "test-mutex" testbackend.createNamespace(ns) session = 1 pid = lockedexecutable.start( testbackend.theBackend()(ns), lock_session_timeout=session) timestamp = time.time() self.assertRaises(lockedexecutable.LockNotTakenException, lockedexecutable.start, testbackend.theBackend()(ns)) execution_time = time.time() - timestamp self.assertTrue(execution_time >= 3 * session, 'The previous step should take at least 3 x sessiontimeout (%s) but they take %s s' % (session, execution_time)) lockedexecutable.stop(pid)
def test_Basic(self): B.testConfiguration() testbackend.createNamespace("basebackup") target = testbackend.theBackend()("basebackup") backupWithMonitoring(self, self.source, target, endSnapshot="A") backupWithMonitoring(self, self.source, target, endSnapshot="C") backupWithMonitoring(self, self.source, target, endSnapshot="E") backupWithMonitoring(self, self.source, target)
def test_sequential(self): # """Or just remove any documentation about which test is running and what it's supposed to do # so the next guy can spend half a day fixing it. # """ timestamp = time.time() ns = "test-sequential" testbackend.createNamespace(ns) session = 1 pid = lockedexecutable.start( testbackend.theBackend()(ns), lock_session_timeout=session) lockedexecutable.stop(pid) pid = lockedexecutable.start( testbackend.theBackend()(ns), lock_session_timeout=session) lockedexecutable.stop(pid) execution_time = time.time() - timestamp self.assertTrue(execution_time <= session, 'All previous steps together should be finished within the sessiontimeout (%s) but they take %s s' % (session, execution_time))
def test_ScrubbingAndSnapshotMgmtTarget(self): testbackend.createNamespace("toscrub") target = testbackend.theBackend()("toscrub") # def check(allss, toscrubss): # self.assertEqual(B.getVolumeSnapshots(target), allss) # self.assertEqual(B.getScrubSnapshots(target), toscrubss) for ss in B.getVolumeSnapshots(self.source): backupWithMonitoring(self, self.source, target, endSnapshot=ss)
def test_restore(self): ns1 = "xxx" ns2 = "yyy" for ns in [ns1, ns2]: testbackend.createNamespace(ns) self.makeDirs("DC2", ns2) DC1 = testbackend.theBackend() DC2 = Backend.LocalBackend(self.pathTo("DC2")) B.copy(self.source, DC1(ns1)) B.copy(DC1(ns1), DC1(ns2)) B.copy(DC1(ns2), DC2(ns2))
def test_Monitoring(self): B.testConfiguration() ns = "monitortest" testbackend.createNamespace(ns) target = testbackend.theBackend()(ns) self.assertEqual(B.getProgressInfo(target), None) backupWithMonitoring(self, self.source, target) info = B.getProgressInfo(target) self.assertTrue(type(info), dict) self.assertEqual(info["total_size"], info["seen"]) self.assertEqual(info["still_to_be_examined"], 0) self.assertTrue(info["sent_to_backend"] <= info["total_size"])
def failrestore_test(self): # """ create a namespace # copy a volume to it # rename the volume # take a lock on the namespace # try to rename the volume again -> should fail # """ PITReplication.testConfiguration() ns = "failrestore-test" testbackend.createNamespace(ns) target = testbackend.theBackend()(ns) PITReplication.copy(self.source, target) PITReplication.renameVolume(target, "new_name1") pid = lockedexecutable.start(target) self.assertRaises(Exception, PITReplication.renameVolume, target, "new_name2", 'rename the volume again should fail') lockedexecutable.stop(pid)
def failbackup_test(self): # """ create a namespace # backup to certain snapshot -> should succeed # take a lock on the namespace # try to backup to the end of the volume -> this should fail # """ PITReplication.testConfiguration() ns = "failbackup-test" testbackend.createNamespace(ns) target = testbackend.theBackend()(ns) PITReplication.backup(self.source, target, startSnapshot="A") pid = lockedexecutable.start(target) self.assertRaises(Exception, PITReplication.backup, self.source, target, endSnapshot="C") lockedexecutable.stop(pid)
def test_OutOfOrder(self): for ns in ["incremental", "final", "usb"]: testbackend.createNamespace(ns) backupWithMonitoring(self, self.source, testbackend.theBackend()("usb"), endSnapshot="C") backupWithMonitoring(self, self.source, testbackend.theBackend()("incremental"), startSnapshot="C") B.copy(testbackend.theBackend()("usb"), testbackend.theBackend()("final")) backupWithMonitoring(self, testbackend.theBackend()("incremental"), testbackend.theBackend()("final"))
def test_VolumeRoles(self): for ns in ["base", "inc"]: testbackend.createNamespace(ns) self.assertEqual( B.getVolumeInfo(self.source)["volume_role"], ToolCut.WanBackupVolumeRole.Normal) for s in ["B", "C", "D"]: backupWithMonitoring(self, self.source, testbackend.theBackend()("base"), endSnapshot=s) self.assertEqual( B.getVolumeInfo( testbackend.theBackend()("base"))["volume_role"], ToolCut.WanBackupVolumeRole.BackupBase) self.assertEqual( B.getVolumeSnapshots(testbackend.theBackend()("base")), ["B", "C", "D"]) backupWithMonitoring(self, self.source, testbackend.theBackend()("inc"), startSnapshot="B", endSnapshot="C") self.assertEqual( B.getVolumeInfo(testbackend.theBackend()("inc"))["volume_role"], ToolCut.WanBackupVolumeRole.BackupIncremental) self.assertEqual(B.getVolumeSnapshots(testbackend.theBackend()("inc")), ["B", "C"]) backupWithMonitoring(self, self.source, testbackend.theBackend()("inc")) self.assertEqual( B.getVolumeInfo(testbackend.theBackend()("inc"))["volume_role"], ToolCut.WanBackupVolumeRole.BackupIncremental) self.assertEqual(B.getVolumeSnapshots(testbackend.theBackend()("inc")), ["B", "C", "F"]) self.assertRaises(Exception, B.promote, testbackend.theBackend()("inc")) B.promote(testbackend.theBackend()("base")) self.assertEqual( B.getVolumeInfo(testbackend.theBackend()("base"))["volume_role"], ToolCut.WanBackupVolumeRole.Normal) self.makeDirs("copy") cpy = Backend.LocalBackend(self.getDir())("copy") B.copy(self.source, cpy) self.assertEqual( B.getVolumeInfo(cpy)["volume_role"], ToolCut.WanBackupVolumeRole.Normal)
def test_rename(self): testbackend.createNamespace("xxx") target = testbackend.theBackend()("xxx") B.copy(self.source, target) B.renameVolume(target, "new_name")
def test_Idempotency(self): testbackend.createNamespace("foo") target = testbackend.theBackend()("foo") backupWithMonitoring(self, self.source, target) backupWithMonitoring(self, self.source, target)
def setUp(self): unittest.TestCase.setUp(self) testbackend.setUp() ns = "backend-test" testbackend.createNamespace(ns) self.target = testbackend.theBackend()(ns)
def test_VolumeRoles(self): for ns in ["base", "inc"]: testbackend.createNamespace(ns) self.assertEqual(B.getVolumeInfo(self.source)["volume_role"], ToolCut.WanBackupVolumeRole.Normal) for s in ["B", "C", "D"]: backupWithMonitoring(self, self.source, testbackend.theBackend()("base"), endSnapshot=s) self.assertEqual( B.getVolumeInfo( testbackend.theBackend()("base"))["volume_role"], ToolCut.WanBackupVolumeRole.BackupBase) self.assertEqual( B.getVolumeSnapshots(testbackend.theBackend()("base")), ["B", "C", "D"]) backupWithMonitoring(self, self.source, testbackend.theBackend()("inc"), startSnapshot="B", endSnapshot="C") self.assertEqual( B.getVolumeInfo(testbackend.theBackend()("inc"))["volume_role"], ToolCut.WanBackupVolumeRole.BackupIncremental) self.assertEqual(B.getVolumeSnapshots(testbackend.theBackend()("inc")), ["B", "C"]) backupWithMonitoring(self, self.source, testbackend.theBackend()("inc")) self.assertEqual( B.getVolumeInfo(testbackend.theBackend()("inc"))["volume_role"], ToolCut.WanBackupVolumeRole.BackupIncremental) self.assertEqual(B.getVolumeSnapshots(testbackend.theBackend()("inc")), ["B", "C", "F"]) self.assertRaises(Exception, B.promote, testbackend.theBackend()("inc")) B.promote(testbackend.theBackend()("base")) self.assertEqual( B.getVolumeInfo(testbackend.theBackend()("base"))["volume_role"], ToolCut.WanBackupVolumeRole.Normal) self.makeDirs("copy") cpy = Backend.LocalBackend(self.getDir())("copy") B.copy(self.source, cpy) self.assertEqual(B.getVolumeInfo(cpy)["volume_role"], ToolCut.WanBackupVolumeRole.Normal)
def test_simple1(self): ns = "test-simple1" testbackend.createNamespace(ns) pid = lockedexecutable.start(testbackend.theBackend()(ns)) lockedexecutable.stop(pid)