@@ -416,24 +416,17 @@ def _run(self, command, src, dst, *options):
416416 self .assertEqual (result , 0 )
417417
418418
419- def backup (self , * options ):
419+ def backup (self , src , dst , * options ):
420420 """Invoke the program to backup snapshots/subvolumes."""
421- self ._run ("backup" , self . _snapshots , self . _backups , * options )
421+ self ._run ("backup" , src , dst , * options )
422422
423423
424- def restore (self , * options , reverse = False ):
424+ def restore (self , src , dst , * options , ** kwargs ):
425425 """Invoke the program to restore snapshots/subvolumes."""
426- if not reverse :
427- src = self ._backups
428- dst = self ._snapshots
429- else :
430- src = self ._snapshots
431- dst = self ._backups
432-
433426 self ._run ("restore" , src , dst , * options )
434427
435428
436- def performTest (self , backup , restore ):
429+ def performTest (self , backup , restore , src , dst ):
437430 """Test a simple run of the program with two subvolumes."""
438431 with alias (self ._mount ) as m ,\
439432 alias (self ._backup ) as b :
@@ -442,15 +435,15 @@ def performTest(self, backup, restore):
442435
443436 # Case 1) Run in ordinary fashion to backup data into a
444437 # separate btrfs backup volume.
445- backup ()
438+ backup (src , dst )
446439 self .assertEqual (len (glob (b .path ("backup" , "*" ))), 2 )
447440
448441 # Case 2) Delete all created snapshots (really only the
449442 # snapshots for now) from our "source" and try
450443 # restoring them from the backup.
451444 self .wipeSubvolumes (self ._snapshots )
452445
453- restore ("--snapshots-only" )
446+ restore (dst , src , "--snapshots-only" )
454447 user , root = glob (m .path ("snapshots" , "*" ))
455448
456449 self .assertContains (m .path (user , "data" , "movie.mp4" ), "abcdefgh" )
@@ -462,7 +455,7 @@ def performTest(self, backup, restore):
462455 self .wipeSubvolumes (self ._snapshots )
463456
464457 # This time we use the '--reverse' option.
465- restore ("--reverse" , "--snapshots-only" , reverse = True )
458+ restore ("--reverse" , "--snapshots-only" , src , dst , reverse = True )
466459
467460 user , root = glob (m .path ("snapshots" , "*" ))
468461
@@ -475,7 +468,7 @@ def performTest(self, backup, restore):
475468 self .wipeSubvolumes (m .path (), pattern = "root" )
476469 self .wipeSubvolumes (m .path ("snapshots" ))
477470
478- restore ()
471+ restore (dst , src )
479472
480473 user , = glob (m .path ("home" , "user" ))
481474 root , = glob (m .path ("root" ))
@@ -486,14 +479,14 @@ def performTest(self, backup, restore):
486479
487480 def testNormalRun (self ):
488481 """Test backup and restore."""
489- self .performTest (self .backup , self .restore )
482+ self .performTest (self .backup , self .restore , self . _snapshots , self . _backups )
490483
491484
492485 def testGpgRun (self ):
493486 """Test backup and restore with end-to-end encryption by GnuPG."""
494487 # TODO: It could make sense to have the destination volume being
495488 # backed by a file system other than btrfs.
496- def backup (* options ):
489+ def backup (src , dst , * options ):
497490 """Invoke the program to backup snapshots/subvolumes in an encrypted way."""
498491 gpg_options = "--encrypt --no-default-keyring " \
499492 "--keyring={pubkey} --trust-model=always " \
@@ -504,9 +497,9 @@ def backup(*options):
504497 "--snapshot-ext=gpg" ,
505498 "--recv-filter=%s %s" % (GPG , gpg_options ),
506499 ]
507- self .backup (* options )
500+ self .backup (src , dst , * options )
508501
509- def restore (* options , reverse = False ):
502+ def restore (src , dst , * options , reverse = False ):
510503 """Invoke the program to restore snapshots/subvolumes from an encrypted source."""
511504 filt = "recv" if reverse else "send"
512505 gpg_options = "--decrypt --no-default-keyring " \
@@ -520,7 +513,7 @@ def restore(*options, reverse=False):
520513 "--%s-filter=%s %s" % (filt , GPG , gpg_options ),
521514 "--join" ,
522515 ]
523- self .restore (* options , reverse = reverse )
516+ self .restore (src , dst , * options , reverse = reverse )
524517
525518 try :
526519 GPG = findCommand ("gpg" )
@@ -540,7 +533,7 @@ def restore(*options, reverse=False):
540533 execute (GPG , "--dearmor" , stdin = stdin , stdout = private_key .fileno ())
541534
542535 # Invoke the test but have it run with the functions using GPG.
543- self .performTest (backup , restore )
536+ self .performTest (backup , restore , self . _snapshots , self . _backups )
544537
545538
546539if __name__ == "__main__" :
0 commit comments