3
3
''' An automated test of the backends. '''
6
from helper_functions import *
10
The helper_functions module contains debug() and verbose() functions which are
11
used for printing output.
13
set_debug(debug=True, debug_print_origin=False, verbose=True)
8
16
'''Copy & Paste code from main.py --info for automatically getting all backends.'''
9
backends = ['rdiff_backup']
11
'''Of perhaps we need a directory of schedule files to execute?'''
17
backends = ['rdiff-backup']
20
b = b.replace('-','_')
14
21
__import__('backends.' + b)
23
'''Delete previous contents of tests folder.'''
24
if path.exists('tests'):
25
shutil.rmtree('tests')
27
'''Make sure that worked.'''
28
if not path.exists('tests'):
29
print "Oh no! 'tests' did not get created."
32
'''Create folder to backup.'''
33
orig = tarfile.open('test files.tar.gz')
34
orig.extractall("tests")
37
lsoutput = safely_pipe("ls -lR", cd="tests/orig")
40
'''Save ls output to file.'''
41
h = open("tests/lsorig.txt", 'w')
45
raw_input('Press Enter to Continue, Ctrl+C to quit')
17
48
print "Testing %s" % b
18
orig = tarfile.open('test files.tar.gz')
21
print "Creating backup-esperanto command..."
25
retcode = subprocess.call(cmd, shell=True)
27
print "\nBackup succeeded."
29
print >>sys.stderr, "Error! Child was terminated by signal", \
32
print >>sys.stderr, "Error! Child returned", retcode
34
print >>sys.stderr, "Execution failed:", e
50
print "Creating backup-esperanto run command..."
51
cmd = ('python main.py run -i --debug --file "test1.schedule" ' +
52
'--backend ' + b + ' --destination "tests/' + b + '"')
54
print "Running command..."
56
raw_input('Press Enter to Continue, Ctrl+C to quit')
58
print "Creating list-snapshots command..."
59
cmd = ('python main.py list-snapshots --file "test1.schedule"' +
60
' --backend ' + b + ' --destination "tests/' + b + '"')
62
print "Store those values in a variable."
63
output = safely_pipe(cmd)
64
print horizontal_line()
65
print "Command returned:"
67
print horizontal_line()
68
raw_input('Press Enter to Continue, Ctrl+C to quit')
69
'''Split up output by newlines.'''
70
output = output.strip().splitlines()
71
snapshot = output.pop()
72
print("latest snapshot = %s" % snapshot)
74
print("Creating restore command...")
75
cmd = ('python main.py restore -i --debug "' + snapshot + ':/" ' +
76
' "tests/orig-' + b + '" --file "test1.schedule"' )
79
'''Run ls again, save output.'''
80
restore_lsouput = safely_pipe("ls -lR", cd=("tests/orig-" + b))
81
h = open("tests/lsoutput_" + b, 'w')
82
h.write(restore_lsouput)
84
'''TODO: Compare restore_lsoutput for each backend to see if they're
b'\\ No newline at end of file'