Merge lp:~robru/cupstream2distro/new-reverter into lp:cupstream2distro
- new-reverter
- Merge into trunk
Proposed by
Robert Bruce Park
on 2015-03-10
| Status: | Merged |
|---|---|
| Approved by: | Robert Bruce Park on 2015-03-10 |
| Approved revision: | 939 |
| Merged at revision: | 939 |
| Proposed branch: | lp:~robru/cupstream2distro/new-reverter |
| Merge into: | lp:cupstream2distro |
| Diff against target: |
1122 lines (+361/-522) 13 files modified
Makefile (+1/-1) citrain/build.py (+25/-14) citrain/jenkins-templates/revert.xml.tmpl (+91/-0) citrain/revert.py (+132/-0) citrain/reverter.py (+0/-205) citrain/setup_citrain.py (+1/-0) cupstream2distro/errors.py (+5/-0) cupstream2distro/packagemanager.py (+8/-63) tests/unit/__init__.py (+2/-0) tests/unit/test_packagemanager.py (+5/-231) tests/unit/test_script_build.py (+3/-4) tests/unit/test_script_revert.py (+85/-3) tests/unit/test_script_setup_citrain.py (+3/-1) |
| To merge this branch: | bzr merge lp:~robru/cupstream2distro/new-reverter |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| PS Jenkins bot | continuous-integration | Approve on 2015-03-10 | |
| Robert Bruce Park (community) | Approve on 2015-03-10 | ||
|
Review via email:
|
|||
Commit Message
New revert job.
Description of the Change
To post a comment you must log in.
| PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:964
http://
Executed test runs:
Click here to trigger a rebuild:
http://
review:
Approve
(continuous-integration)
| PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:966
http://
Executed test runs:
Click here to trigger a rebuild:
http://
review:
Approve
(continuous-integration)
lp:~robru/cupstream2distro/new-reverter
updated
on 2015-03-10
- 939. By Robert Bruce Park on 2015-03-10
-
Rewrite reverter.py with 100% test coverage.
| PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:939
http://
Executed test runs:
Click here to trigger a rebuild:
http://
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file 'Makefile' |
| 2 | --- Makefile 2015-03-03 09:45:08 +0000 |
| 3 | +++ Makefile 2015-03-10 17:39:11 +0000 |
| 4 | @@ -1,5 +1,5 @@ |
| 5 | check: check3 check2 |
| 6 | - python3 -m coverage report --include='c*/*' --show-missing --fail-under=79 |
| 7 | + python3 -m coverage report --include='c*/*' --show-missing --fail-under=85 |
| 8 | |
| 9 | check2: |
| 10 | python -m coverage run -m nose2 |
| 11 | |
| 12 | === modified file 'citrain/build.py' |
| 13 | --- citrain/build.py 2015-03-09 23:41:22 +0000 |
| 14 | +++ citrain/build.py 2015-03-10 17:39:11 +0000 |
| 15 | @@ -566,6 +566,26 @@ |
| 16 | from_archive = None |
| 17 | from_series = None |
| 18 | |
| 19 | + def delete_old_dsc(self): |
| 20 | + """Original DSC is not needed, we will generate a new one.""" |
| 21 | + for old_dsc in glob(SILO_DIR('{}_*.dsc'.format(self.name))): |
| 22 | + with suppress(OSError): |
| 23 | + log_value_of.old_dsc('Deleting!') |
| 24 | + os.remove(old_dsc) |
| 25 | + |
| 26 | + def position_source(self, from_dir): |
| 27 | + """Move the original source tree to the correct location.""" |
| 28 | + shutil.rmtree(self.path, ignore_errors=True) |
| 29 | + shutil.move(from_dir, self.path) |
| 30 | + |
| 31 | + def rename_orig_tarball(self, new_upstream): |
| 32 | + for orig_tarball in glob(SILO_DIR('{}_*.orig.*'.format(self.name))): |
| 33 | + log_value_of.orig_tarball() |
| 34 | + ext = orig_tarball.split('.')[-1] |
| 35 | + tarball = '{}_{}.orig.tar.{}'.format(self.name, new_upstream, ext) |
| 36 | + log_value_of.tarball('Renaming orig.tar to') |
| 37 | + shutil.move(orig_tarball, SILO_DIR(tarball)) |
| 38 | + |
| 39 | def collect_phase(self): |
| 40 | """Download sync packages from the sync source.""" |
| 41 | logging.info('Preparing source sync for {}.'.format(self.name)) |
| 42 | @@ -574,12 +594,8 @@ |
| 43 | self.name, self.from_archive, from_series, path=SILO_DIR()) |
| 44 | if from_dir is None: |
| 45 | raise BuildError('{} not found in archive.'.format(self.name)) |
| 46 | - for old_dsc in glob(SILO_DIR('{}_*.dsc'.format(self.name))): |
| 47 | - with suppress(OSError): |
| 48 | - log_value_of.old_dsc('Deleting!') |
| 49 | - os.remove(old_dsc) |
| 50 | - shutil.rmtree(self.path, ignore_errors=True) |
| 51 | - shutil.move(from_dir, self.path) |
| 52 | + self.delete_old_dsc() |
| 53 | + self.position_source(from_dir) |
| 54 | from_version = self.get_package_version() |
| 55 | new_version = from_version.replace('~rtm', '') |
| 56 | ppa_version = pm.get_current_version_for_series( |
| 57 | @@ -593,12 +609,7 @@ |
| 58 | new_version = V(new_version).append_tag('rtm') |
| 59 | log_value_of.new_version() |
| 60 | new_upstream = V(new_version).get_upstream() |
| 61 | - for orig_tarball in glob(SILO_DIR('{}_*.orig.*'.format(self.name))): |
| 62 | - log_value_of.orig_tarball() |
| 63 | - ext = orig_tarball.split('.')[-1] |
| 64 | - tarball = '{}_{}.orig.tar.{}'.format(self.name, new_upstream, ext) |
| 65 | - log_value_of.tarball('Renaming orig.tar to') |
| 66 | - shutil.move(orig_tarball, SILO_DIR(tarball)) |
| 67 | + self.rename_orig_tarball(new_upstream) |
| 68 | self.correct_package_changelog(new_version, self.series.name) |
| 69 | self.initialize_branch() |
| 70 | DotProject.soft_save(self.name, dest=dest_version, ours=new_version) |
| 71 | @@ -741,13 +752,13 @@ |
| 72 | getattr(BuildBase, 'post_{}_phase'.format(phase), nop)(self.silo_state) |
| 73 | |
| 74 | |
| 75 | -def main(): |
| 76 | +def main(manager=BuildManager): |
| 77 | """Execute the build, logging & saving any errors. |
| 78 | |
| 79 | :returns: 0 on success, 1 on any failure. |
| 80 | """ |
| 81 | silo_state = SiloState(env.SILONAME) |
| 82 | - buildmanager = BuildManager(silo_state) |
| 83 | + buildmanager = manager(silo_state) |
| 84 | phases = ('validate', 'clean', 'collect', 'build', 'upload', 'watch') |
| 85 | if env.WATCH_ONLY == 'true': |
| 86 | phases = ('validate', 'watch') |
| 87 | |
| 88 | === added file 'citrain/jenkins-templates/revert.xml.tmpl' |
| 89 | --- citrain/jenkins-templates/revert.xml.tmpl 1970-01-01 00:00:00 +0000 |
| 90 | +++ citrain/jenkins-templates/revert.xml.tmpl 2015-03-10 17:39:11 +0000 |
| 91 | @@ -0,0 +1,91 @@ |
| 92 | +<?xml version='1.0' encoding='UTF-8'?> |
| 93 | +<project> |
| 94 | + <actions/> |
| 95 | + <description>Perform revert of selected silo packages.</description> |
| 96 | + <logRotator> |
| 97 | + <daysToKeep>15</daysToKeep> |
| 98 | + <numToKeep>-1</numToKeep> |
| 99 | + <artifactDaysToKeep>-1</artifactDaysToKeep> |
| 100 | + <artifactNumToKeep>-1</artifactNumToKeep> |
| 101 | + </logRotator> |
| 102 | + <keepDependencies>false</keepDependencies> |
| 103 | + <properties> |
| 104 | + <hudson.security.AuthorizationMatrixProperty> |
| 105 | + <permission>hudson.model.Item.Read:ubuntu-core-dev</permission> |
| 106 | + <permission>hudson.model.Item.Cancel:ubuntu-core-dev</permission> |
| 107 | + <permission>hudson.model.Item.Build:ubuntu-core-dev</permission> |
| 108 | + <permission>hudson.model.Item.Read:canonical-ci-eng</permission> |
| 109 | + <permission>hudson.model.Item.Cancel:canonical-ci-eng</permission> |
| 110 | + <permission>hudson.model.Item.Build:canonical-ci-eng</permission> |
| 111 | + <permission>hudson.model.Item.Read:ubuntu-unity</permission> |
| 112 | + <permission>hudson.model.Item.Cancel:ubuntu-unity</permission> |
| 113 | + <permission>hudson.model.Item.Build:ubuntu-unity</permission> |
| 114 | + </hudson.security.AuthorizationMatrixProperty> |
| 115 | + <hudson.model.ParametersDefinitionProperty> |
| 116 | + <parameterDefinitions> |
| 117 | + <hudson.model.StringParameterDefinition> |
| 118 | + <name>SILONAME</name> |
| 119 | + <description>The silo you previously prepared to handle this revert in. Must be in the form of "ubuntu/landing-xxx"</description> |
| 120 | + <defaultValue>ubuntu/landing-</defaultValue> |
| 121 | + </hudson.model.StringParameterDefinition> |
| 122 | + <hudson.model.StringParameterDefinition> |
| 123 | + <name>PACKAGE_VERSIONS</name> |
| 124 | + <description>The package versions you desire to revert down to. Must be in the form of "foo=1.0 bar=2.0". Leave blank to automatically revert to the second-most-recent version.</description> |
| 125 | + <defaultValue></defaultValue> |
| 126 | + </hudson.model.StringParameterDefinition> |
| 127 | + <hudson.model.BooleanParameterDefinition> |
| 128 | + <name>DEBUG</name> |
| 129 | + <description>Print extra debugging information in the log.</description> |
| 130 | + <defaultValue>false</defaultValue> |
| 131 | + </hudson.model.BooleanParameterDefinition> |
| 132 | + </parameterDefinitions> |
| 133 | + </hudson.model.ParametersDefinitionProperty> |
| 134 | + </properties> |
| 135 | + <scm class="hudson.scm.NullSCM"/> |
| 136 | + <canRoam>false</canRoam> |
| 137 | + <disabled>false</disabled> |
| 138 | + <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> |
| 139 | + <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> |
| 140 | + <triggers class="vector"/> |
| 141 | + <builders> |
| 142 | + <hudson.tasks.Shell> |
| 143 | + <command>#!/bin/sh |
| 144 | +export LANG=en_US.UTF-8 |
| 145 | +export WORKSPACE="$PWD" |
| 146 | + |
| 147 | +cd ~/silos/$SILONAME |
| 148 | + |
| 149 | +{BINDIR}/revert.py |
| 150 | +RETVAL=$? |
| 151 | + |
| 152 | +# FIXME: this should be in python to avoid duplication with build job. |
| 153 | +if [ -d ubuntu/ ]; then |
| 154 | + for DIR in ubuntu/*; do |
| 155 | + PACKAGE=$(basename $DIR) |
| 156 | + debdiff ubuntu/${{PACKAGE}}/${{PACKAGE}}_*.dsc ${{PACKAGE}}_*.dsc 2>/dev/null >full_${{PACKAGE}}.diff |
| 157 | + done |
| 158 | +fi |
| 159 | + |
| 160 | +cp *.diff "$WORKSPACE" 2>/dev/null || true |
| 161 | + |
| 162 | +# ubuntu/ directory only contains distro versions, and only used for diffing. |
| 163 | +# This cuts our disk usage in half: |
| 164 | +rm -rf ubuntu/ build-area/ |
| 165 | + |
| 166 | +exit $RETVAL |
| 167 | +</command> |
| 168 | + </hudson.tasks.Shell> |
| 169 | + </builders> |
| 170 | + <publishers> |
| 171 | + <hudson.tasks.ArtifactArchiver> |
| 172 | + <artifacts>*.diff</artifacts> |
| 173 | + <allowEmptyArchive>true</allowEmptyArchive> |
| 174 | + <onlyIfSuccessful>false</onlyIfSuccessful> |
| 175 | + <fingerprint>false</fingerprint> |
| 176 | + <defaultExcludes>true</defaultExcludes> |
| 177 | + </hudson.tasks.ArtifactArchiver> |
| 178 | + </publishers> |
| 179 | + <buildWrappers> |
| 180 | + <org.jenkinsci.plugins.builduser.BuildUser plugin="build-user-vars-plugin@1.3"/> |
| 181 | + </buildWrappers> |
| 182 | +</project> |
| 183 | |
| 184 | === added file 'citrain/revert.py' |
| 185 | --- citrain/revert.py 1970-01-01 00:00:00 +0000 |
| 186 | +++ citrain/revert.py 2015-03-10 17:39:11 +0000 |
| 187 | @@ -0,0 +1,132 @@ |
| 188 | +#!/usr/bin/python |
| 189 | +# -*- coding: utf-8 -*- |
| 190 | +# Copyright (C) 2015 Canonical |
| 191 | +# |
| 192 | +# This program is free software; you can redistribute it and/or modify it under |
| 193 | +# the terms of the GNU General Public License as published by the Free Software |
| 194 | +# Foundation; version 3. |
| 195 | +# |
| 196 | +# This program is distributed in the hope that it will be useful, but WITHOUT |
| 197 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 198 | +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 199 | +# details. |
| 200 | +# |
| 201 | +# You should have received a copy of the GNU General Public License along with |
| 202 | +# this program; if not, write to the Free Software Foundation, Inc., |
| 203 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 204 | + |
| 205 | +"""CI Train Revert Job |
| 206 | + |
| 207 | +Revert distro packages to older versions. |
| 208 | + |
| 209 | +Usage: |
| 210 | + |
| 211 | +1. Prepare a silo, listing the packages to revert as manual source uploads. |
| 212 | + |
| 213 | +2. Run the jenkins 'revert' job, do not run this script locally. |
| 214 | + |
| 215 | +3. Publish the silo as normal. |
| 216 | + |
| 217 | +Environment variables: |
| 218 | + |
| 219 | +SILONAME |
| 220 | + The silo you've previously prepared to handle your revert. |
| 221 | + |
| 222 | +PACKAGE_VERSIONS |
| 223 | + The desired versions to revert to, in the form of "foo=1.0 bar=2.0". If |
| 224 | + you leave this blank, the second-most-recent upload will be chosen. |
| 225 | + |
| 226 | +DEBUG |
| 227 | + Enable debug infos |
| 228 | +""" |
| 229 | + |
| 230 | +from __future__ import absolute_import, division, unicode_literals |
| 231 | + |
| 232 | +import os |
| 233 | +import sys |
| 234 | + |
| 235 | +sys.path.append(os.path.dirname(os.path.dirname(__file__))) |
| 236 | + |
| 237 | +from cupstream2distro.version import V |
| 238 | +from citrain.merge_clean import MergeManager |
| 239 | +from cupstream2distro.project import DotProject |
| 240 | +from citrain.build import SourceSync, main as build_main |
| 241 | +from cupstream2distro.errors import RevertError |
| 242 | +from cupstream2distro.packagemanager import ( |
| 243 | + get_current_version_for_series, |
| 244 | + get_source_package, |
| 245 | + sort_by_date, |
| 246 | +) |
| 247 | +from cupstream2distro.utils import ( |
| 248 | + SILO_DIR, |
| 249 | + call, |
| 250 | + env, |
| 251 | + log_value_of, |
| 252 | + run_script, |
| 253 | +) |
| 254 | + |
| 255 | +SEPARATOR = '.~is.' |
| 256 | + |
| 257 | + |
| 258 | +class Revert(SourceSync): |
| 259 | + """Encode the steps necessary to revert a source package.""" |
| 260 | + versions = {} |
| 261 | + |
| 262 | + def collect_phase(self): |
| 263 | + known = sort_by_date( |
| 264 | + self.dest.getPublishedSources( |
| 265 | + exact_match=True, |
| 266 | + source_name=self.name, |
| 267 | + distro_series=self.series, |
| 268 | + pocket='Release'), |
| 269 | + all_packages=True) |
| 270 | + current = known[0].source_package_version |
| 271 | + ppa_version = get_current_version_for_series( |
| 272 | + self.name, self.series.name, dest=self.silo_ppa, all_packages=True) |
| 273 | + ppa_version = ppa_version.partition(SEPARATOR)[0] |
| 274 | + desired = self.versions.get(self.name) |
| 275 | + if not desired: |
| 276 | + try: |
| 277 | + desired = known[1].source_package_version |
| 278 | + except IndexError: |
| 279 | + raise RevertError('No previous version to revert found.') |
| 280 | + highest = V.max(current, ppa_version) |
| 281 | + highest = V(highest).create_new(self.series.version) |
| 282 | + upstream = V(highest).get_upstream() |
| 283 | + desired_upstream = V(desired).get_upstream() |
| 284 | + new_version = '{}{}{}-0ubuntu1'.format( |
| 285 | + upstream, SEPARATOR, desired_upstream) |
| 286 | + upstream = V(new_version).get_upstream() |
| 287 | + log_value_of.new_version() |
| 288 | + from_dir = get_source_package( |
| 289 | + self.name, self.dest, self.series, |
| 290 | + path=SILO_DIR(), version=desired) |
| 291 | + self.delete_old_dsc() |
| 292 | + self.position_source(from_dir) |
| 293 | + self.rename_orig_tarball(upstream) |
| 294 | + call(['dch', '-v', new_version, |
| 295 | + 'Reverting to {} due to regression.'.format(desired)], |
| 296 | + cwd=self.path) |
| 297 | + call(['dch', '-r', '-D', self.series.name, '--force-distribution', ''], |
| 298 | + cwd=self.path) |
| 299 | + self.initialize_branch() |
| 300 | + DotProject.soft_save(self.name, dest=current, ours=new_version) |
| 301 | + |
| 302 | + |
| 303 | +class RevertManager(MergeManager): |
| 304 | + """Orchestrate the reverting of packages.""" |
| 305 | + |
| 306 | + def choose_classes(self): |
| 307 | + """Revert everything.""" |
| 308 | + self.types = {Revert: self.names} |
| 309 | + for package in env.PACKAGE_VERSIONS.split(): |
| 310 | + source_name, div, version = package.partition('=') |
| 311 | + Revert.versions[source_name] = version |
| 312 | + |
| 313 | + |
| 314 | +def main(): |
| 315 | + """Execute the revert.""" |
| 316 | + return build_main(RevertManager) |
| 317 | + |
| 318 | + |
| 319 | +run_script(__name__, __doc__, main) |
| 320 | |
| 321 | === removed file 'citrain/reverter.py' |
| 322 | --- citrain/reverter.py 2015-03-09 23:41:22 +0000 |
| 323 | +++ citrain/reverter.py 1970-01-01 00:00:00 +0000 |
| 324 | @@ -1,205 +0,0 @@ |
| 325 | -#!/usr/bin/python |
| 326 | -# -*- coding: utf-8 -*- |
| 327 | -# Copyright (C) 2014 Canonical |
| 328 | -# |
| 329 | -# This program is free software; you can redistribute it and/or modify it under |
| 330 | -# the terms of the GNU General Public License as published by the Free Software |
| 331 | -# Foundation; version 3. |
| 332 | -# |
| 333 | -# This program is distributed in the hope that it will be useful, but WITHOUT |
| 334 | -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 335 | -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 336 | -# details. |
| 337 | -# |
| 338 | -# You should have received a copy of the GNU General Public License along with |
| 339 | -# this program; if not, write to the Free Software Foundation, Inc., |
| 340 | -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 341 | - |
| 342 | -from __future__ import absolute_import, division, unicode_literals |
| 343 | - |
| 344 | -import argparse |
| 345 | -import lazr |
| 346 | -import logging |
| 347 | -import os |
| 348 | -import tempfile |
| 349 | -import shutil |
| 350 | -import sys |
| 351 | -import subprocess |
| 352 | - |
| 353 | -sys.path.append(os.path.dirname(os.path.dirname(__file__))) |
| 354 | - |
| 355 | -from six.moves import input as text_input |
| 356 | - |
| 357 | -from cupstream2distro.launchpadmanager import lp |
| 358 | -from cupstream2distro import packagemanager |
| 359 | -from cupstream2distro.packagemanager import newest |
| 360 | -from cupstream2distro.version import V |
| 361 | -from cupstream2distro.utils import os_path_join_safe, run_script |
| 362 | - |
| 363 | - |
| 364 | -def main(): |
| 365 | - # Unlike the rest of the train, reverter is run manually outside |
| 366 | - # of "silo dirs", so override SILO_DIR() to just be the cwd. |
| 367 | - packagemanager.SILO_DIR = os.getcwd |
| 368 | - parser = argparse.ArgumentParser( |
| 369 | - description="Revert to previous version of the one published in the " |
| 370 | - "release pocket of selected packages") |
| 371 | - |
| 372 | - parser.add_argument( |
| 373 | - 'source', |
| 374 | - nargs='+', |
| 375 | - help='Source package name. To force a specific version to ' |
| 376 | - 'downgrade to, use source=<version>') |
| 377 | - parser.add_argument( |
| 378 | - 'commitmessage', |
| 379 | - help='Commit message to use in all packages') |
| 380 | - parser.add_argument( |
| 381 | - '--distribution', |
| 382 | - default='ubuntu', |
| 383 | - help="The destination distribution (default: ubuntu)") |
| 384 | - parser.add_argument( |
| 385 | - '--ppa', |
| 386 | - help="ppa destination if destination isn't ubuntu archives") |
| 387 | - parser.add_argument( |
| 388 | - '--series', |
| 389 | - help="force a specific series") |
| 390 | - parser.add_argument( |
| 391 | - '-d', |
| 392 | - '--debug', |
| 393 | - action='store_true', |
| 394 | - default=False, |
| 395 | - help="Enable debug infos") |
| 396 | - |
| 397 | - args = parser.parse_args() |
| 398 | - |
| 399 | - logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO, |
| 400 | - format="%(asctime)s %(levelname)s %(message)s") |
| 401 | - |
| 402 | - if args.series: |
| 403 | - try: |
| 404 | - series = lp.get_series(args.series, distro_name=args.distribution) |
| 405 | - except lazr.restfulclient.errors.NotFound: |
| 406 | - logging.error("{} doesn't exist".format(args.series)) |
| 407 | - return 1 |
| 408 | - else: |
| 409 | - series = lp.distributions[args.distribution].current_series |
| 410 | - logging.info( |
| 411 | - "Taking {} as current destination series".format(series.name)) |
| 412 | - |
| 413 | - if args.ppa: |
| 414 | - dest = lp.get_ppa(args.ppa) |
| 415 | - else: |
| 416 | - dest = lp.distributions[args.distribution].main_archive |
| 417 | - |
| 418 | - workdir = tempfile.mkdtemp() |
| 419 | - os.chdir(workdir) |
| 420 | - upload_dir = os_path_join_safe(workdir, 'upload') |
| 421 | - latest_dir = os_path_join_safe(workdir, 'latest') |
| 422 | - os.makedirs(upload_dir) |
| 423 | - os.makedirs(latest_dir) |
| 424 | - source_version_revert = {} |
| 425 | - changes_revert_path = {} |
| 426 | - for source in args.source: |
| 427 | - sourceversion = source.split('=') |
| 428 | - source_package_name = sourceversion[0] |
| 429 | - try: |
| 430 | - version_to_downgrade_to = sourceversion[1] |
| 431 | - except IndexError: |
| 432 | - # downgrade to previous version than latest published one |
| 433 | - version_to_downgrade_to = newest( |
| 434 | - dest.getPublishedSources( |
| 435 | - exact_match=True, |
| 436 | - source_name=source_package_name, |
| 437 | - distro_series=series, |
| 438 | - pocket='Release'), n=1).source_package_version |
| 439 | - source_version_revert[source_package_name] = version_to_downgrade_to |
| 440 | - logging.info("Downgrading {} to {}".format( |
| 441 | - source_package_name, version_to_downgrade_to)) |
| 442 | - |
| 443 | - confirmation = text_input( |
| 444 | - "Commit message will be:\n{}\n\n" |
| 445 | - "Ok with the versions and commit message above? [y/N] ".format( |
| 446 | - args.commitmessage)) |
| 447 | - if confirmation.lower() not in ('y', 'yes'): |
| 448 | - return 1 |
| 449 | - |
| 450 | - for source in source_version_revert: |
| 451 | - orig_tarball = None |
| 452 | - |
| 453 | - os.chdir(upload_dir) |
| 454 | - revert_version = source_version_revert[source] |
| 455 | - new_version_path = packagemanager.get_source_package_from_dest( |
| 456 | - source, |
| 457 | - dest, |
| 458 | - revert_version, |
| 459 | - series.name) |
| 460 | - |
| 461 | - os.chdir(latest_dir) |
| 462 | - latest_version = packagemanager.get_current_version_for_series( |
| 463 | - source, series.name, dest=dest) |
| 464 | - latest_version_path = packagemanager.get_source_package_from_dest( |
| 465 | - source, |
| 466 | - dest, |
| 467 | - latest_version, |
| 468 | - series.name) |
| 469 | - |
| 470 | - shutil.copy2( |
| 471 | - os_path_join_safe(latest_version_path, 'debian', 'changelog'), |
| 472 | - os_path_join_safe(new_version_path, 'debian', 'changelog')) |
| 473 | - |
| 474 | - source_upload_dir = os.path.dirname(new_version_path) |
| 475 | - os.chdir(source_upload_dir) |
| 476 | - changes_revert_path[source] = source_upload_dir |
| 477 | - |
| 478 | - for file_name in os.listdir('.'): |
| 479 | - if ".orig." in file_name: |
| 480 | - orig_tarball = file_name |
| 481 | - |
| 482 | - if not orig_tarball: |
| 483 | - logging.error("Couldn't find original tarball") |
| 484 | - return 1 |
| 485 | - |
| 486 | - new_orig_tarball = "{}_{}.is.{}.orig.{}".format( |
| 487 | - source, |
| 488 | - V(latest_version).get_upstream(), |
| 489 | - V(revert_version).get_upstream(), |
| 490 | - orig_tarball.split(".orig.")[-1]) |
| 491 | - os.rename(orig_tarball, new_orig_tarball) |
| 492 | - |
| 493 | - new_packaging_version = "{}.is.{}-0ubuntu1".format( |
| 494 | - V(latest_version).get_upstream(epoch=True), |
| 495 | - V(revert_version).get_upstream()) |
| 496 | - logging.info( |
| 497 | - "Preparing {} with version {}".format( |
| 498 | - source, new_packaging_version)) |
| 499 | - os.chdir(new_version_path) |
| 500 | - if subprocess.call(['dch', |
| 501 | - '-v', |
| 502 | - new_packaging_version, |
| 503 | - args.commitmessage]) != 0: |
| 504 | - return 1 |
| 505 | - if subprocess.call(['dch', |
| 506 | - '-r', |
| 507 | - '-D', |
| 508 | - series.name, |
| 509 | - '--force-distribution', |
| 510 | - '']) != 0: |
| 511 | - return 1 |
| 512 | - if subprocess.call(['debuild', '-S']) != 0: |
| 513 | - return 1 |
| 514 | - |
| 515 | - print(('=' * 80)) |
| 516 | - subprocess.call("cat {}/*/*/*.changes".format(upload_dir), shell=True) |
| 517 | - confirmation = text_input('Ok to upload those? [y/N] ') |
| 518 | - if confirmation.lower() not in ('y', 'yes'): |
| 519 | - return 1 |
| 520 | - |
| 521 | - for source in changes_revert_path: |
| 522 | - os.chdir(changes_revert_path[source]) |
| 523 | - subprocess.call("dput *.changes", shell=True) |
| 524 | - |
| 525 | - shutil.rmtree(workdir) |
| 526 | - return 0 |
| 527 | - |
| 528 | - |
| 529 | -run_script(__name__, __doc__, main) |
| 530 | |
| 531 | === modified file 'citrain/setup_citrain.py' |
| 532 | --- citrain/setup_citrain.py 2015-03-03 09:45:08 +0000 |
| 533 | +++ citrain/setup_citrain.py 2015-03-10 17:39:11 +0000 |
| 534 | @@ -95,6 +95,7 @@ |
| 535 | setup_job('upgrade-chroot') |
| 536 | setup_job('apt-get-clean') |
| 537 | setup_job('pbuilder-clean') |
| 538 | + setup_job('revert') |
| 539 | return 0 |
| 540 | |
| 541 | |
| 542 | |
| 543 | === modified file 'cupstream2distro/errors.py' |
| 544 | --- cupstream2distro/errors.py 2015-03-03 09:45:08 +0000 |
| 545 | +++ cupstream2distro/errors.py 2015-03-10 17:39:11 +0000 |
| 546 | @@ -51,3 +51,8 @@ |
| 547 | class MergeError(CITrainError): |
| 548 | """Exception raised when there's a problem with merging.""" |
| 549 | pass |
| 550 | + |
| 551 | + |
| 552 | +class RevertError(CITrainError): |
| 553 | + """Exception raised when there's a problem with reverting.""" |
| 554 | + pass |
| 555 | |
| 556 | === modified file 'cupstream2distro/packagemanager.py' |
| 557 | --- cupstream2distro/packagemanager.py 2015-03-09 23:41:22 +0000 |
| 558 | +++ cupstream2distro/packagemanager.py 2015-03-10 17:39:11 +0000 |
| 559 | @@ -157,7 +157,7 @@ |
| 560 | |
| 561 | |
| 562 | # TODO: Integrate these functions into Package class. |
| 563 | -def get_source_package(source_name, dest, series, path=None): |
| 564 | +def get_source_package(source_name, dest, series, path=None, version=None): |
| 565 | """Download the latest version of a package in an ubuntu archive. |
| 566 | |
| 567 | :param source_name: String name of the source package to download. |
| 568 | @@ -165,14 +165,19 @@ |
| 569 | :param series: LP distro_series object representing eg vivid, utopic, etc. |
| 570 | :param path: Absolute path where you want files downloaded. |
| 571 | Defaults to SILO_DIR()/ubuntu/source_name. |
| 572 | + :param version: The version you want to download. Leave blank for newest. |
| 573 | :returns: The path to the source tree (subdir of path param), or None. |
| 574 | """ |
| 575 | path = path or SILO_DIR('ubuntu', source_name) |
| 576 | with suppress(OSError): |
| 577 | os.makedirs(path) |
| 578 | |
| 579 | - source = newest(dest.getPublishedSources( |
| 580 | - exact_match=True, source_name=source_name, distro_series=series)) |
| 581 | + kwargs = dict( |
| 582 | + exact_match=True, source_name=source_name, distro_series=series) |
| 583 | + if version: |
| 584 | + kwargs.update(version=version) |
| 585 | + source = newest( |
| 586 | + dest.getPublishedSources(**kwargs), all_packages=bool(version)) |
| 587 | if not source: |
| 588 | logging.warning('{} not found in {}.'.format(source_name, dest.name)) |
| 589 | return None |
| 590 | @@ -237,66 +242,6 @@ |
| 591 | status=queue).total_size > 0 |
| 592 | |
| 593 | |
| 594 | -# FIXME: Only used by reverter.py; this should be deleted and |
| 595 | -# reverter.py ported to get_source_package(). |
| 596 | -def get_source_package_from_dest(source_name, |
| 597 | - dest_archive, |
| 598 | - dest_current_version, |
| 599 | - series_name, |
| 600 | - download_dir='ubuntu'): |
| 601 | - """Download and return a path containing the current dest version. |
| 602 | - |
| 603 | - None if this package was never published to dest archive. |
| 604 | - """ |
| 605 | - if dest_current_version == "0": |
| 606 | - logging.info( |
| 607 | - "This package was never released to the destination archive, " |
| 608 | - "don't return downloaded source") |
| 609 | - return None |
| 610 | - |
| 611 | - logging.info('Downloading {} {} from {} to the "{}" directory.'.format( |
| 612 | - source_name, dest_current_version, series_name, download_dir)) |
| 613 | - source_package_download_dir = os_path_join_safe( |
| 614 | - SILO_DIR(), download_dir, source_name) |
| 615 | - series = lp.get_series(series_name, dest=dest_archive) |
| 616 | - with suppress(OSError): |
| 617 | - os.makedirs(source_package_download_dir) |
| 618 | - |
| 619 | - sourcepkg = newest(dest_archive.getPublishedSources( |
| 620 | - exact_match=True, |
| 621 | - source_name=source_name, |
| 622 | - distro_series=series, |
| 623 | - version=dest_current_version), all_packages=True) |
| 624 | - if not sourcepkg: |
| 625 | - raise Exception("Couldn't get in the destination the expected version") |
| 626 | - for url in sourcepkg.sourceFileUrls(): |
| 627 | - filename = unquote(url.split('/')[-1]) |
| 628 | - filepath = os_path_join_safe(source_package_download_dir, filename) |
| 629 | - urlretrieve(url, filepath) |
| 630 | - dscs = glob(os_path_join_safe( |
| 631 | - source_package_download_dir, '*{}.dsc'.format( |
| 632 | - dest_current_version.split(':')[-1]))) |
| 633 | - instance, stdout, stderr = call( |
| 634 | - ['dpkg-source', '-x'] + dscs, cwd=source_package_download_dir) |
| 635 | - if instance.returncode != 0: |
| 636 | - raise Exception(stderr) |
| 637 | - |
| 638 | - # check the dir exist |
| 639 | - # remove epoch is there is one |
| 640 | - splitted_version = dest_current_version.split(':')[-1].split('-') |
| 641 | - if len(splitted_version) > 1: |
| 642 | - # we don't want the ubuntu or debian version (it's not in the source |
| 643 | - # package name) |
| 644 | - splitted_version = splitted_version[:-1] |
| 645 | - version_for_source_file = '-'.join(splitted_version) |
| 646 | - source_dirname = os_path_join_safe( |
| 647 | - source_package_download_dir, '{}-{}'.format( |
| 648 | - source_name, version_for_source_file)) |
| 649 | - if not os.path.isdir(source_dirname): |
| 650 | - raise Exception(source_dirname + ': Directory not found') |
| 651 | - return source_dirname |
| 652 | - |
| 653 | - |
| 654 | def _packaging_changes_between_dsc(oldsource_dsc, newsource_dsc): |
| 655 | """Return if there has been a packaging change between two dsc files. |
| 656 | |
| 657 | |
| 658 | === modified file 'tests/unit/__init__.py' |
| 659 | --- tests/unit/__init__.py 2015-03-09 23:41:22 +0000 |
| 660 | +++ tests/unit/__init__.py 2015-03-10 17:39:11 +0000 |
| 661 | @@ -193,6 +193,8 @@ |
| 662 | self.script.Package = Mock() |
| 663 | self.script.Revno = Mock() |
| 664 | self.script.SiloState = Mock() |
| 665 | + self.script.call = Mock() |
| 666 | + self.script.log_call = Mock() |
| 667 | self.script.branchhandling = Mock() |
| 668 | self.script.bh = Mock() |
| 669 | self.script.glob = Mock() |
| 670 | |
| 671 | === modified file 'tests/unit/test_packagemanager.py' |
| 672 | --- tests/unit/test_packagemanager.py 2015-03-09 23:41:22 +0000 |
| 673 | +++ tests/unit/test_packagemanager.py 2015-03-10 17:39:11 +0000 |
| 674 | @@ -17,7 +17,6 @@ |
| 675 | from __future__ import absolute_import, division, unicode_literals |
| 676 | |
| 677 | import os |
| 678 | -import shutil |
| 679 | |
| 680 | from six.moves.urllib.parse import quote |
| 681 | from six.moves import cStringIO as StringIO |
| 682 | @@ -30,7 +29,7 @@ |
| 683 | |
| 684 | from cupstream2distro import packagemanager |
| 685 | from cupstream2distro.packagemanager import Package |
| 686 | -from cupstream2distro.utils import env, os_path_join_safe, utf8_open |
| 687 | +from cupstream2distro.utils import os_path_join_safe, utf8_open |
| 688 | from cupstream2distro.errors import CITrainError, PackageError |
| 689 | |
| 690 | |
| 691 | @@ -255,7 +254,7 @@ |
| 692 | dest.getPublishedSources.assert_called_once_with( |
| 693 | exact_match=True, source_name='flubjub', distro_series=series) |
| 694 | new.assert_called_once_with( |
| 695 | - dest.getPublishedSources.return_value) |
| 696 | + dest.getPublishedSources.return_value, all_packages=False) |
| 697 | source.sourceFileUrls.assert_called_once_with() |
| 698 | urlM.assert_called_once_with( |
| 699 | 'http://example.com/flubjub_1.0+15.04.20150218.dsc', |
| 700 | @@ -291,7 +290,7 @@ |
| 701 | dest.getPublishedSources.assert_called_once_with( |
| 702 | exact_match=True, source_name='flubjub', distro_series=series) |
| 703 | new.assert_called_once_with( |
| 704 | - dest.getPublishedSources.return_value) |
| 705 | + dest.getPublishedSources.return_value, all_packages=False) |
| 706 | source.sourceFileUrls.assert_called_once_with() |
| 707 | urlM.assert_called_once_with( |
| 708 | 'http://example.com/flubjub_1.0+15.04.20150218.dsc', |
| 709 | @@ -327,7 +326,7 @@ |
| 710 | dest.getPublishedSources.assert_called_once_with( |
| 711 | exact_match=True, source_name='flubjub', distro_series=series) |
| 712 | new.assert_called_once_with( |
| 713 | - dest.getPublishedSources.return_value) |
| 714 | + dest.getPublishedSources.return_value, all_packages=False) |
| 715 | source.sourceFileUrls.assert_called_once_with() |
| 716 | urlM.assert_called_once_with( |
| 717 | 'http://example.com/flubjub_1.0+15.04.20150218.dsc', |
| 718 | @@ -361,7 +360,7 @@ |
| 719 | dest.getPublishedSources.assert_called_once_with( |
| 720 | exact_match=True, source_name='flubjub', distro_series=series) |
| 721 | new.assert_called_once_with( |
| 722 | - dest.getPublishedSources.return_value) |
| 723 | + dest.getPublishedSources.return_value, all_packages=False) |
| 724 | self.assertEqual(source.sourceFileUrls.mock_calls, []) |
| 725 | self.assertEqual(urlM.mock_calls, []) |
| 726 | self.assertEqual(callM.mock_calls, []) |
| 727 | @@ -484,231 +483,6 @@ |
| 728 | if filename.endswith('.dsc'): |
| 729 | return filename |
| 730 | |
| 731 | - @patch('cupstream2distro.packagemanager.lp') |
| 732 | - def test_get_source_package_from_dest(self, lpMock): |
| 733 | - """We grab the correct source from dest.""" |
| 734 | - env.SILONAME = 'ubuntu/landing-234' |
| 735 | - dest = Mock() |
| 736 | - dest.distribution.name = 'ubuntu' |
| 737 | - source1 = Mock() |
| 738 | - source1.status = 'Published' |
| 739 | - dest.getPublishedSources.return_value = [source1] |
| 740 | - source1.sourceFileUrls.return_value = ( |
| 741 | - self.get_source_files_for_package( |
| 742 | - 'foo_package', for_download=True)) |
| 743 | - |
| 744 | - source_package_dir = packagemanager.get_source_package_from_dest( |
| 745 | - 'foo', dest, '42.0daily83.09.13.2-0ubuntu1', 'rolling') |
| 746 | - |
| 747 | - lpMock.get_series.assert_called_with('rolling', dest=dest) |
| 748 | - dest.getPublishedSources.assert_called_once_with( |
| 749 | - exact_match=True, |
| 750 | - source_name='foo', |
| 751 | - distro_series=lpMock.get_series.return_value, |
| 752 | - version='42.0daily83.09.13.2-0ubuntu1') |
| 753 | - source1.sourceFileUrls.assert_called_once() |
| 754 | - self.assertTrue(os.path.isdir(source_package_dir)) |
| 755 | - |
| 756 | - @patch('cupstream2distro.packagemanager.lp') |
| 757 | - def test_get_source_package_from_dest_two_foo_packages(self, lpMock): |
| 758 | - """Only unpack the right source package by version.""" |
| 759 | - env.SILONAME = 'ubuntu/landing-123' |
| 760 | - dest1 = Mock() |
| 761 | - dest1.distribution.name = 'ubuntu' |
| 762 | - source1 = Mock() |
| 763 | - source1.status = 'Published' |
| 764 | - dest2 = Mock() |
| 765 | - dest2.distribution.name = 'ubuntu' |
| 766 | - source2 = Mock() |
| 767 | - source2.status = 'Published' |
| 768 | - dest1.getPublishedSources.return_value = [source1] |
| 769 | - dest2.getPublishedSources.return_value = [source2] |
| 770 | - source1.sourceFileUrls.return_value = ( |
| 771 | - self.get_source_files_for_package( |
| 772 | - 'foo_package', for_download=True)) |
| 773 | - source2.sourceFileUrls.return_value = ( |
| 774 | - self.get_source_files_for_package( |
| 775 | - 'foo_package_with_upstream_changes', for_download=True)) |
| 776 | - |
| 777 | - source_package_dir1 = packagemanager.get_source_package_from_dest( |
| 778 | - 'foo', dest1, '42.0daily83.09.13.2-0ubuntu1', 'rolling') |
| 779 | - self.assertTrue(os.path.isdir(source_package_dir1)) |
| 780 | - |
| 781 | - # to make sure that it's not extracting both .dsc's during the |
| 782 | - # get_source_package_from_dest step |
| 783 | - shutil.rmtree(source_package_dir1) |
| 784 | - |
| 785 | - source_package_dir2 = packagemanager.get_source_package_from_dest( |
| 786 | - 'foo', dest2, '42.0+13.10.20130709-0ubuntu1', 'rolling') |
| 787 | - self.assertFalse(os.path.isdir(source_package_dir1)) |
| 788 | - self.assertTrue(os.path.isdir(source_package_dir2)) |
| 789 | - |
| 790 | - @patch('cupstream2distro.packagemanager.lp') |
| 791 | - def test_get_source_package_from_dest_multiple_candidates(self, lpMock): |
| 792 | - """We grab the correct source from dest, even if more than one.""" |
| 793 | - env.SILONAME = 'hello' |
| 794 | - dest = Mock() |
| 795 | - dest.distribution.name = 'ubuntu' |
| 796 | - source1 = Mock() |
| 797 | - source1.status = 'Published' |
| 798 | - source1.date_created = datetime(2014, 1, 1) |
| 799 | - source2 = Mock() |
| 800 | - source2.status = 'Published' |
| 801 | - source2.date_created = datetime(2014, 2, 1) |
| 802 | - dest.getPublishedSources.return_value = [source1, source2] |
| 803 | - source2.sourceFileUrls.return_value = ( |
| 804 | - self.get_source_files_for_package( |
| 805 | - 'foo_package', for_download=True)) |
| 806 | - |
| 807 | - source_package_dir = packagemanager.get_source_package_from_dest( |
| 808 | - 'foo', dest, '42.0daily83.09.13.2-0ubuntu1', 'rolling') |
| 809 | - |
| 810 | - lpMock.get_series.assert_called_with('rolling', dest=dest) |
| 811 | - dest.getPublishedSources.assert_called_once_with( |
| 812 | - exact_match=True, |
| 813 | - source_name='foo', |
| 814 | - distro_series=lpMock.get_series.return_value, |
| 815 | - version='42.0daily83.09.13.2-0ubuntu1') |
| 816 | - source2.sourceFileUrls.assert_called_once() |
| 817 | - self.assertFalse(source1.sourceFileUrls.called) |
| 818 | - self.assertTrue(os.path.isdir(source_package_dir)) |
| 819 | - |
| 820 | - @patch('cupstream2distro.packagemanager.lp') |
| 821 | - def test_get_source_package_from_dest_with_epoc(self, lpMock): |
| 822 | - """We grab the correct source from dest with epoch.""" |
| 823 | - env.SILONAME = 'i-am-an-invalid-silo-name-but-thats-ok' |
| 824 | - dest = Mock() |
| 825 | - dest.distribution.name = 'ubuntu' |
| 826 | - source1 = Mock() |
| 827 | - source1.status = 'Published' |
| 828 | - dest.getPublishedSources.return_value = [source1] |
| 829 | - source1.sourceFileUrls.return_value = ( |
| 830 | - self.get_source_files_for_package( |
| 831 | - 'foo_package', for_download=True)) |
| 832 | - |
| 833 | - source_package_dir = packagemanager.get_source_package_from_dest( |
| 834 | - 'foo', dest, '1:42.0daily83.09.13.2-0ubuntu1', 'rolling') |
| 835 | - |
| 836 | - lpMock.get_series.assert_called_with('rolling', dest=dest) |
| 837 | - dest.getPublishedSources.assert_called_once_with( |
| 838 | - exact_match=True, |
| 839 | - source_name='foo', |
| 840 | - distro_series=lpMock.get_series.return_value, |
| 841 | - version='1:42.0daily83.09.13.2-0ubuntu1') |
| 842 | - source1.sourceFileUrls.assert_called_once() |
| 843 | - self.assertTrue(os.path.isdir(source_package_dir)) |
| 844 | - self.assertNotIn(':', source_package_dir) |
| 845 | - |
| 846 | - @patch('cupstream2distro.packagemanager.lp') |
| 847 | - def test_get_source_package_from_dest_for_native(self, lpMock): |
| 848 | - """We grab the correct source from dest for native packages.""" |
| 849 | - env.SILONAME = 'frumpbuntu/flailing-987' |
| 850 | - dest = Mock() |
| 851 | - dest.distribution.name = 'ubuntu' |
| 852 | - source1 = Mock() |
| 853 | - source1.status = 'Published' |
| 854 | - dest.getPublishedSources.return_value = [source1] |
| 855 | - source1.sourceFileUrls.return_value = ( |
| 856 | - self.get_source_files_for_package( |
| 857 | - 'foo_native_package', for_download=True)) |
| 858 | - |
| 859 | - source_package_dir = packagemanager.get_source_package_from_dest( |
| 860 | - 'foo', dest, '42.0daily83.09.13.2', 'rolling') |
| 861 | - |
| 862 | - lpMock.get_series.assert_called_with('rolling', dest=dest) |
| 863 | - dest.getPublishedSources.assert_called_once_with( |
| 864 | - exact_match=True, |
| 865 | - source_name='foo', |
| 866 | - distro_series=lpMock.get_series.return_value, |
| 867 | - version='42.0daily83.09.13.2') |
| 868 | - source1.sourceFileUrls.assert_called_once() |
| 869 | - self.assertTrue(os.path.isdir(source_package_dir)) |
| 870 | - |
| 871 | - @patch('cupstream2distro.packagemanager.lp') |
| 872 | - def test_get_source_package_from_dest_with_debian_version( |
| 873 | - self, lpMock): |
| 874 | - """We grab the correct source from dest with only a debian version.""" |
| 875 | - env.SILONAME = 'ubuntu/landing-000' |
| 876 | - dest = Mock() |
| 877 | - dest.distribution.name = 'ubuntu' |
| 878 | - source1 = Mock() |
| 879 | - source1.status = 'Published' |
| 880 | - dest.getPublishedSources.return_value = [source1] |
| 881 | - source1.sourceFileUrls.return_value = ( |
| 882 | - self.get_source_files_for_package( |
| 883 | - 'foo_debian_package', for_download=True)) |
| 884 | - |
| 885 | - source_package_dir = packagemanager.get_source_package_from_dest( |
| 886 | - 'foo', dest, '42.0daily83.09.13.2-1', 'rolling') |
| 887 | - |
| 888 | - lpMock.get_series.assert_called_with('rolling', dest=dest) |
| 889 | - dest.getPublishedSources.assert_called_once_with( |
| 890 | - exact_match=True, |
| 891 | - source_name='foo', |
| 892 | - distro_series=lpMock.get_series.return_value, |
| 893 | - version='42.0daily83.09.13.2-1') |
| 894 | - source1.sourceFileUrls.assert_called_once() |
| 895 | - self.assertTrue(os.path.isdir(source_package_dir)) |
| 896 | - |
| 897 | - @patch('cupstream2distro.packagemanager.lp') |
| 898 | - def test_get_source_package_from_dest_with_special_chars( |
| 899 | - self, lpMock): |
| 900 | - """Grab the correct source from dest with chars like ~ and +.""" |
| 901 | - env.SILONAME = 'ubuntu/landing-000' |
| 902 | - dest = Mock() |
| 903 | - dest.distribution.name = 'ubuntu' |
| 904 | - source1 = Mock() |
| 905 | - source1.status = 'Published' |
| 906 | - dest.getPublishedSources.return_value = [source1] |
| 907 | - source1.sourceFileUrls.return_value = ( |
| 908 | - self.get_source_files_for_package( |
| 909 | - 'foo_specialchars_package', for_download=True)) |
| 910 | - |
| 911 | - source_package_dir = packagemanager.get_source_package_from_dest( |
| 912 | - 'foo', dest, '42.0~daily83.09.13.2+0-0ubuntu1', 'rolling') |
| 913 | - |
| 914 | - lpMock.get_series.assert_called_once_with('rolling', dest=dest) |
| 915 | - dest.getPublishedSources.assert_called_once_with( |
| 916 | - exact_match=True, |
| 917 | - source_name='foo', |
| 918 | - distro_series=lpMock.get_series.return_value, |
| 919 | - version='42.0~daily83.09.13.2+0-0ubuntu1') |
| 920 | - source1.sourceFileUrls.assert_called_once() |
| 921 | - self.assertTrue(os.path.isdir(source_package_dir)) |
| 922 | - |
| 923 | - @patch('cupstream2distro.packagemanager.lp') |
| 924 | - def test_get_source_package_from_dest_not_published(self, lpMock): |
| 925 | - """We return none if the package was never published into the dest.""" |
| 926 | - self.assertIsNone(packagemanager.get_source_package_from_dest( |
| 927 | - 'foo', None, '0', 'rolling')) |
| 928 | - self.assertEqual(os.listdir('.'), []) |
| 929 | - self.assertFalse(lpMock.get_series.called) |
| 930 | - |
| 931 | - @patch('cupstream2distro.packagemanager.lp') |
| 932 | - def test_get_source_package_from_dest_with_ubuntu_native_version( |
| 933 | - self, lpMock): |
| 934 | - """We grab the correct source from dest with ubuntu native version.""" |
| 935 | - dest = Mock() |
| 936 | - dest.distribution.name = 'ubuntu' |
| 937 | - source1 = Mock() |
| 938 | - source1.status = 'Published' |
| 939 | - dest.getPublishedSources.return_value = [source1] |
| 940 | - source1.sourceFileUrls.return_value = ( |
| 941 | - self.get_source_files_for_package( |
| 942 | - 'foo_native_ubuntu_version', for_download=True)) |
| 943 | - |
| 944 | - source_package_dir = packagemanager.get_source_package_from_dest( |
| 945 | - 'foo', dest, '42ubuntu1', 'rolling') |
| 946 | - |
| 947 | - lpMock.get_series.assert_called_once_with('rolling', dest=dest) |
| 948 | - dest.getPublishedSources.assert_called_once_with( |
| 949 | - exact_match=True, |
| 950 | - source_name='foo', |
| 951 | - distro_series=lpMock.get_series.return_value, |
| 952 | - version='42ubuntu1') |
| 953 | - source1.sourceFileUrls.assert_called_once() |
| 954 | - self.assertTrue(os.path.isdir(source_package_dir)) |
| 955 | - |
| 956 | def test_detect_packaging_changes_since_last_release(self): |
| 957 | """We detect packaging changes since last release.""" |
| 958 | self.assertTrue( |
| 959 | |
| 960 | === modified file 'tests/unit/test_script_build.py' |
| 961 | --- tests/unit/test_script_build.py 2015-03-09 23:41:22 +0000 |
| 962 | +++ tests/unit/test_script_build.py 2015-03-10 17:39:11 +0000 |
| 963 | @@ -791,7 +791,6 @@ |
| 964 | from_archive = self.script.SourceSync.from_archive = Mock() |
| 965 | self.script.pm.get_current_version_for_series\ |
| 966 | .return_value = '1.9+15.04.20150208-0ubuntu1' |
| 967 | - self.script.pm.version_greater_equal.return_value = True |
| 968 | globs = [ |
| 969 | [self.tempdir + '/sink_1.9.orig.tar.gz'], |
| 970 | [self.tempdir + '/sink_1.9.dsc'], |
| 971 | @@ -1015,7 +1014,7 @@ |
| 972 | self.script.env.WATCH_ONLY = 'false' |
| 973 | silo_state = self.script.SiloState.return_value |
| 974 | bm = self.script.BuildManager = Mock() |
| 975 | - self.assertEqual(self.script.main(), 0) |
| 976 | + self.assertEqual(self.script.main(bm), 0) |
| 977 | bm.assert_called_once_with(silo_state) |
| 978 | self.assertEqual( |
| 979 | bm.return_value.mock_calls, [ |
| 980 | @@ -1030,7 +1029,7 @@ |
| 981 | self.script.env.WATCH_ONLY = 'true' |
| 982 | silo_state = self.script.SiloState.return_value |
| 983 | bm = self.script.BuildManager = Mock() |
| 984 | - self.assertEqual(self.script.main(), 0) |
| 985 | + self.assertEqual(self.script.main(bm), 0) |
| 986 | bm.assert_called_once_with(silo_state) |
| 987 | self.assertEqual( |
| 988 | bm.return_value.mock_calls, [ |
| 989 | @@ -1049,7 +1048,7 @@ |
| 990 | silo_state = self.script.SiloState.return_value |
| 991 | bm = self.script.BuildManager = Mock() |
| 992 | bm.return_value.do = Mock(side_effect=raise_errs) |
| 993 | - self.assertEqual(self.script.main(), 1) |
| 994 | + self.assertEqual(self.script.main(bm), 1) |
| 995 | bm.assert_called_once_with(silo_state) |
| 996 | self.assertEqual( |
| 997 | bm.return_value.mock_calls, [ |
| 998 | |
| 999 | === renamed file 'tests/unit/test_script_reverter.py' => 'tests/unit/test_script_revert.py' |
| 1000 | --- tests/unit/test_script_reverter.py 2015-03-03 09:45:08 +0000 |
| 1001 | +++ tests/unit/test_script_revert.py 2015-03-10 17:39:11 +0000 |
| 1002 | @@ -16,13 +16,95 @@ |
| 1003 | |
| 1004 | from __future__ import absolute_import, division, unicode_literals |
| 1005 | |
| 1006 | +from datetime import datetime |
| 1007 | +from mock import Mock, call |
| 1008 | + |
| 1009 | from tests.unit import CITrainScriptTestCase |
| 1010 | +from cupstream2distro.errors import RevertError |
| 1011 | |
| 1012 | # Unused import necessary for code coverage reporting |
| 1013 | -from citrain import reverter |
| 1014 | -reverter |
| 1015 | +from citrain import revert |
| 1016 | +revert |
| 1017 | |
| 1018 | |
| 1019 | class ReverterTestCase(CITrainScriptTestCase): |
| 1020 | """Test the CI Train Reverter script.""" |
| 1021 | - scriptname = 'reverter.py' |
| 1022 | + scriptname = 'revert.py' |
| 1023 | + |
| 1024 | + def test_revert_collect_phase(self): |
| 1025 | + """Ensure that Revert class can get packages to revert to.""" |
| 1026 | + today = datetime.today().strftime('%Y%m%d') |
| 1027 | + s1 = Mock(source_package_version='2.0') |
| 1028 | + s2 = Mock(source_package_version='1.0') |
| 1029 | + self.script.sort_by_date = Mock(return_value=[s1, s2]) |
| 1030 | + self.script.get_current_version_for_series = Mock(return_value='0') |
| 1031 | + self.script.get_source_package = Mock() |
| 1032 | + series = Mock(version='15.04') |
| 1033 | + dest = Mock() |
| 1034 | + ppa = Mock() |
| 1035 | + revert = self.script.Revert('regress', series, dest, ppa) |
| 1036 | + revert.delete_old_dsc = Mock() |
| 1037 | + revert.position_source = Mock() |
| 1038 | + revert.rename_orig_tarball = Mock() |
| 1039 | + revert.initialize_branch = Mock() |
| 1040 | + revert.collect_phase() |
| 1041 | + self.script.sort_by_date.assert_called_once_with( |
| 1042 | + revert.dest.getPublishedSources.return_value, all_packages=True) |
| 1043 | + self.assertEqual(revert.dest.getPublishedSources.mock_calls, [ |
| 1044 | + call(exact_match=True, source_name='regress', |
| 1045 | + distro_series=series, pocket='Release'), |
| 1046 | + ]) |
| 1047 | + self.script.get_current_version_for_series.assert_called_once_with( |
| 1048 | + 'regress', series.name, dest=ppa, all_packages=True) |
| 1049 | + self.script.get_source_package.assert_called_once_with( |
| 1050 | + 'regress', dest, series, path=self.tempdir, version='1.0') |
| 1051 | + revert.delete_old_dsc.assert_called_once_with() |
| 1052 | + revert.position_source.assert_called_once_with( |
| 1053 | + self.script.get_source_package.return_value) |
| 1054 | + new_version = '2.0+15.04.{}.~is.1.0'.format(today) |
| 1055 | + revert.rename_orig_tarball.assert_called_once_with(new_version) |
| 1056 | + self.assertEqual(self.script.call.mock_calls, [ |
| 1057 | + call(['dch', '-v', new_version + '-0ubuntu1', |
| 1058 | + 'Reverting to 1.0 due to regression.'], cwd=revert.path), |
| 1059 | + call(['dch', '-r', '-D', series.name, '--force-distribution', ''], |
| 1060 | + cwd=revert.path), |
| 1061 | + ]) |
| 1062 | + revert.initialize_branch.assert_called_once_with() |
| 1063 | + self.script.DotProject.soft_save.assert_called_once_with( |
| 1064 | + 'regress', dest='2.0', ours=new_version + '-0ubuntu1') |
| 1065 | + |
| 1066 | + def test_revert_collect_phase_none_found(self): |
| 1067 | + """Raise the correct error when there's no previous version.""" |
| 1068 | + s1 = Mock(source_package_version='2.0') |
| 1069 | + self.script.sort_by_date = Mock(return_value=[s1]) |
| 1070 | + self.script.get_current_version_for_series = Mock(return_value='0') |
| 1071 | + self.script.get_source_package = Mock() |
| 1072 | + series = Mock(version='15.04') |
| 1073 | + dest = Mock() |
| 1074 | + ppa = Mock() |
| 1075 | + revert = self.script.Revert('regress', series, dest, ppa) |
| 1076 | + with self.assertRaisesRegexp(RevertError, 'No previous version'): |
| 1077 | + revert.collect_phase() |
| 1078 | + |
| 1079 | + def test_revert_manager_choose_classes(self): |
| 1080 | + """Ensure that RevertManager chooses all packages to revert.""" |
| 1081 | + self.script.env.PACKAGE_VERSIONS = 'foo=1.0 bar=2.0' |
| 1082 | + silo_state = Mock() |
| 1083 | + rm = self.script.RevertManager(silo_state) |
| 1084 | + rm.names = Mock() |
| 1085 | + rm.choose_classes() |
| 1086 | + self.assertEqual(rm.types, { |
| 1087 | + self.script.Revert: rm.names, |
| 1088 | + }) |
| 1089 | + self.assertEqual(self.script.Revert.versions, { |
| 1090 | + 'foo': '1.0', |
| 1091 | + 'bar': '2.0', |
| 1092 | + }) |
| 1093 | + |
| 1094 | + def test_main(self): |
| 1095 | + """Ensure main() triggers everything.""" |
| 1096 | + self.script.build_main = Mock() |
| 1097 | + self.assertEqual( |
| 1098 | + self.script.main(), self.script.build_main.return_value) |
| 1099 | + self.script.build_main.assert_called_once_with( |
| 1100 | + self.script.RevertManager) |
| 1101 | |
| 1102 | === modified file 'tests/unit/test_script_setup_citrain.py' |
| 1103 | --- tests/unit/test_script_setup_citrain.py 2015-03-03 09:45:08 +0000 |
| 1104 | +++ tests/unit/test_script_setup_citrain.py 2015-03-10 17:39:11 +0000 |
| 1105 | @@ -163,7 +163,8 @@ |
| 1106 | call('check-publication-migration'), |
| 1107 | call('upgrade-chroot'), |
| 1108 | call('apt-get-clean'), |
| 1109 | - call('pbuilder-clean')]) |
| 1110 | + call('pbuilder-clean'), |
| 1111 | + call('revert')]) |
| 1112 | |
| 1113 | def test_integration(self): |
| 1114 | """A basic integration test for jenkins config deployment.""" |
| 1115 | @@ -175,6 +176,7 @@ |
| 1116 | 'check-publication-migration/config.xml', |
| 1117 | 'pbuilder-clean/config.xml', |
| 1118 | 'prepare-silo/config.xml', |
| 1119 | + 'revert/config.xml', |
| 1120 | 'ubuntu-landing-000-0-reconfigure/config.xml', |
| 1121 | 'ubuntu-landing-000-1-build/config.xml', |
| 1122 | 'ubuntu-landing-000-2-publish/config.xml', |

PASSED: Continuous integration, rev:963 jenkins. qa.ubuntu. com/job/ cu2d-choo- choo-ci/ 587/
http://
Executed test runs:
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/cu2d- choo-choo- ci/587/ rebuild
http://