本文整理汇总了Python中lib.db.DB.check_upgrade方法的典型用法代码示例。如果您正苦于以下问题:Python DB.check_upgrade方法的具体用法?Python DB.check_upgrade怎么用?Python DB.check_upgrade使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.db.DB
的用法示例。
在下文中一共展示了DB.check_upgrade方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VerifyTestCase
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import check_upgrade [as 别名]
class VerifyTestCase(unittest.TestCase):
def setUp(self):
self.config = Config.get_config()
self.db = DB()
self.db.check_upgrade()
self.mark_db_ids()
self.test_folder = tempfile.mkdtemp()
self.files_folder = os.path.join(self.test_folder, "files")
self.store_folder = os.path.join(self.test_folder, "store")
self.restore_folder = os.path.join(self.test_folder, "restore")
utils.makedirs(self.files_folder)
utils.makedirs(self.store_folder)
utils.makedirs(self.restore_folder)
utils.build_file_structure(self.files_folder, 50 * const.Kilobyte, 500 * const.Kilobyte)
# Build a store object (dont save config)
# Note the careful size selection - we want backups to overflow the FolderStore.
self.store = FolderStore("teststore", "2MB", True, self.store_folder)
self.config.storage[self.store.name] = self.store
# Build the backup object (dont save config)
self.backup = Backup("testbackup")
self.backup.include_folders = [self.files_folder]
self.backup.store = self.store.name
self.backup.notify_msg = False
self.include_packages = True
self.config.backups[self.backup.name] = self.backup
# build an options object for use with the backup
self.options = BlankClass()
self.options.dry_run = False
self.options.message = False
self.options.email = False
self.options.shutdown = False
self.options.norecurse = False
self.old_pass = self.config.data_passphrase
self.config.data_passphrase = "banana"
def tearDown(self):
self.config.data_passphrase = self.old_pass
# Remove all DB records created during this test
self.clean_db()
shutil.rmtree(self.test_folder)
self.assertFalse(os.path.isdir(self.test_folder))
def testVerify(self):
# Run a full backup
b = Run("testbackup", const.FullBackup, self.options)
b.run()
# Get the times
runs = self.db.runs("testbackup")
run = runs[0]
v = Verify("testbackup", run.start_time)
self.assertTrue(v.run())
def testBadVerify(self):
# Run a full backup
b = Run("testbackup", const.FullBackup, self.options)
b.run()
# Get the times
runs = self.db.runs("testbackup")
run = runs[0]
# Get the location of the data file from the streamer
streamer = StreamOut(None, self.store, b.backup_folder)
datafile = os.path.join(self.store.root, streamer.get_path(0))
size = os.path.getsize(datafile)
# Now corrupt the data file a little
with open(datafile, "r+b") as f:
f.seek(size // 2, 0)
f.write("X")
v = Verify("testbackup", run.start_time)
self.assertRaises(Exception, v.run)
def testBadConfig(self):
# Run a full backup
b = Run("testbackup", const.FullBackup, self.options)
b.run()
# Get the times
runs = self.db.runs("testbackup")
run = runs[0]
# Delete The Config File
configfile = os.path.join(run.folder, const.ConfigName)
#.........这里部分代码省略.........
示例2: LongRunTestCase
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import check_upgrade [as 别名]
class LongRunTestCase(unittest.TestCase):
def setUp(self):
self.config = Config.get_config()
self.db = DB()
self.db.check_upgrade()
self.mark_db_ids()
self.test_folder = tempfile.mkdtemp()
self.files_folder = os.path.join(self.test_folder, "files")
self.store_folder = os.path.join(self.test_folder, "store")
self.restore_folder = os.path.join(self.test_folder, "restore")
utils.makedirs(self.files_folder)
utils.makedirs(self.store_folder)
utils.makedirs(self.restore_folder)
# Build the base set of files
with open(os.path.join(self.files_folder, "base"), "w") as f:
f.write("base")
with open(os.path.join(self.files_folder, "incr"), "w") as f:
f.write("0")
config_file = os.path.expanduser("~/.vault")
if not os.path.exists(config_file):
raise Exception("Vault test configuration file (~/.vault) does not exist")
self.store_config = ConfigParser.RawConfigParser()
self.store_config.read(config_file)
# FOLDER STORE
self.store = FolderStore("teststore", "50MB", True, self.store_folder)
# DROPBOX STORE
# self.login = self.store_config.get("DropBox", "login")
# self.password = self.store_config.get("DropBox", "password")
# self.folder = self.store_config.get("DropBox", "folder")
# self.app_key = self.store_config.get("DropBox", "app_key")
# self.app_secret_key = self.store_config.get("DropBox", "app_secret_key")
# self.store = DropBoxStore("teststore", 0, False, self.folder, self.login, self.password,
# self.app_key, self.app_secret_key)
# S3 STORE
# self.key = self.store_config.get("Amazon", "aws_access_key_id")
# self.secret_key = self.store_config.get("Amazon", "aws_secret_access_key")
# self.bucket = self.store_config.get("Amazon", "bucket")
# self.store = S3Store("teststore", 0, False, bucket=self.bucket, key=self.key, secret_key=self.secret_key)
# Now record the existance of this store
self.config.storage[self.store.name] = self.store
# Build the backup object (dont save config)
self.backup = Backup("testbackup")
self.backup.include_folders = [self.files_folder]
self.backup.store = self.store.name
self.backup.notify_msg = False
self.old_pass = self.config.data_passphrase
self.config.data_passphrase = "goofy"
self.backup.encrypt = True
self.config.backups[self.backup.name] = self.backup
# build an options object for use with the backup
self.options = BlankClass()
self.options.dry_run = False
self.options.message = False
self.options.email = False
self.options.shutdown = False
self.options.norecurse = False
# How many cycles?
self.cycles = 20
def tearDown(self):
self.config.data_passphrase = self.old_pass
# Remove all DB records created during this test
self.clean_db()
shutil.rmtree(self.test_folder)
self.assertFalse(os.path.isdir(self.test_folder))
def testLongRun(self):
# Run a full backup
b = Run(self.backup.name, const.FullBackup, self.options)
b.run()
for cycle in xrange(self.cycles):
print(str(cycle)+"\r")
time.sleep(1)
# Change some files
with open(os.path.join(self.files_folder, "incr"), "w") as f:
f.write(os.urandom(100))
with open(os.path.join(self.files_folder, str(cycle)), "w") as f:
f.write(os.urandom(100))
# Run an incr backup
b = Run(self.backup.name, const.IncrBackup, self.options)
b.run()
#.........这里部分代码省略.........
示例3: ServerTestCase
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import check_upgrade [as 别名]
class ServerTestCase(unittest.TestCase):
def setUp(self):
self.config = Config.get_config()
self.db = DB()
self.db.check_upgrade()
self.mark_db_ids()
self.test_folder = tempfile.mkdtemp()
self.files_folder = os.path.join(self.test_folder, "files")
self.store_folder = os.path.join(self.test_folder, "store")
self.restore_folder = os.path.join(self.test_folder, "restore")
utils.makedirs(self.files_folder)
utils.makedirs(self.store_folder)
utils.makedirs(self.restore_folder)
utils.build_file_structure(self.files_folder, 50 * const.Kilobyte, 500 * const.Kilobyte)
# Build a store object (dont save the config)
# Note the careful size selection - we want backups to overflow the FolderStore.
self.store = FolderStore("teststore", "2MB", True, self.store_folder)
self.config.storage[self.store.name] = self.store
# Build the backup object (dont save config)
self.backup = Backup("testbackup")
self.backup.include_folders = [self.files_folder]
self.backup.store = self.store.name
self.backup.notify_msg = False
self.old_pass = self.config.data_passphrase
self.config.data_passphrase = "goofy"
self.backup.encrypt = True
self.config.backups[self.backup.name] = self.backup
# build an options object for use with the backup
self.options = BlankClass()
self.options.dry_run = False
self.options.message = False
self.options.email = False
self.options.shutdown = False
self.options.norecurse = False
def tearDown(self):
self.config.data_passphrase = self.old_pass
# Remove all DB records created during this test
self.clean_db()
shutil.rmtree(self.test_folder)
self.assertFalse(os.path.isdir(self.test_folder))
def testBackupRestore(self):
self.backup_restore_compare()
def testCheckFiles(self):
self.backup.include_packages = True
b = Run("testbackup", const.FullBackup, self.options)
b.run()
# Check that all the right files are there.
runs = self.db.runs(self.backup.name)
self.assertEqual(len(runs), 1)
run = runs[0]
folder = run.folder
self.assertTrue(self.store.exists(os.path.join(folder, const.PackageFile + const.EncryptionSuffix)))
self.assertTrue(self.store.exists(os.path.join(folder, const.LOFFile + const.EncryptionSuffix)))
self.assertTrue(self.store.exists(os.path.join(folder, const.ConfigName + const.EncryptionSuffix)))
self.assertTrue(self.store.exists)
def testAutoManagementOfStore1(self):
# Run a set of backups that will overload the store.
# The automanaged store should continue to archive old backups as required.
# Store space reclaimation happens across all backups (i.e. any run).
# We should see older runs from the first backup disappear.
max_size, dummy, dummy = self.store.limit_details()
filesize = utils.du(self.backup.include_folders[0])
# Lets make sure we are going to do enough backups that
# the older ones will be removed.
RunCount = (max_size // filesize) + 2
last_start = None
for cycle in xrange(RunCount):
if last_start:
# Make sure we have ticked to another second since the start of the last backup.
while datetime.now() - last_start < timedelta(seconds=1):
time.sleep(0.01)
backup = Backup(self.backup.name + str(cycle))
backup.include_folders = self.backup.include_folders
backup.store = self.backup.store
backup.notify_msg = False
self.config.backups[backup.name] = backup
# Run a full backup
b = Run(backup.name, const.FullBackup, self.options)
b.run()
last_start = b.start_time
#.........这里部分代码省略.........