~kwilliam++/+junk/backup-esperanto

« back to all changes in this revision

Viewing changes to auto_test.py

  • Committer: William Hilton
  • Date: 2008-08-04 00:58:19 UTC
  • Revision ID: wmhilton@gmail.com-20080804005819-0dfeffm5w91416b7
More command line options added; working 1st version of the automatic testing script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
3
''' An automated test of the backends. '''
4
 
 
 
4
import os
5
5
import tarfile
6
 
import subprocess
 
6
from helper_functions import *
 
7
import shutil
 
8
 
 
9
'''
 
10
The helper_functions module contains debug() and verbose() functions which are
 
11
used for printing output.
 
12
'''
 
13
set_debug(debug=True, debug_print_origin=False, verbose=True)
 
14
 
7
15
 
8
16
'''Copy & Paste code from main.py --info for automatically getting all backends.'''
9
 
backends = ['rdiff_backup']
10
 
 
11
 
'''Of perhaps we need a directory of schedule files to execute?'''
 
17
backends = ['rdiff-backup']
12
18
 
13
19
for b in backends:
 
20
    b = b.replace('-','_')
14
21
    __import__('backends.' + b)
15
22
 
 
23
'''Delete previous contents of tests folder.'''
 
24
if path.exists('tests'):
 
25
    shutil.rmtree('tests')
 
26
os.mkdir('tests')
 
27
'''Make sure that worked.'''
 
28
if not path.exists('tests'):
 
29
    print "Oh no! 'tests' did not get created."
 
30
    quit()
 
31
 
 
32
'''Create folder to backup.'''
 
33
orig = tarfile.open('test files.tar.gz')
 
34
orig.extractall("tests")
 
35
orig.close()
 
36
 
 
37
lsoutput = safely_pipe("ls -lR", cd="tests/orig")
 
38
print "lsoutput:"
 
39
print lsoutput
 
40
'''Save ls output to file.'''
 
41
h = open("tests/lsorig.txt", 'w')
 
42
h.write(lsoutput)
 
43
h.close()
 
44
print
 
45
raw_input('Press Enter to Continue, Ctrl+C to quit')
 
46
 
16
47
for b in backends:
17
48
    print "Testing %s" % b
18
 
    orig = tarfile.open('test files.tar.gz')
19
 
    orig.extractall()
20
 
    orig.close()
21
 
    print "Creating backup-esperanto command..."
22
 
    cmd = "python main.py 
23
 
    try:
24
 
        
25
 
        retcode = subprocess.call(cmd, shell=True)
26
 
        if retcode == 0:
27
 
            print "\nBackup succeeded."
28
 
        elif retcode < 0:
29
 
            print >>sys.stderr, "Error! Child was terminated by signal", \
30
 
                -retcode
31
 
        else:
32
 
            print >>sys.stderr, "Error! Child returned", retcode
33
 
    except OSError, e:
34
 
        print >>sys.stderr, "Execution failed:", e
 
49
    '''Create backup'''
 
50
    print "Creating backup-esperanto run command..."
 
51
    cmd = ('python main.py run -i --debug --file "test1.schedule" ' +
 
52
            '--backend ' + b + ' --destination "tests/' + b + '"')
 
53
    print cmd
 
54
    print "Running command..."
 
55
    safely_call(cmd)
 
56
    raw_input('Press Enter to Continue, Ctrl+C to quit')
 
57
    '''List snapshots.'''
 
58
    print "Creating list-snapshots command..."
 
59
    cmd = ('python main.py list-snapshots --file "test1.schedule"' +
 
60
            ' --backend ' + b + ' --destination "tests/' + b + '"')
 
61
    print cmd
 
62
    print "Store those values in a variable."
 
63
    output = safely_pipe(cmd)
 
64
    print horizontal_line()
 
65
    print "Command returned:"
 
66
    print output
 
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)
 
73
    '''Restore backup.'''
 
74
    print("Creating restore command...")
 
75
    cmd = ('python main.py restore -i --debug "' + snapshot + ':/" ' +
 
76
        ' "tests/orig-' + b + '" --file "test1.schedule"' )
 
77
    print cmd
 
78
    safely_call(cmd)
 
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)
 
83
    h.close()
 
84
    '''TODO: Compare restore_lsoutput for each backend to see if they're
 
85
    identical.'''
 
86
 
 
87
 
 
88
 
 
89
 
 
90
    
 
 
b'\\ No newline at end of file'