Merge lp:~nskaggs/juju-release-tools/add-daily-build into lp:juju-release-tools

Proposed by Nicholas Skaggs
Status: Merged
Merged at revision: 299
Proposed branch: lp:~nskaggs/juju-release-tools/add-daily-build
Merge into: lp:juju-release-tools
Diff against target: 561 lines (+311/-132)
2 files modified
build_package.py (+50/-11)
tests/test_build_package.py (+261/-121)
To merge this branch: bzr merge lp:~nskaggs/juju-release-tools/add-daily-build
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+293532@code.launchpad.net

Description of the change

Add date and build for blessed build support

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

I don't think the change is complete and I think this breaks our official releases.

build_package.py is used to make testing an real packages. I think these changes will create packages we intend to release our devel and stable PPAs with dates and hashes in them. The script that extracts agents from packages is sensitive to the binary package names. I doubt agents can be created for official streams because the binary package names will have date and hashes in them.

I think "make test" will fail. juju-release-scripts is a production project that manages releases and the agent archive. We need tests to ensure releases are boring.

I have some suggestions inline.

review: Needs Information (core)
301. By Nicholas Skaggs

add revid too

302. By Nicholas Skaggs

make everything new optional

303. By Nicholas Skaggs

fix ordering and tests

304. By Nicholas Skaggs

add daily tests

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

I made a new template string. Feel free to comment on things like we really need -ubuntu in there, etc.

I also added tests -- anything else you'd like to see specific to daily?

In addition, I did a test run using this new code with the existing job to ensure I didn't break anything: http://juju-ci.vapour.ws/view/Release, package, publish/job/release-juju-create-source-packages-test/1/

Revision history for this message
Curtis Hovey (sinzui) wrote :

Your change looks good, but I believe something is incomplete. Looking at
    http://juju-ci.vapour.ws:8080/job/release-juju-create-source-packages-daily/
I see a orig.tar.gz that is identical to what we have uploaded before:
    juju-core_2.0-beta6.orig.tar.gz

The orig.tar.gz name is identical to the official package we released at
     http://juju-ci.vapour.ws:8080/job/release-juju-create-source-packages/

Lp never forgets a tarfile. A new orig file was not uploaded. Instead, Lp accepted the tarfile because its hash is identical to the one previously uploaded. Anything tarfile that claims to have the same name, btu a different hash will be rejected because it could be a man in the middle attack. When release-juju-create-source-packages-daily creates juju-core_2.0-beta6.orig.tar.gz, the next version (juju-core_2.0-beta7.orig.tar.gz) we will never be able to release 2.0-beta7.

I think a single rule in build_source() will suffice to avoid this problem. Before we create the SourceFile, we get the version from the tarfile. We can rename the tarfile. Maybe we can change these lines

    tarfile_name = os.path.basename(tarfile_path)
    version = tarfile_name.split('_')[-1].replace('.tar.gz', '')

to something like:

    tarfile_name = os.path.basename(tarfile_path)
    version = tarfile_name.split('_')[-1].replace('.tar.gz', '')
    if revid:
        daily_version = {}~{}'.format(version, revid)
        daily_tarfile_name = tarfile_name.replace(version, daily_version)
        tarfile_dir = os.path.dirname(tarfile_path)
        daily_tarfile_path = os.path.join(tarfile_dir, daily_tarfile_name)
        os.rename(tarfile_path, daily_tarfile_path)
        tarfile_path = daily_tarfile_path

^ I typed that really fast. It probably has errors. Maybe we want the orig to have the date and build id too. Maybe this should be extracted to a helper function that is easy to test.

    tarfile_name = os.path.basename(tarfile_path)
    version = tarfile_name.split('_')[-1].replace('.tar.gz', '')
    if revid:
        tarfile_path = rename_daily_tarfile(tarfile_path, version, revid)

review: Needs Fixing (code)
305. By Nicholas Skaggs

add unique name for daily tarball

306. By Nicholas Skaggs

just set names; revamp tests

307. By Nicholas Skaggs

rename

308. By Nicholas Skaggs

flake8

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Ok, refactored tests to use scenarios. I stopped myself from going too crazy. I believe you have unique tarballs now too:

http://juju-ci.vapour.ws/job/release-juju-create-source-packages-daily/15/

Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you Nicholas.

The test refactorings were unexpected and challenging to read as they look to like a total rewrite when they are not. In general, a branch should not exceed 400 lines. I would have made the testscenarios change in a separate branch. I can see this is a nice addition. I have but one quibble over a test name in line.

The hosts that use this project will fail their these tests because python-testscenarios is not installed by any of our other deps. This project's deps are unified with juju-ci-tools. It's Makefile will provide the deps for for juju-release-tools. That isn't true any more :(. I accept python-testscenarios. I think we need a new Makefile target that installs: python-testscenarios. The good news is we do not need to make this project work on windows, centos, or os x.

HOWEVER. Something is wrong and I don't see anything wrong in your implementation. Look at
    http://juju-ci.vapour.ws/job/release-juju-create-source-packages-daily/15/artifact/juju-build-trusty-all/juju-core_2.0-beta6-20160503+3921+4bbce805~14.04.dsc
^ I see juju-core_2.0-beta6.orig.tar.gz in there. We don't want that uploaded. I don't see how it exists since I see os.rename. I think the tar file is renamed immediately. We pass the new tarfile name to the step that imports it. I see this confirmed at
    http://juju-ci.vapour.ws/job/release-juju-create-source-packages-daily/ws/juju-build-any-all/
When I look at
     http://juju-ci.vapour.ws/job/release-juju-create-source-packages-daily/ws/juju-build-trusty-all/
I see our new version as the debian tar, but not the orig.

Oh. I think I know. create_source_package_branch() takes version. It "sets" the version of the upstream tarfile being imported...oh wow.

1 we need to pass the new version so that the call to create the pristine-tar returns the right version for the orig.
2. um maybe we didn't need to rename the tarfile because I think the spb's pristine-tar always becomes the .orig.

review: Needs Information (code)
Revision history for this message
Curtis Hovey (sinzui) wrote :

Hi Nicholas.

After reading this code again. I don't think we need to rename the tarfile. In stead we want to pass a revised version to create_source_package_branch().

1. The call to import-upstream uses version because the upstream tar file is not guaranteed to be debian friendly. The "version" we pass is used to bzr to recreate the orig tarfile as needed.

2. The step to import the tarfile is done in its own sub dir (*.all-all) to keep it isolated from the dirs that make source packages.

3. I think is collides with the changes to create_source_package() which wants to make the source package version. :( Since the version, revid date etc was applied outside of create_source_package() it will make a mistake. Either we continue to pass the original version to this function, or we choose to make this function accept the version passed.

Sorry for advising you

309. By Nicholas Skaggs

fix version for orig tarball

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

So Curtis, looking this morning the answer was rather simple, heh. I looked at the function and agreed with you. I fixed the test as well and everything has the long version string now. Here's an output for you to grok.

http://juju-ci.vapour.ws/job/release-juju-create-source-packages-daily/21/

Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you very much.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'build_package.py'
--- build_package.py 2016-04-14 22:08:19 +0000
+++ build_package.py 2016-05-04 14:09:15 +0000
@@ -115,6 +115,7 @@
115115
116116
117UBUNTU_VERSION_TEMPLATE = '{version}-0ubuntu1~{release}.{upatch}~juju1'117UBUNTU_VERSION_TEMPLATE = '{version}-0ubuntu1~{release}.{upatch}~juju1'
118DAILY_VERSION_TEMPLATE = '{version}-{date}+{build}+{revid}~{release}'
118119
119120
120VERSION_PATTERN = re.compile('(\d+)\.(\d+)\.(\d+)')121VERSION_PATTERN = re.compile('(\d+)\.(\d+)\.(\d+)')
@@ -317,18 +318,28 @@
317 return spb318 return spb
318319
319320
320def make_ubuntu_version(series, version, upatch=1):321def make_ubuntu_version(series, version, upatch=1,
322 date=None, build=None, revid=None):
321 """Return an Ubuntu package version.323 """Return an Ubuntu package version.
322324
323 :param series: The series codename.325 :param series: The series codename.
324 :param version: The upstream version.326 :param version: The upstream version.
325 :param upatch: The package patch number for cases where a packaging rules327 :param upatch: The package patch number for cases where a packaging rules
326 are updated and the package rebuilt.328 are updated and the package rebuilt.
329 :param date: The date of the build.
330 :param build: The build number in CI.
331 :param revid: The revid hash of the source.
327 :return: An Ubuntu version string.332 :return: An Ubuntu version string.
328 """333 """
329 release = juju_series.get_version(series)334 release = juju_series.get_version(series)
330 return UBUNTU_VERSION_TEMPLATE.format(335 # if daily params are set, we make daily build
331 version=version, release=release, upatch=upatch)336 if all([date, build, revid]):
337 return DAILY_VERSION_TEMPLATE.format(
338 version=version, release=release, upatch=upatch,
339 date=date, build=build, revid=revid)
340 else:
341 return UBUNTU_VERSION_TEMPLATE.format(
342 version=version, release=release, upatch=upatch)
332343
333344
334def make_changelog_message(version, bugs=None):345def make_changelog_message(version, bugs=None):
@@ -382,8 +393,9 @@
382393
383394
384def create_source_package(source_dir, spb, series, version,395def create_source_package(source_dir, spb, series, version,
385 upatch='1', bugs=None, gpgcmd=None,396 upatch='1', bugs=None, gpgcmd=None, debemail=None,
386 debemail=None, debfullname=None, verbose=False):397 debfullname=None, verbose=False,
398 date=None, build=None, revid=None):
387 """Create a series source package from a source package branch.399 """Create a series source package from a source package branch.
388400
389 The new source package can be used to create series source packages.401 The new source package can be used to create series source packages.
@@ -401,8 +413,13 @@
401 :param debemail: The email address to attribute the changelog entry to.413 :param debemail: The email address to attribute the changelog entry to.
402 :param debfullname: The name to attribute the changelog entry to.414 :param debfullname: The name to attribute the changelog entry to.
403 :param verbose: Increase the information about the work performed.415 :param verbose: Increase the information about the work performed.
416 :param date: The date of the build.
417 :param build: The build number in CI.
418 :param revid: The revid hash of the source.
404 """419 """
405 ubuntu_version = make_ubuntu_version(series, version, upatch)420
421 ubuntu_version = make_ubuntu_version(series, version, upatch,
422 date, build, revid)
406 message = make_changelog_message(version, bugs=bugs)423 message = make_changelog_message(version, bugs=bugs)
407 source = os.path.join(source_dir, 'source')424 source = os.path.join(source_dir, 'source')
408 env = make_deb_shell_env(debemail, debfullname)425 env = make_deb_shell_env(debemail, debfullname)
@@ -416,7 +433,8 @@
416433
417def build_source(tarfile_path, location, series, bugs,434def build_source(tarfile_path, location, series, bugs,
418 debemail=None, debfullname=None, gpgcmd=None,435 debemail=None, debfullname=None, gpgcmd=None,
419 branch=None, upatch=1, verbose=False):436 branch=None, upatch=1, verbose=False,
437 date=None, build=None, revid=None):
420 """Build one or more series source packages from a new release tarfile.438 """Build one or more series source packages from a new release tarfile.
421439
422 The packages are unsigned by default, but providing the path to a gpgcmd,440 The packages are unsigned by default, but providing the path to a gpgcmd,
@@ -435,12 +453,25 @@
435 :param upatch: The package patch number for cases where a packaging rules453 :param upatch: The package patch number for cases where a packaging rules
436 are updated and the package rebuilt.454 are updated and the package rebuilt.
437 :param verbose: Increase the verbostiy of output.455 :param verbose: Increase the verbostiy of output.
456 :param date: The date of the build.
457 :param build: The build number in CI.
458 :param revid: The revid hash of the source.
438 :return: the exit code (which is 0 or else an exception was raised).459 :return: the exit code (which is 0 or else an exception was raised).
439 """460 """
440 if not isinstance(series, list):461 if not isinstance(series, list):
441 series = [series]462 series = [series]
442 tarfile_name = os.path.basename(tarfile_path)463 tarfile_name = os.path.basename(tarfile_path)
443 version = tarfile_name.split('_')[-1].replace('.tar.gz', '')464 version = tarfile_name.split('_')[-1].replace('.tar.gz', '')
465 if all([date, build, revid]):
466 daily_version = '{}~{}~{}~{}'.format(version, date, build, revid)
467 daily_tarfile_name = tarfile_name.replace(version, daily_version)
468 tarfile_dir = os.path.dirname(tarfile_path)
469 daily_tarfile_path = os.path.join(tarfile_dir, daily_tarfile_name)
470 os.rename(tarfile_name, daily_tarfile_name)
471 tarfile_path = daily_tarfile_path
472 tarfile_name = daily_tarfile_name
473 version = daily_version
474
444 files = [SourceFile(None, None, tarfile_name, tarfile_path)]475 files = [SourceFile(None, None, tarfile_name, tarfile_path)]
445 spb_dir = setup_local(476 spb_dir = setup_local(
446 location, 'any', 'all', files, verbose=verbose)477 location, 'any', 'all', files, verbose=verbose)
@@ -448,9 +479,10 @@
448 for a_series in series:479 for a_series in series:
449 build_dir = setup_local(location, a_series, 'all', [], verbose=verbose)480 build_dir = setup_local(location, a_series, 'all', [], verbose=verbose)
450 create_source_package(481 create_source_package(
451 build_dir, spb, a_series, version, upatch=upatch, bugs=bugs,482 build_dir, spb, a_series, version,
452 gpgcmd=gpgcmd, debemail=debemail, debfullname=debfullname,483 upatch=upatch, bugs=bugs, gpgcmd=gpgcmd,
453 verbose=verbose)484 debemail=debemail, debfullname=debfullname, verbose=verbose,
485 date=date, build=build, revid=revid)
454 return 0486 return 0
455487
456488
@@ -473,7 +505,8 @@
473 args.tar_file, args.location, args.series, args.bugs,505 args.tar_file, args.location, args.series, args.bugs,
474 debemail=args.debemail, debfullname=args.debfullname,506 debemail=args.debemail, debfullname=args.debfullname,
475 gpgcmd=args.gpgcmd, branch=args.branch, upatch=args.upatch,507 gpgcmd=args.gpgcmd, branch=args.branch, upatch=args.upatch,
476 verbose=args.verbose)508 verbose=args.verbose,
509 date=args.date, build=args.build, revid=args.revid)
477 elif args.command == 'binary':510 elif args.command == 'binary':
478 exitcode = build_binary(511 exitcode = build_binary(
479 args.dsc, args.location, args.series, args.arch,512 args.dsc, args.location, args.series, args.arch,
@@ -510,6 +543,12 @@
510 src_parser.add_argument(543 src_parser.add_argument(
511 'series', help="The destination Ubuntu release or LIVING for all.")544 'series', help="The destination Ubuntu release or LIVING for all.")
512 src_parser.add_argument(545 src_parser.add_argument(
546 '--date', default=None, help="A datestamp to apply to the build")
547 src_parser.add_argument(
548 '--build', default=None, help="The build number from CI")
549 src_parser.add_argument(
550 '--revid', default=None, help="The short hash for revid")
551 src_parser.add_argument(
513 'bugs', nargs='*', help="Bugs this version will fix in the release.")552 'bugs', nargs='*', help="Bugs this version will fix in the release.")
514 bin_parser = subparsers.add_parser('binary', help='Build a binary package')553 bin_parser = subparsers.add_parser('binary', help='Build a binary package')
515 bin_parser.add_argument(554 bin_parser.add_argument(
516555
=== modified file 'tests/test_build_package.py'
--- tests/test_build_package.py 2016-02-10 18:39:43 +0000
+++ tests/test_build_package.py 2016-05-04 14:09:15 +0000
@@ -8,6 +8,7 @@
8from StringIO import StringIO8from StringIO import StringIO
9from textwrap import dedent9from textwrap import dedent
10import unittest10import unittest
11from testscenarios import TestWithScenarios
1112
12from build_package import (13from build_package import (
13 _JujuSeries,14 _JujuSeries,
@@ -165,70 +166,6 @@
165 bb_mock.assert_called_with(166 bb_mock.assert_called_with(
166 'my.dsc', '~/workspace', 'trusty', 'i386', ppa=None, verbose=False)167 'my.dsc', '~/workspace', 'trusty', 'i386', ppa=None, verbose=False)
167168
168 def test_get_args_source(self):
169 shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
170 with patch.dict('os.environ', shell_env):
171 args = get_args(
172 ['prog', 'source', 'my_1.25.0.tar.gz', '~/workspace', 'trusty',
173 '123', '456'])
174 self.assertEqual('source', args.command)
175 self.assertEqual('my_1.25.0.tar.gz', args.tar_file)
176 self.assertEqual('~/workspace', args.location)
177 self.assertEqual('trusty', args.series)
178 self.assertEqual(['123', '456'], args.bugs)
179 self.assertEqual('me@email', args.debemail)
180 self.assertEqual('me', args.debfullname)
181 self.assertIsNone(args.gpgcmd)
182 self.assertEqual(DEFAULT_SPB, args.branch)
183 self.assertEqual('1', args.upatch)
184 self.assertFalse(args.verbose)
185
186 def test_get_args_source_default_spb2_branch(self):
187 shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
188 with patch.dict('os.environ', shell_env):
189 args = get_args(
190 ['prog', 'source', 'my_2.0-a.tar.gz', '~/workspace', 'trusty',
191 '123', '456'])
192 self.assertEqual('source', args.command)
193 self.assertEqual('my_2.0-a.tar.gz', args.tar_file)
194 self.assertEqual(DEFAULT_SPB2, args.branch)
195
196 def test_get_args_source_with_branch(self):
197 shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
198 with patch.dict('os.environ', shell_env):
199 args = get_args(
200 ['prog', 'source', 'my_2.0-a.tar.gz', '~/workspace', 'trusty',
201 '123', '456', '--branch', '~/my-branch'])
202 self.assertEqual('source', args.command)
203 self.assertEqual('my_2.0-a.tar.gz', args.tar_file)
204 self.assertEqual('~/my-branch', args.branch)
205
206 def test_get_args_source_with_living(self):
207 with patch('build_package.juju_series.get_living_names', autospec=True,
208 return_value=['precise', 'trusty']) as js_mock:
209 args = get_args(
210 ['prog', 'source', 'my.tar.gz', '~/workspace', 'LIVING',
211 '123', '456'])
212 self.assertEqual(['precise', 'trusty'], args.series)
213 self.assertEqual(1, js_mock.call_count)
214 args = get_args(
215 ['prog', 'source', 'my.tar.gz', '~/workspace', 'LIVING',
216 '123', '456'])
217 self.assertEqual(juju_series.get_living_names(), args.series)
218
219 def test_main_source(self):
220 with patch('build_package.build_source', autospec=True,
221 return_value=0) as bs_mock:
222 code = main([
223 'prog', 'source',
224 '--debemail', 'me@email', '--debfullname', 'me',
225 'my.tar.gz', '~/workspace', 'trusty', '123', '456'])
226 self.assertEqual(0, code)
227 bs_mock.assert_called_with(
228 'my.tar.gz', '~/workspace', 'trusty', ['123', '456'],
229 debemail='me@email', debfullname='me', gpgcmd=None,
230 branch=DEFAULT_SPB, upatch='1', verbose=False)
231
232 @autopatch('build_package.move_debs', return_value=True)169 @autopatch('build_package.move_debs', return_value=True)
233 @autopatch('build_package.teardown_lxc', return_value=True)170 @autopatch('build_package.teardown_lxc', return_value=True)
234 @autopatch('build_package.build_in_lxc')171 @autopatch('build_package.build_in_lxc')
@@ -380,28 +317,6 @@
380 found = move_debs(build_dir, workspace)317 found = move_debs(build_dir, workspace)
381 self.assertFalse(found)318 self.assertFalse(found)
382319
383 @autopatch('build_package.create_source_package')
384 @autopatch('build_package.create_source_package_branch',
385 return_value='./spb_path')
386 @autopatch('build_package.setup_local',
387 side_effect=['./spb_dir', './precise_dir', './trusty_dir'])
388 def test_build_source(self, sl_mock, spb_mock, csp_mock):
389 return_code = build_source(
390 './my_1.2.3.tar.gz', './workspace', ['precise', 'trusty'], ['987'],
391 debemail=None, debfullname=None, gpgcmd='my/gpg',
392 branch='lp:branch', upatch=None, verbose=False)
393 sl_mock.assert_any_call(
394 './workspace', 'any', 'all',
395 [SourceFile(None, None, 'my_1.2.3.tar.gz', './my_1.2.3.tar.gz')],
396 verbose=False)
397 spb_mock.assert_called_with(
398 './spb_dir', '1.2.3', 'my_1.2.3.tar.gz', 'lp:branch')
399 sl_mock.assert_any_call(
400 './workspace', 'precise', 'all', [], verbose=False)
401 sl_mock.assert_any_call(
402 './workspace', 'trusty', 'all', [], verbose=False)
403 self.assertEqual(0, return_code)
404
405 @autopatch('subprocess.check_call')320 @autopatch('subprocess.check_call')
406 def test_create_source_package_branch(self, cc_mock):321 def test_create_source_package_branch(self, cc_mock):
407 spb = create_source_package_branch(322 spb = create_source_package_branch(
@@ -433,41 +348,6 @@
433 'New upstream stable point release. (LP #987, LP #876)',348 'New upstream stable point release. (LP #987, LP #876)',
434 message)349 message)
435350
436 @autopatch('build_package.sign_source_package')
437 @autopatch('subprocess.check_call')
438 def test_create_source_package(self, cc_mock, ss_mock):
439 create_source_package(
440 '/juju-build-trusty-all', '/juju-build-any-all/spb', 'trusty',
441 '1.2.3', upatch='1', bugs=['987'], gpgcmd=None,
442 debemail='me@email', debfullname='me', verbose=False)
443 script = BUILD_SOURCE_TEMPLATE.format(
444 spb='/juju-build-any-all/spb',
445 source='/juju-build-trusty-all/source',
446 series='trusty', ubuntu_version='1.2.3-0ubuntu1~14.04.1~juju1',
447 message='New upstream stable point release. (LP #987)')
448 env = make_deb_shell_env('me@email', 'me')
449 cc_mock.assert_called_with(
450 [script], shell=True, cwd='/juju-build-trusty-all', env=env)
451 self.assertEqual(0, ss_mock.call_count)
452
453 @autopatch('build_package.sign_source_package')
454 @autopatch('subprocess.check_call')
455 def test_create_source_package_with_gpgcmd(self, cc_mock, ss_mock):
456 create_source_package(
457 '/juju-build-trusty-all', '/juju-build-any-all/spb', 'trusty',
458 '1.2.3', upatch='1', bugs=['987'], gpgcmd='/my/gpgcmd',
459 debemail='me@email', debfullname='me', verbose=False)
460 script = BUILD_SOURCE_TEMPLATE.format(
461 spb='/juju-build-any-all/spb',
462 source='/juju-build-trusty-all/source',
463 series='trusty', ubuntu_version='1.2.3-0ubuntu1~14.04.1~juju1',
464 message='New upstream stable point release. (LP #987)')
465 env = make_deb_shell_env('me@email', 'me')
466 cc_mock.assert_called_with(
467 [script], shell=True, cwd='/juju-build-trusty-all', env=env)
468 ss_mock.assert_called_with(
469 '/juju-build-trusty-all', '/my/gpgcmd', 'me@email', 'me')
470
471 @autopatch('subprocess.check_call')351 @autopatch('subprocess.check_call')
472 def test_sign_source_package(self, cc_mock):352 def test_sign_source_package(self, cc_mock):
473 sign_source_package(353 sign_source_package(
@@ -508,3 +388,263 @@
508 package_version='1.25.0-0ubuntu1~16.04.1~juju1')388 package_version='1.25.0-0ubuntu1~16.04.1~juju1')
509 self.assertEqual(0, code)389 self.assertEqual(0, code)
510 self.assertEqual('xenial\n', so_mock.getvalue())390 self.assertEqual('xenial\n', so_mock.getvalue())
391
392
393class CreateBuildSource(TestWithScenarios):
394
395 scenarios = [
396 ('release',
397 {'date': None,
398 'build': None,
399 'revid': None,
400 'version': '1.2.3',
401 'original_tarfile_name': None,
402 'tarfile_name': 'my_1.2.3.tar.gz',
403 'tarfile_path': './my_1.2.3.tar.gz'
404 }),
405
406 ('daily',
407 {'date': '20160502',
408 'build': '3065',
409 'revid': '4bbce805',
410 'version': '1.2.3~20160502~3065~4bbce805',
411 'original_tarfile_name': 'my_1.2.3.tar.gz',
412 'tarfile_name': 'my_1.2.3~20160502~3065~4bbce805.tar.gz',
413 'tarfile_path': './my_1.2.3~20160502~3065~4bbce805.tar.gz'
414 }),
415 ('broken_daily',
416 {'date': None,
417 'build': '3065',
418 'revid': '4bbce805',
419 'version': '1.2.3',
420 'original_tarfile_name': None,
421 'tarfile_name': 'my_1.2.3.tar.gz',
422 'tarfile_path': './my_1.2.3.tar.gz'
423 })
424 ]
425
426 @autopatch('build_package.create_source_package')
427 @autopatch('build_package.create_source_package_branch',
428 return_value='./spb_path')
429 @autopatch('build_package.setup_local',
430 side_effect=['./spb_dir', './precise_dir', './trusty_dir'])
431 @autopatch('build_package.os.rename', return_value=True)
432 def test_build_source_test(self, os_mock, sl_mock, spb_mock, csp_mock):
433 return_code = build_source(
434 './my_1.2.3.tar.gz', './workspace', ['precise', 'trusty'], ['987'],
435 debemail=None, debfullname=None, gpgcmd='my/gpg',
436 branch='lp:branch', upatch=None, verbose=False,
437 date=self.date, build=self.build, revid=self.revid)
438 if self.original_tarfile_name is not None:
439 os_mock.assert_called_with(self.original_tarfile_name,
440 self.tarfile_name)
441 sl_mock.assert_any_call(
442 './workspace', 'any', 'all',
443 [SourceFile(None, None, self.tarfile_name, self.tarfile_path)],
444 verbose=False)
445 spb_mock.assert_called_with(
446 './spb_dir', self.version, self.tarfile_name, 'lp:branch')
447 sl_mock.assert_any_call(
448 './workspace', 'precise', 'all', [], verbose=False)
449 sl_mock.assert_any_call(
450 './workspace', 'trusty', 'all', [], verbose=False)
451 self.assertEqual(0, return_code)
452
453
454class CreateSourcePackageTests(TestWithScenarios):
455
456 scenarios = [
457 ('release',
458 {'date': None,
459 'build': None,
460 'revid': None,
461 'ubuntu_version': '1.2.3-0ubuntu1~14.04.1~juju1'
462 }),
463
464 ('daily',
465 {'date': '20160502',
466 'build': '3065',
467 'revid': '4bbce805',
468 'ubuntu_version': '1.2.3-20160502+3065+4bbce805~14.04'
469 }),
470 ('broken_daily',
471 {'date': None,
472 'build': '3065',
473 'revid': '4bbce805',
474 'ubuntu_version': '1.2.3-0ubuntu1~14.04.1~juju1'
475 })
476 ]
477
478 @autopatch('build_package.sign_source_package')
479 @autopatch('subprocess.check_call')
480 def test_create_source_package(self, cc_mock, ss_mock):
481 create_source_package(
482 '/juju-build-trusty-all', '/juju-build-any-all/spb', 'trusty',
483 '1.2.3', upatch='1', bugs=['987'], gpgcmd=None,
484 debemail='me@email', debfullname='me', verbose=False,
485 date=self.date, build=self.build, revid=self.revid)
486 script = BUILD_SOURCE_TEMPLATE.format(
487 spb='/juju-build-any-all/spb',
488 source='/juju-build-trusty-all/source',
489 series='trusty',
490 ubuntu_version=self.ubuntu_version,
491 message='New upstream stable point release. (LP #987)')
492 env = make_deb_shell_env('me@email', 'me')
493 cc_mock.assert_called_with(
494 [script], shell=True, cwd='/juju-build-trusty-all', env=env)
495 self.assertEqual(0, ss_mock.call_count)
496
497 @autopatch('build_package.sign_source_package')
498 @autopatch('subprocess.check_call')
499 def test_create_source_package_with_gpgcmd(self, cc_mock, ss_mock):
500 create_source_package(
501 '/juju-build-trusty-all', '/juju-build-any-all/spb', 'trusty',
502 '1.2.3', upatch='1', bugs=['987'], gpgcmd='/my/gpgcmd',
503 debemail='me@email', debfullname='me', verbose=False,
504 date=self.date, build=self.build, revid=self.revid)
505 script = BUILD_SOURCE_TEMPLATE.format(
506 spb='/juju-build-any-all/spb',
507 source='/juju-build-trusty-all/source',
508 series='trusty',
509 ubuntu_version=self.ubuntu_version,
510 message='New upstream stable point release. (LP #987)')
511 env = make_deb_shell_env('me@email', 'me')
512 cc_mock.assert_called_with(
513 [script], shell=True, cwd='/juju-build-trusty-all', env=env)
514 ss_mock.assert_called_with(
515 '/juju-build-trusty-all', '/my/gpgcmd', 'me@email', 'me')
516
517
518class GetArgsTests(TestWithScenarios):
519
520 scenarios = [
521 ('release',
522 {'date': None,
523 'build': None,
524 'revid': None
525 }),
526
527 ('daily',
528 {'date': '20160502',
529 'build': '3065',
530 'revid': '4bbce805'
531 }),
532 ('broken_daily',
533 {'date': None,
534 'build': '3065',
535 'revid': '4bbce805'
536 })
537 ]
538
539 def test_get_args_source(self):
540 shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
541 with patch.dict('os.environ', shell_env):
542 args_list = ['prog', 'source', 'my_1.25.0.tar.gz', '~/workspace',
543 'trusty', '123', '456']
544 if self.date:
545 args_list.append('--date')
546 args_list.append(self.date)
547 if self.build:
548 args_list.append('--build')
549 args_list.append(self.build)
550 if self.revid:
551 args_list.append('--revid')
552 args_list.append(self.revid)
553 args = get_args(args_list)
554 self.assertEqual('source', args.command)
555 self.assertEqual('my_1.25.0.tar.gz', args.tar_file)
556 self.assertEqual('~/workspace', args.location)
557 self.assertEqual('trusty', args.series)
558 self.assertEqual(['123', '456'], args.bugs)
559 self.assertEqual('me@email', args.debemail)
560 self.assertEqual('me', args.debfullname)
561 self.assertIsNone(args.gpgcmd)
562 self.assertEqual(DEFAULT_SPB, args.branch)
563 self.assertEqual('1', args.upatch)
564 self.assertFalse(args.verbose)
565 self.assertEqual(self.date, args.date)
566 self.assertEqual(self.build, args.build)
567 self.assertEqual(self.revid, args.revid)
568
569 def test_get_args_source_default_spb2_branch(self):
570 shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
571 with patch.dict('os.environ', shell_env):
572 args_list = ['prog', 'source', 'my_2.0-a.tar.gz', '~/workspace',
573 'trusty', '123', '456']
574 if self.date:
575 args_list.append('--date')
576 args_list.append(self.date)
577 if self.build:
578 args_list.append('--build')
579 args_list.append(self.build)
580 if self.revid:
581 args_list.append('--revid')
582 args_list.append(self.revid)
583 args = get_args(args_list)
584 self.assertEqual('source', args.command)
585 self.assertEqual('my_2.0-a.tar.gz', args.tar_file)
586 self.assertEqual(DEFAULT_SPB2, args.branch)
587
588 def test_get_args_source_with_branch(self):
589 shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
590 with patch.dict('os.environ', shell_env):
591 args_list = ['prog', 'source', 'my_2.0-a.tar.gz', '~/workspace',
592 'trusty', '123', '456', '--branch', '~/my-branch']
593 if self.date:
594 args_list.append('--date')
595 args_list.append(self.date)
596 if self.build:
597 args_list.append('--build')
598 args_list.append(self.build)
599 if self.revid:
600 args_list.append('--revid')
601 args_list.append(self.revid)
602 args = get_args(args_list)
603 self.assertEqual('source', args.command)
604 self.assertEqual('my_2.0-a.tar.gz', args.tar_file)
605 self.assertEqual('~/my-branch', args.branch)
606
607 def test_get_args_source_with_living(self):
608 with patch('build_package.juju_series.get_living_names', autospec=True,
609 return_value=['precise', 'trusty']) as js_mock:
610 args_list = ['prog', 'source', 'my.tar.gz', '~/workspace',
611 'LIVING', '123', '456']
612 if self.date:
613 args_list.append('--date')
614 args_list.append(self.date)
615 if self.build:
616 args_list.append('--build')
617 args_list.append(self.build)
618 if self.revid:
619 args_list.append('--revid')
620 args_list.append(self.revid)
621 args = get_args(args_list)
622 self.assertEqual(['precise', 'trusty'], args.series)
623 self.assertEqual(1, js_mock.call_count)
624 args = get_args(
625 ['prog', 'source', 'my.tar.gz', '~/workspace', 'LIVING',
626 '123', '456'])
627 self.assertEqual(juju_series.get_living_names(), args.series)
628
629 def test_main_source(self):
630 with patch('build_package.build_source', autospec=True,
631 return_value=0) as bs_mock:
632 args_list = ['prog', 'source', '--debemail', 'me@email',
633 '--debfullname', 'me', 'my.tar.gz', '~/workspace',
634 'trusty', '123', '456']
635 if self.date:
636 args_list.append('--date')
637 args_list.append(self.date)
638 if self.build:
639 args_list.append('--build')
640 args_list.append(self.build)
641 if self.revid:
642 args_list.append('--revid')
643 args_list.append(self.revid)
644 code = main(args_list)
645 self.assertEqual(0, code)
646 bs_mock.assert_called_with(
647 'my.tar.gz', '~/workspace', 'trusty', ['123', '456'],
648 debemail='me@email', debfullname='me', gpgcmd=None,
649 branch=DEFAULT_SPB, upatch='1', verbose=False,
650 date=self.date, build=self.build, revid=self.revid)

Subscribers

People subscribed via source and target branches