2
# "-u": Force stdin, stdout and stderr to be totally unbuffered.
3
# To get more accurate log files
6
# http://www.faqts.com/knowledge_base/entry/versions/index.phtml?aid=4419
8
from optparse import OptionParser
11
sys.path.insert(0, "../DistUpgrade")
17
from UpgradeTestBackend import UpgradeTestBackend
19
# FIXME: move this into the generic backend code
22
d = backend._unpackToTmpdir(backend.tarball)
23
print "logging into: '%s'" % d
24
backend._runInChroot(d, ["/bin/sh"])
34
def createBackend(backend_name, profile, basedir):
36
backend_modul = __import__(backend_name)
37
backend_class = getattr(backend_modul, backend_name)
38
except (ImportError, AttributeError, TypeError), e:
39
print "Can not import: %s (%s) " % (backend_name, e)
41
return backend_class(profile, basedir)
43
def testUpgrade(backend_name, profile, basedir, add_pkgs, to_stdout=False):
44
backend = createBackend(backend_name, profile, basedir)
45
assert(backend != None)
47
if not os.path.exists(profile):
48
print "ERROR: Can't find '%s' " % profile
50
# make sure we actually have a resultdir
51
resultdir = os.path.join(os.path.dirname(profile),"result")
52
if not os.path.exists(resultdir):
53
os.makedirs(resultdir)
54
fd = os.open(os.path.join(resultdir,"bootstrap.log"),
55
os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0644)
58
#fd2 = os.open("/dev/null",os.O_RDONLY)
60
print "%s log started" % datetime.datetime.now()
64
if not backend.bootstrap():
65
print "FAILED: bootstrap for '%s'" % profile
69
if not backend.installPackages(add_pkgs):
70
print "FAILED: installPacakges '%s'" % add_pkgs
72
if not backend.upgrade():
73
print "FAILED: upgrade for '%s'" % profile
76
if not backend.test():
77
print "FAILED: test for '%s'" % profile
79
print "profile: %s worked" % profile
83
print "Caught exception in testUpgrade for '%s' (%s)" % (profile, e)
88
if __name__ == "__main__":
90
parser = OptionParser()
91
parser.add_option("-p", "--profile", dest="profile",
92
default="profile/ubuntu/DistUpgrade.cfg",
93
help="write report to FILE")
94
parser.add_option("--additinoal", "--additional-pkgs", dest="add_pkgs",
96
help="add additional pkgs before running the upgrade")
97
parser.add_option("-a", "--auto", dest="auto", default=False,
99
help="run all tests in profile/ dir")
100
parser.add_option("--bootstrap-only", "--bootstrap-only",dest="bootstrap_only",
103
help="only bootstrap the image")
104
parser.add_option("-l", "--login", dest="login", default=False,
106
help="log into the a profile")
107
parser.add_option("-b", "--backend", dest="backend",
108
default="UpgradeTestBackendQemu",
109
help="UpgradeTestBackend to use: UpgradeTestBackendChroot, UpgradeTestBackendQemu")
110
parser.add_option("-d", "--diff", dest="gen_diff",
111
default=False, action="store_true",
112
help="generate a diff of the upgraded image versus a fresh installed image")
113
parser.add_option("--stdout", "--stdout", dest="to_stdout",
114
default=False, action="store_true",
115
help="all output goes to stdout")
118
(options, args) = parser.parse_args()
119
basedir = os.getcwd()
128
# we have some profiles that have DistUpgrade.cfg.dapper
129
for d in glob.glob("./profile/*/DistUpgrade.cfg*"):
132
print "Testing '%s'" % d
133
res &= testUpgrade(options.backend, d, basedir)
135
backend = createBackend(options.backend, options.profile, basedir)
137
elif options.bootstrap_only:
138
backend = createBackend(options.backend, options.profile, basedir)
139
backend.bootstrap(force=True)
140
elif options.gen_diff:
141
backend = createBackend(options.backend, options.profile, basedir)
144
res &= testUpgrade(options.backend, options.profile, basedir, options.add_pkgs.split(","), options.to_stdout)
146
print "ERROR: exception caught '%s' " % e
148
traceback.print_exc()