~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to AutoUpgradeTester/auto-install-tester.py

  • Committer: Michael Vogt
  • Date: 2008-11-14 19:03:53 UTC
  • Revision ID: michael.vogt@ubuntu.com-20081114190353-tnrwn4pvarb9gxyb
* debian/rules 
  - remove the arch-build target
* DistUpgrade/DistUpgradeController.py:
  - improvements to the sources.list rewriting, better tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os
 
4
import os.path
 
5
import time
 
6
 
 
7
import sys
 
8
sys.path.insert(0, "../DistUpgrade")
 
9
 
 
10
from UpgradeTestBackend import UpgradeTestBackend
 
11
from UpgradeTestBackendQemu import *
 
12
 
 
13
import apt
 
14
import apt_pkg
 
15
 
 
16
if __name__ == "__main__":
 
17
 
 
18
    # create backend
 
19
    apt_pkg.Config.Set("APT::Architecture","i386")
 
20
 
 
21
    # FIXME: hardcoding pathes sucks
 
22
    basedir = "./profile/intrepid-auto-install"
 
23
    aptbasedir = os.path.join(basedir,"auto-install-test")
 
24
    profile = os.path.join(basedir, "DistUpgrade.cfg")
 
25
    backend = UpgradeTestBackendQemu(profile, profile)
 
26
    backend.bootstrap()
 
27
 
 
28
    # create dirs if needed
 
29
    for d in ["etc/apt/",
 
30
              "var/lib/dpkg",
 
31
              "var/lib/apt/lists/partial",
 
32
              "var/cache/apt/archives/partial"]:
 
33
        if not os.path.exists(os.path.join(aptbasedir,d)):
 
34
            os.makedirs(os.path.join(aptbasedir,d))
 
35
 
 
36
    # copy status file
 
37
    backend.start()
 
38
    print "copy status file"
 
39
    backend._copyFromImage("/var/lib/dpkg/status",
 
40
                           os.path.join(aptbasedir,"var/lib/dpkg/","status"))
 
41
    backend.stop()
 
42
 
 
43
    # build apt stuff (outside of the kvm)
 
44
    mirror = backend.config.get("NonInteractive","Mirror")
 
45
    dist = backend.config.get("Sources","From")
 
46
    components = backend.config.getlist("NonInteractive","Components")
 
47
    pockets =  backend.config.getlist("NonInteractive","Pockets")
 
48
    f=open(os.path.join(aptbasedir,"etc","apt","sources.list"),"w")
 
49
    f.write("deb %s %s %s\n" % (mirror, dist, " ".join(components)))
 
50
    for pocket in pockets:
 
51
        f.write("deb %s %s-%s %s\n" % (mirror, dist, pocket, " ".join(components)))
 
52
    f.close()
 
53
    
 
54
    # get a cache
 
55
    cache = apt.Cache(rootdir=os.path.abspath(aptbasedir))
 
56
    cache.update(apt.progress.TextFetchProgress())
 
57
    cache.open(apt.progress.OpProgress())
 
58
 
 
59
    # now test if we can install stuff
 
60
    backend.start()
 
61
    backend._runInImage(["apt-get","update"])
 
62
    backend.saveVMSnapshot("clean-base")
 
63
 
 
64
    # sqlite browser
 
65
    
 
66
    resultdir = os.path.join(basedir,"result")
 
67
    statusfile = open(os.path.join(resultdir,"pkgs_done.txt"),"w")
 
68
    failures = open(os.path.join(resultdir,"failures.txt"),"w")
 
69
    # now see if we can install and remove it again
 
70
    i=1
 
71
    for pkg in cache:
 
72
        print "\n\nPackage %i of %i (%s)" % (i, len(cache), float(i)/float(len(cache))*100)
 
73
 
 
74
        # skip stuff in the ubuntu-minimal that we can't install or upgrade
 
75
        if pkg.isInstalled and not pkg.isUpgradable:
 
76
            continue
 
77
        # see if we can install/upgrade the pkg
 
78
        try:
 
79
            pkg.markInstall()
 
80
        except SystemError, e:
 
81
            pkg.markKeep()
 
82
        if not (pkg.markedInstall or pkg.markedUpgrade):
 
83
            print "pkg: %s not installable" % pkg.name
 
84
            failures.write("%s markInstall()\n " % pkg.name)
 
85
            continue
 
86
        cache._depcache.Init()
 
87
 
 
88
        statusfile.write("%s\n" % pkg.name)
 
89
        # try to install it
 
90
        ret = backend._runInImage(["DEBIAN_FRONTEND=noninteractive","apt-get","install", "-y",pkg.name])
 
91
        print "apt returned: ", ret
 
92
        if ret != 0:
 
93
            print "apt returned a error"
 
94
            failures.write("%s install (%s)\n" % (pkg.name,ret))
 
95
            # FIXME: bugger, that does not seem to work, I'm unable
 
96
            # to load the state later again when a new instance of
 
97
            # kvm is loaded :(
 
98
            #backend.saveVMSnapshot("failed-install-%s" % pkg.name)
 
99
            time.sleep(5)
 
100
            backend._copyFromImage("/var/log/apt/term.log",os.path.join(basedir,"result","%s-fail.txt" % pkg.name))
 
101
        # now remove it again
 
102
        ret = backend._runInImage(["DEBIAN_FRONTEND=noninteractive","apt-get","autoremove", "-y",pkg.name])
 
103
        print "apt returned: ", ret
 
104
        if ret != 0:
 
105
            failures.write("%s remove (%s)\n" % (pkg.name,ret))
 
106
            #backend.saveVMSnapshot("failed-autoremove-%s" % pkg.name)
 
107
            time.sleep(5)
 
108
            backend._copyFromImage("/var/log/apt/term.log",os.path.join(basedir,"result","%s-fail.txt" % pkg.name))
 
109
        backend.restoreVMSnapshot("clean-base")
 
110
        statusfile.flush()
 
111
        failures.flush()
 
112
        i+=1
 
113
    # all done, stop the backend
 
114
    backend.stop()
 
115