~straemer/ubuntu/quantal/update-manager/fix-for-1058070

« back to all changes in this revision

Viewing changes to AutoUpgradeTester/UpgradeTestBackend.py

  • Committer: Package Import Robot
  • Author(s): Colin Watson, Colin Watson, Adam Conrad, Barry Warsaw, Michael Vogt, Stéphane Graber, Steve Langasek
  • Date: 2012-06-14 00:57:42 UTC
  • Revision ID: package-import@ubuntu.com-20120614005742-2tnicupbt5io911y
Tags: 1:0.163
[ Colin Watson ]
* Isolate tests from local configuration in
  /etc/update-manager/release-upgrades.d/.
* Use Python attributes rather than GObject.get_data and GObject.set_data,
  which have been removed upstream (LP: #1009859).
* Switch default view class to Gtk3 and replace python-gobject dependency
  with python-gi.
* Port away from old-style apt.Package candidateFoo and installedFoo
  properties, preferring candidate.foo and installed.foo.  In a number of
  cases we have to check whether candidate/installed is non-None first.
* Use apt_pkg.version_compare rather than apt_pkg.VersionCompare.
* Use apt_pkg.uri_to_filename rather than apt_pkg.URItoFileName.
* Use apt_pkg.TagFile (and related new-style API) rather than
  apt_pkg.ParseTagFile.
* Use apt_pkg.PackageManager rather than apt_pkg.GetPackageManager.
* Use apt_pkg.Acquire rather than apt_pkg.GetAcquire.
* Use mark_foo/marked_foo rather than markFoo/markedFoo.
* Use apt_pkg.ActionGroup rather than apt_pkg.GetPkgActionGroup.
* Use apt_pkg.ProblemResolver rather than apt_pkg.GetPkgProblemResolver.
* Use apt_pkg.read_config_file rather than apt_pkg.ReadConfigFile.
* Use new spelling of apt_pkg.DepCache methods.
* Rename several local cache methods to PEP-8 style to avoid showing up in
  the output of /usr/share/python-apt/migrate-0.8.py.
* Use apt_pkg.size_to_str rather than apt_pkg.SizeToStr.
* Use apt_pkg.PackageManager.get_archives rather than
  apt_pkg.PackageManager.GetArchives.
* Use apt_pkg.Acquire.fetch_needed rather than
  apt_pkg.Acquire.FetchNeeded.
* Use new spelling of apt_pkg.Package/Version/Dependency methods.
* Use apt_pkg.pkgsystem_lock rather than apt_pkg.PkgSystemLock.
* Use new spelling of apt_pkg dependency parsing methods.
* Use new spelling of apt_pkg.SourceList methods.
* Bump python-apt (build-)dependency to >= 0.8.0.
* Add a scheme for excluding false positives from the pyflakes test, and
  enable it by default.
* Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
  3, using gettext or ugettext as appropriate.
* Always pass bytes to hashlib.md5.update.
* Fix DistUpgradeAptCdrom to account for gzip files being opened in binary
  mode.
* Convert the last use of os.popen to subprocess.check_output, which makes
  it easier to read str rather than bytes.  (This requires Python 2.7.)
* Decode bytes read from urlopened file objects.
* UpdateManager/backend/InstallBackendSynaptic.py
  - Keep a reference to the data tuple passed to GObject.child_watch_add
    to avoid attempts to destroy it without a thread context
    (LP: #724687).
  - Open temporary synaptic selections file in text mode.
* Define __bool__ rather than __nonzero__ method in Python 3.
* sort(cmp=) and sorted(cmp=) no longer work in Python 3.  Use appropriate
  key= arguments instead.
* Fix ResourceWarning while reading /proc/mounts.
* Make update-manager-kde depend on psmisc, for killall.
* DistUpgrade/DistUpgradeView.py:
  - Use floor division in FuzzyTimeToStr.
* DistUpgrade/DistUpgradeViewText.py:
  - Flush stdout after printing confirmation message, since it doesn't
    have a trailing newline.
* Use the appropriate Unicode gettext methods in both Python 2 and 3, and
  drop lots of Python-3-unfriendly Unicode mangling as a result.
* DistUpgrade/DistUpgradeViewKDE.py:
  - Open the terminal log in binary mode.
* data/do-release-upgrade.8:
  - Provide a more useful NAME section.
* DistUpgrade/DistUpgradeCache.py:
  - Tolerate SyntaxError from attempting to import NvidiaDetector, until
    such time as a complete ubuntu-drivers-common Python 3 port is in the
    archive.
* Switch #! lines over to python3, apart from dist-upgrader which needs to
  stay as Python 2 for a while longer (and have some special arrangement
  for running with Python 3 for upgrades from >= quantal).
* Run tests under both Python 2 and 3.

[ Adam Conrad ]
* Merge branch from Michael Terry to drop auto-upgrade-tester
  from update-manager and move it into its own source package

[ Barry Warsaw ]
* Begin refactoring of Computer Janitor code by renaming and
  re-situating all of it to janitor/plugincore.  This will eventually be
  removed from here into its own separate branch.
* Merge the temporary Python 3 sprint branch back into trunk, and close
  the py3 sprint branch.
* Moved UpdateManager/backend and UpdateManager/UnitySupport.py to the
  python*-update-manager packages for apturl.

[ Michael Vogt ]
* UpdateManager/GtkProgress.py:
  - fix python-apt 0.8 API crash

[ Stéphane Graber ]
* Drop fdsend as it's not used and doesn't build with python3.
* Make update-manager-core a binary all packages (everything is python).
* Split update-manager-core into python-update-manager,
  python3-update-manager and update-manager-core.
* Build-depend and depend on python-apt >= 0.8.5~ as we need proper
  python3 support.

[ Steve Langasek ]
* tests/test_country_mirror.py: the test suite shouldn't fail if $LANG
  isn't set in the environment.
* update-manager is now using python3 as an interpreter, so fix these up
  to actually be python3 packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# TargetNonInteractive.py
2
 
#
3
 
# abstraction for non-interactive backends (like chroot, qemu)
4
 
#
5
 
 
6
 
from DistUpgrade.DistUpgradeConfigParser import DistUpgradeConfig
7
 
 
8
 
try:
9
 
    import configparser
10
 
except ImportError:
11
 
    import ConfigParser as configparser
12
 
import os
13
 
import tempfile
14
 
from shutil import rmtree
15
 
 
16
 
# refactor the code so that we have
17
 
# UpgradeTest - the controler object
18
 
# UpgradeTestImage - abstraction for chroot/qemu/xen
19
 
 
20
 
class UpgradeTestImage(object):
21
 
    def runInTarget(self, command):
22
 
        pass
23
 
    def copyToImage(self, fromFile, toFile):
24
 
        pass
25
 
    def copyFromImage(self, fromFile, toFile):
26
 
        pass
27
 
    def bootstrap(self, force=False):
28
 
        pass
29
 
    def start(self):
30
 
        pass
31
 
    def stop(self):
32
 
        pass
33
 
 
34
 
class UpgradeTestBackend(object):
35
 
    """ This is a abstrace interface that all backends (chroot, qemu)
36
 
        should implement - very basic currently :)
37
 
    """
38
 
 
39
 
    apt_options = ["-y","--allow-unauthenticated"]
40
 
 
41
 
    def __init__(self, profiledir, resultdir=""):
42
 
        " init the backend with the given profile "
43
 
        # init the dirs
44
 
        assert(profiledir != None)
45
 
        profiledir = os.path.normpath(profiledir)
46
 
        profile = os.path.join(os.path.abspath(profiledir), "DistUpgrade.cfg")
47
 
        self.upgradefilesdir = "./DistUpgrade"
48
 
 
49
 
        if os.path.exists("./post_upgrade_tests/"):
50
 
            self.post_upgrade_tests_dir = "./post_upgrade_tests/"
51
 
        else:
52
 
            self.post_upgrade_tests_dir = "/usr/share/auto-upgrade-tester/post_upgrade_tests/"
53
 
        # init the rest
54
 
        if os.path.exists(profile):
55
 
            override_cfg_d = os.path.join(profiledir, "..", "override.cfg.d")
56
 
            defaults_cfg_d = os.path.join(profiledir, "..", "defaults.cfg.d")
57
 
            self.profile = os.path.abspath(profile)
58
 
            self.config = DistUpgradeConfig(datadir=os.path.dirname(profile),
59
 
                                            name=os.path.basename(profile),
60
 
                                            override_dir=override_cfg_d,
61
 
                                            defaults_dir=defaults_cfg_d)
62
 
        else:
63
 
            raise IOError("Can't find profile '%s' (%s) " % (profile, os.getcwd()))
64
 
        if resultdir:
65
 
            base_resultdir = resultdir
66
 
        else:
67
 
            base_resultdir = self.config.getWithDefault(
68
 
                "NonInteractive", "ResultDir", "results-upgrade-tester")
69
 
        self.resultdir = os.path.abspath(
70
 
            os.path.join(base_resultdir, profiledir.split("/")[-1]))
71
 
 
72
 
        # Cleanup result directory before new run
73
 
        if os.path.exists(self.resultdir):
74
 
            rmtree(self.resultdir)
75
 
        os.makedirs(self.resultdir)
76
 
        
77
 
        self.fromDist = self.config.get("Sources","From")
78
 
        if "http_proxy" in os.environ and not self.config.has_option("NonInteractive","Proxy"):
79
 
            self.config.set("NonInteractive","Proxy", os.environ["http_proxy"])
80
 
        elif self.config.has_option("NonInteractive","Proxy"):
81
 
            proxy=self.config.get("NonInteractive","Proxy")
82
 
            os.putenv("http_proxy",proxy)
83
 
        os.putenv("DEBIAN_FRONTEND","noninteractive")
84
 
        self.cachedir = None
85
 
        try:
86
 
            self.cachedir = self.config.get("NonInteractive","CacheDebs")
87
 
        except configparser.NoOptionError:
88
 
            pass
89
 
        # init a sensible environment (to ensure proper operation if
90
 
        # run from cron)
91
 
        os.environ["PATH"] = "/usr/sbin:/usr/bin:/sbin:/bin"
92
 
 
93
 
    def installPackages(self, pkgs):
94
 
        """
95
 
        install packages in the image
96
 
        """
97
 
        pass
98
 
 
99
 
    def getSourcesListFile(self):
100
 
        """
101
 
        creates a temporary sources.list file and returns it to 
102
 
        the caller
103
 
        """
104
 
        # write new sources.list
105
 
        sourceslist = tempfile.NamedTemporaryFile()
106
 
        comps = self.config.getlist("NonInteractive","Components")
107
 
        pockets = self.config.getlist("NonInteractive","Pockets")
108
 
        mirror = self.config.get("NonInteractive","Mirror")
109
 
        sourceslist.write("deb %s %s %s\n" % (mirror, self.fromDist, " ".join(comps)))
110
 
        for pocket in pockets:
111
 
            sourceslist.write("deb %s %s-%s %s\n" % (mirror, self.fromDist,pocket, " ".join(comps)))
112
 
        sourceslist.flush()
113
 
        return sourceslist
114
 
    
115
 
    def bootstrap(self):
116
 
        " bootstaps a pristine install"
117
 
        pass
118
 
 
119
 
    def upgrade(self):
120
 
        " upgrade a given install "
121
 
        pass
122
 
 
123
 
    def test(self):
124
 
        " test if the upgrade was successful "
125
 
        pass
126
 
 
127
 
    def resultsToJunitXML(self, results, outputfile = None):
128
 
        """
129
 
        Filter results to get Junit XML output
130
 
 
131
 
        :param results: list of results. Each result is a dictionary of the form
132
 
            name: name of the test
133
 
            result: (pass, fail, error)
134
 
            time: execution time of the test in seconds
135
 
            message: optional message in case of failure or error
136
 
        :param output: Output XML to this file instead of returning the value
137
 
        """
138
 
        from xml.sax.saxutils import escape
139
 
 
140
 
        output = ""
141
 
        testsuite_name = ''
142
 
        res = [x['result'] for x in results]
143
 
        fail_count = res.count('fail')
144
 
        error_count = res.count('error')
145
 
        total_count = len(res)
146
 
        total_time = sum([x['time'] for x in results])
147
 
 
148
 
        output = """<testsuite errors="%d" failures="%d" name="%s" tests="%d" time="%.3f">\n""" % (
149
 
            error_count, fail_count, testsuite_name, total_count,total_time)
150
 
 
151
 
        for result in results:
152
 
            output += """<testcase classname="%s" name="%s" time="%.3f">\n""" % (
153
 
                self.profilename + '.PostUpgradeTest',
154
 
                result['name'][:-3], result['time'])
155
 
            if 'fail' in result['result']:
156
 
                output += """<failure type="%s">%s\n</failure>\n""" % (
157
 
                    'exception', escape(result['message']))
158
 
            elif 'error' in result['result']:
159
 
                output += """<error type="%s">%s\n</error>\n""" % (
160
 
                    'exception', escape(result['message']))
161
 
 
162
 
            output += "</testcase>\n"
163
 
        output += "</testsuite>\n"
164
 
 
165
 
        if outputfile:
166
 
            with open(outputfile, 'w') as f:
167
 
                f.write(output)
168
 
        else:
169
 
            return output