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
1=== modified file 'build_package.py'
2--- build_package.py 2016-04-14 22:08:19 +0000
3+++ build_package.py 2016-05-04 14:09:15 +0000
4@@ -115,6 +115,7 @@
5
6
7 UBUNTU_VERSION_TEMPLATE = '{version}-0ubuntu1~{release}.{upatch}~juju1'
8+DAILY_VERSION_TEMPLATE = '{version}-{date}+{build}+{revid}~{release}'
9
10
11 VERSION_PATTERN = re.compile('(\d+)\.(\d+)\.(\d+)')
12@@ -317,18 +318,28 @@
13 return spb
14
15
16-def make_ubuntu_version(series, version, upatch=1):
17+def make_ubuntu_version(series, version, upatch=1,
18+ date=None, build=None, revid=None):
19 """Return an Ubuntu package version.
20
21 :param series: The series codename.
22 :param version: The upstream version.
23 :param upatch: The package patch number for cases where a packaging rules
24 are updated and the package rebuilt.
25+ :param date: The date of the build.
26+ :param build: The build number in CI.
27+ :param revid: The revid hash of the source.
28 :return: An Ubuntu version string.
29 """
30 release = juju_series.get_version(series)
31- return UBUNTU_VERSION_TEMPLATE.format(
32- version=version, release=release, upatch=upatch)
33+ # if daily params are set, we make daily build
34+ if all([date, build, revid]):
35+ return DAILY_VERSION_TEMPLATE.format(
36+ version=version, release=release, upatch=upatch,
37+ date=date, build=build, revid=revid)
38+ else:
39+ return UBUNTU_VERSION_TEMPLATE.format(
40+ version=version, release=release, upatch=upatch)
41
42
43 def make_changelog_message(version, bugs=None):
44@@ -382,8 +393,9 @@
45
46
47 def create_source_package(source_dir, spb, series, version,
48- upatch='1', bugs=None, gpgcmd=None,
49- debemail=None, debfullname=None, verbose=False):
50+ upatch='1', bugs=None, gpgcmd=None, debemail=None,
51+ debfullname=None, verbose=False,
52+ date=None, build=None, revid=None):
53 """Create a series source package from a source package branch.
54
55 The new source package can be used to create series source packages.
56@@ -401,8 +413,13 @@
57 :param debemail: The email address to attribute the changelog entry to.
58 :param debfullname: The name to attribute the changelog entry to.
59 :param verbose: Increase the information about the work performed.
60+ :param date: The date of the build.
61+ :param build: The build number in CI.
62+ :param revid: The revid hash of the source.
63 """
64- ubuntu_version = make_ubuntu_version(series, version, upatch)
65+
66+ ubuntu_version = make_ubuntu_version(series, version, upatch,
67+ date, build, revid)
68 message = make_changelog_message(version, bugs=bugs)
69 source = os.path.join(source_dir, 'source')
70 env = make_deb_shell_env(debemail, debfullname)
71@@ -416,7 +433,8 @@
72
73 def build_source(tarfile_path, location, series, bugs,
74 debemail=None, debfullname=None, gpgcmd=None,
75- branch=None, upatch=1, verbose=False):
76+ branch=None, upatch=1, verbose=False,
77+ date=None, build=None, revid=None):
78 """Build one or more series source packages from a new release tarfile.
79
80 The packages are unsigned by default, but providing the path to a gpgcmd,
81@@ -435,12 +453,25 @@
82 :param upatch: The package patch number for cases where a packaging rules
83 are updated and the package rebuilt.
84 :param verbose: Increase the verbostiy of output.
85+ :param date: The date of the build.
86+ :param build: The build number in CI.
87+ :param revid: The revid hash of the source.
88 :return: the exit code (which is 0 or else an exception was raised).
89 """
90 if not isinstance(series, list):
91 series = [series]
92 tarfile_name = os.path.basename(tarfile_path)
93 version = tarfile_name.split('_')[-1].replace('.tar.gz', '')
94+ if all([date, build, revid]):
95+ daily_version = '{}~{}~{}~{}'.format(version, date, build, revid)
96+ daily_tarfile_name = tarfile_name.replace(version, daily_version)
97+ tarfile_dir = os.path.dirname(tarfile_path)
98+ daily_tarfile_path = os.path.join(tarfile_dir, daily_tarfile_name)
99+ os.rename(tarfile_name, daily_tarfile_name)
100+ tarfile_path = daily_tarfile_path
101+ tarfile_name = daily_tarfile_name
102+ version = daily_version
103+
104 files = [SourceFile(None, None, tarfile_name, tarfile_path)]
105 spb_dir = setup_local(
106 location, 'any', 'all', files, verbose=verbose)
107@@ -448,9 +479,10 @@
108 for a_series in series:
109 build_dir = setup_local(location, a_series, 'all', [], verbose=verbose)
110 create_source_package(
111- build_dir, spb, a_series, version, upatch=upatch, bugs=bugs,
112- gpgcmd=gpgcmd, debemail=debemail, debfullname=debfullname,
113- verbose=verbose)
114+ build_dir, spb, a_series, version,
115+ upatch=upatch, bugs=bugs, gpgcmd=gpgcmd,
116+ debemail=debemail, debfullname=debfullname, verbose=verbose,
117+ date=date, build=build, revid=revid)
118 return 0
119
120
121@@ -473,7 +505,8 @@
122 args.tar_file, args.location, args.series, args.bugs,
123 debemail=args.debemail, debfullname=args.debfullname,
124 gpgcmd=args.gpgcmd, branch=args.branch, upatch=args.upatch,
125- verbose=args.verbose)
126+ verbose=args.verbose,
127+ date=args.date, build=args.build, revid=args.revid)
128 elif args.command == 'binary':
129 exitcode = build_binary(
130 args.dsc, args.location, args.series, args.arch,
131@@ -510,6 +543,12 @@
132 src_parser.add_argument(
133 'series', help="The destination Ubuntu release or LIVING for all.")
134 src_parser.add_argument(
135+ '--date', default=None, help="A datestamp to apply to the build")
136+ src_parser.add_argument(
137+ '--build', default=None, help="The build number from CI")
138+ src_parser.add_argument(
139+ '--revid', default=None, help="The short hash for revid")
140+ src_parser.add_argument(
141 'bugs', nargs='*', help="Bugs this version will fix in the release.")
142 bin_parser = subparsers.add_parser('binary', help='Build a binary package')
143 bin_parser.add_argument(
144
145=== modified file 'tests/test_build_package.py'
146--- tests/test_build_package.py 2016-02-10 18:39:43 +0000
147+++ tests/test_build_package.py 2016-05-04 14:09:15 +0000
148@@ -8,6 +8,7 @@
149 from StringIO import StringIO
150 from textwrap import dedent
151 import unittest
152+from testscenarios import TestWithScenarios
153
154 from build_package import (
155 _JujuSeries,
156@@ -165,70 +166,6 @@
157 bb_mock.assert_called_with(
158 'my.dsc', '~/workspace', 'trusty', 'i386', ppa=None, verbose=False)
159
160- def test_get_args_source(self):
161- shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
162- with patch.dict('os.environ', shell_env):
163- args = get_args(
164- ['prog', 'source', 'my_1.25.0.tar.gz', '~/workspace', 'trusty',
165- '123', '456'])
166- self.assertEqual('source', args.command)
167- self.assertEqual('my_1.25.0.tar.gz', args.tar_file)
168- self.assertEqual('~/workspace', args.location)
169- self.assertEqual('trusty', args.series)
170- self.assertEqual(['123', '456'], args.bugs)
171- self.assertEqual('me@email', args.debemail)
172- self.assertEqual('me', args.debfullname)
173- self.assertIsNone(args.gpgcmd)
174- self.assertEqual(DEFAULT_SPB, args.branch)
175- self.assertEqual('1', args.upatch)
176- self.assertFalse(args.verbose)
177-
178- def test_get_args_source_default_spb2_branch(self):
179- shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
180- with patch.dict('os.environ', shell_env):
181- args = get_args(
182- ['prog', 'source', 'my_2.0-a.tar.gz', '~/workspace', 'trusty',
183- '123', '456'])
184- self.assertEqual('source', args.command)
185- self.assertEqual('my_2.0-a.tar.gz', args.tar_file)
186- self.assertEqual(DEFAULT_SPB2, args.branch)
187-
188- def test_get_args_source_with_branch(self):
189- shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
190- with patch.dict('os.environ', shell_env):
191- args = get_args(
192- ['prog', 'source', 'my_2.0-a.tar.gz', '~/workspace', 'trusty',
193- '123', '456', '--branch', '~/my-branch'])
194- self.assertEqual('source', args.command)
195- self.assertEqual('my_2.0-a.tar.gz', args.tar_file)
196- self.assertEqual('~/my-branch', args.branch)
197-
198- def test_get_args_source_with_living(self):
199- with patch('build_package.juju_series.get_living_names', autospec=True,
200- return_value=['precise', 'trusty']) as js_mock:
201- args = get_args(
202- ['prog', 'source', 'my.tar.gz', '~/workspace', 'LIVING',
203- '123', '456'])
204- self.assertEqual(['precise', 'trusty'], args.series)
205- self.assertEqual(1, js_mock.call_count)
206- args = get_args(
207- ['prog', 'source', 'my.tar.gz', '~/workspace', 'LIVING',
208- '123', '456'])
209- self.assertEqual(juju_series.get_living_names(), args.series)
210-
211- def test_main_source(self):
212- with patch('build_package.build_source', autospec=True,
213- return_value=0) as bs_mock:
214- code = main([
215- 'prog', 'source',
216- '--debemail', 'me@email', '--debfullname', 'me',
217- 'my.tar.gz', '~/workspace', 'trusty', '123', '456'])
218- self.assertEqual(0, code)
219- bs_mock.assert_called_with(
220- 'my.tar.gz', '~/workspace', 'trusty', ['123', '456'],
221- debemail='me@email', debfullname='me', gpgcmd=None,
222- branch=DEFAULT_SPB, upatch='1', verbose=False)
223-
224 @autopatch('build_package.move_debs', return_value=True)
225 @autopatch('build_package.teardown_lxc', return_value=True)
226 @autopatch('build_package.build_in_lxc')
227@@ -380,28 +317,6 @@
228 found = move_debs(build_dir, workspace)
229 self.assertFalse(found)
230
231- @autopatch('build_package.create_source_package')
232- @autopatch('build_package.create_source_package_branch',
233- return_value='./spb_path')
234- @autopatch('build_package.setup_local',
235- side_effect=['./spb_dir', './precise_dir', './trusty_dir'])
236- def test_build_source(self, sl_mock, spb_mock, csp_mock):
237- return_code = build_source(
238- './my_1.2.3.tar.gz', './workspace', ['precise', 'trusty'], ['987'],
239- debemail=None, debfullname=None, gpgcmd='my/gpg',
240- branch='lp:branch', upatch=None, verbose=False)
241- sl_mock.assert_any_call(
242- './workspace', 'any', 'all',
243- [SourceFile(None, None, 'my_1.2.3.tar.gz', './my_1.2.3.tar.gz')],
244- verbose=False)
245- spb_mock.assert_called_with(
246- './spb_dir', '1.2.3', 'my_1.2.3.tar.gz', 'lp:branch')
247- sl_mock.assert_any_call(
248- './workspace', 'precise', 'all', [], verbose=False)
249- sl_mock.assert_any_call(
250- './workspace', 'trusty', 'all', [], verbose=False)
251- self.assertEqual(0, return_code)
252-
253 @autopatch('subprocess.check_call')
254 def test_create_source_package_branch(self, cc_mock):
255 spb = create_source_package_branch(
256@@ -433,41 +348,6 @@
257 'New upstream stable point release. (LP #987, LP #876)',
258 message)
259
260- @autopatch('build_package.sign_source_package')
261- @autopatch('subprocess.check_call')
262- def test_create_source_package(self, cc_mock, ss_mock):
263- create_source_package(
264- '/juju-build-trusty-all', '/juju-build-any-all/spb', 'trusty',
265- '1.2.3', upatch='1', bugs=['987'], gpgcmd=None,
266- debemail='me@email', debfullname='me', verbose=False)
267- script = BUILD_SOURCE_TEMPLATE.format(
268- spb='/juju-build-any-all/spb',
269- source='/juju-build-trusty-all/source',
270- series='trusty', ubuntu_version='1.2.3-0ubuntu1~14.04.1~juju1',
271- message='New upstream stable point release. (LP #987)')
272- env = make_deb_shell_env('me@email', 'me')
273- cc_mock.assert_called_with(
274- [script], shell=True, cwd='/juju-build-trusty-all', env=env)
275- self.assertEqual(0, ss_mock.call_count)
276-
277- @autopatch('build_package.sign_source_package')
278- @autopatch('subprocess.check_call')
279- def test_create_source_package_with_gpgcmd(self, cc_mock, ss_mock):
280- create_source_package(
281- '/juju-build-trusty-all', '/juju-build-any-all/spb', 'trusty',
282- '1.2.3', upatch='1', bugs=['987'], gpgcmd='/my/gpgcmd',
283- debemail='me@email', debfullname='me', verbose=False)
284- script = BUILD_SOURCE_TEMPLATE.format(
285- spb='/juju-build-any-all/spb',
286- source='/juju-build-trusty-all/source',
287- series='trusty', ubuntu_version='1.2.3-0ubuntu1~14.04.1~juju1',
288- message='New upstream stable point release. (LP #987)')
289- env = make_deb_shell_env('me@email', 'me')
290- cc_mock.assert_called_with(
291- [script], shell=True, cwd='/juju-build-trusty-all', env=env)
292- ss_mock.assert_called_with(
293- '/juju-build-trusty-all', '/my/gpgcmd', 'me@email', 'me')
294-
295 @autopatch('subprocess.check_call')
296 def test_sign_source_package(self, cc_mock):
297 sign_source_package(
298@@ -508,3 +388,263 @@
299 package_version='1.25.0-0ubuntu1~16.04.1~juju1')
300 self.assertEqual(0, code)
301 self.assertEqual('xenial\n', so_mock.getvalue())
302+
303+
304+class CreateBuildSource(TestWithScenarios):
305+
306+ scenarios = [
307+ ('release',
308+ {'date': None,
309+ 'build': None,
310+ 'revid': None,
311+ 'version': '1.2.3',
312+ 'original_tarfile_name': None,
313+ 'tarfile_name': 'my_1.2.3.tar.gz',
314+ 'tarfile_path': './my_1.2.3.tar.gz'
315+ }),
316+
317+ ('daily',
318+ {'date': '20160502',
319+ 'build': '3065',
320+ 'revid': '4bbce805',
321+ 'version': '1.2.3~20160502~3065~4bbce805',
322+ 'original_tarfile_name': 'my_1.2.3.tar.gz',
323+ 'tarfile_name': 'my_1.2.3~20160502~3065~4bbce805.tar.gz',
324+ 'tarfile_path': './my_1.2.3~20160502~3065~4bbce805.tar.gz'
325+ }),
326+ ('broken_daily',
327+ {'date': None,
328+ 'build': '3065',
329+ 'revid': '4bbce805',
330+ 'version': '1.2.3',
331+ 'original_tarfile_name': None,
332+ 'tarfile_name': 'my_1.2.3.tar.gz',
333+ 'tarfile_path': './my_1.2.3.tar.gz'
334+ })
335+ ]
336+
337+ @autopatch('build_package.create_source_package')
338+ @autopatch('build_package.create_source_package_branch',
339+ return_value='./spb_path')
340+ @autopatch('build_package.setup_local',
341+ side_effect=['./spb_dir', './precise_dir', './trusty_dir'])
342+ @autopatch('build_package.os.rename', return_value=True)
343+ def test_build_source_test(self, os_mock, sl_mock, spb_mock, csp_mock):
344+ return_code = build_source(
345+ './my_1.2.3.tar.gz', './workspace', ['precise', 'trusty'], ['987'],
346+ debemail=None, debfullname=None, gpgcmd='my/gpg',
347+ branch='lp:branch', upatch=None, verbose=False,
348+ date=self.date, build=self.build, revid=self.revid)
349+ if self.original_tarfile_name is not None:
350+ os_mock.assert_called_with(self.original_tarfile_name,
351+ self.tarfile_name)
352+ sl_mock.assert_any_call(
353+ './workspace', 'any', 'all',
354+ [SourceFile(None, None, self.tarfile_name, self.tarfile_path)],
355+ verbose=False)
356+ spb_mock.assert_called_with(
357+ './spb_dir', self.version, self.tarfile_name, 'lp:branch')
358+ sl_mock.assert_any_call(
359+ './workspace', 'precise', 'all', [], verbose=False)
360+ sl_mock.assert_any_call(
361+ './workspace', 'trusty', 'all', [], verbose=False)
362+ self.assertEqual(0, return_code)
363+
364+
365+class CreateSourcePackageTests(TestWithScenarios):
366+
367+ scenarios = [
368+ ('release',
369+ {'date': None,
370+ 'build': None,
371+ 'revid': None,
372+ 'ubuntu_version': '1.2.3-0ubuntu1~14.04.1~juju1'
373+ }),
374+
375+ ('daily',
376+ {'date': '20160502',
377+ 'build': '3065',
378+ 'revid': '4bbce805',
379+ 'ubuntu_version': '1.2.3-20160502+3065+4bbce805~14.04'
380+ }),
381+ ('broken_daily',
382+ {'date': None,
383+ 'build': '3065',
384+ 'revid': '4bbce805',
385+ 'ubuntu_version': '1.2.3-0ubuntu1~14.04.1~juju1'
386+ })
387+ ]
388+
389+ @autopatch('build_package.sign_source_package')
390+ @autopatch('subprocess.check_call')
391+ def test_create_source_package(self, cc_mock, ss_mock):
392+ create_source_package(
393+ '/juju-build-trusty-all', '/juju-build-any-all/spb', 'trusty',
394+ '1.2.3', upatch='1', bugs=['987'], gpgcmd=None,
395+ debemail='me@email', debfullname='me', verbose=False,
396+ date=self.date, build=self.build, revid=self.revid)
397+ script = BUILD_SOURCE_TEMPLATE.format(
398+ spb='/juju-build-any-all/spb',
399+ source='/juju-build-trusty-all/source',
400+ series='trusty',
401+ ubuntu_version=self.ubuntu_version,
402+ message='New upstream stable point release. (LP #987)')
403+ env = make_deb_shell_env('me@email', 'me')
404+ cc_mock.assert_called_with(
405+ [script], shell=True, cwd='/juju-build-trusty-all', env=env)
406+ self.assertEqual(0, ss_mock.call_count)
407+
408+ @autopatch('build_package.sign_source_package')
409+ @autopatch('subprocess.check_call')
410+ def test_create_source_package_with_gpgcmd(self, cc_mock, ss_mock):
411+ create_source_package(
412+ '/juju-build-trusty-all', '/juju-build-any-all/spb', 'trusty',
413+ '1.2.3', upatch='1', bugs=['987'], gpgcmd='/my/gpgcmd',
414+ debemail='me@email', debfullname='me', verbose=False,
415+ date=self.date, build=self.build, revid=self.revid)
416+ script = BUILD_SOURCE_TEMPLATE.format(
417+ spb='/juju-build-any-all/spb',
418+ source='/juju-build-trusty-all/source',
419+ series='trusty',
420+ ubuntu_version=self.ubuntu_version,
421+ message='New upstream stable point release. (LP #987)')
422+ env = make_deb_shell_env('me@email', 'me')
423+ cc_mock.assert_called_with(
424+ [script], shell=True, cwd='/juju-build-trusty-all', env=env)
425+ ss_mock.assert_called_with(
426+ '/juju-build-trusty-all', '/my/gpgcmd', 'me@email', 'me')
427+
428+
429+class GetArgsTests(TestWithScenarios):
430+
431+ scenarios = [
432+ ('release',
433+ {'date': None,
434+ 'build': None,
435+ 'revid': None
436+ }),
437+
438+ ('daily',
439+ {'date': '20160502',
440+ 'build': '3065',
441+ 'revid': '4bbce805'
442+ }),
443+ ('broken_daily',
444+ {'date': None,
445+ 'build': '3065',
446+ 'revid': '4bbce805'
447+ })
448+ ]
449+
450+ def test_get_args_source(self):
451+ shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
452+ with patch.dict('os.environ', shell_env):
453+ args_list = ['prog', 'source', 'my_1.25.0.tar.gz', '~/workspace',
454+ 'trusty', '123', '456']
455+ if self.date:
456+ args_list.append('--date')
457+ args_list.append(self.date)
458+ if self.build:
459+ args_list.append('--build')
460+ args_list.append(self.build)
461+ if self.revid:
462+ args_list.append('--revid')
463+ args_list.append(self.revid)
464+ args = get_args(args_list)
465+ self.assertEqual('source', args.command)
466+ self.assertEqual('my_1.25.0.tar.gz', args.tar_file)
467+ self.assertEqual('~/workspace', args.location)
468+ self.assertEqual('trusty', args.series)
469+ self.assertEqual(['123', '456'], args.bugs)
470+ self.assertEqual('me@email', args.debemail)
471+ self.assertEqual('me', args.debfullname)
472+ self.assertIsNone(args.gpgcmd)
473+ self.assertEqual(DEFAULT_SPB, args.branch)
474+ self.assertEqual('1', args.upatch)
475+ self.assertFalse(args.verbose)
476+ self.assertEqual(self.date, args.date)
477+ self.assertEqual(self.build, args.build)
478+ self.assertEqual(self.revid, args.revid)
479+
480+ def test_get_args_source_default_spb2_branch(self):
481+ shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
482+ with patch.dict('os.environ', shell_env):
483+ args_list = ['prog', 'source', 'my_2.0-a.tar.gz', '~/workspace',
484+ 'trusty', '123', '456']
485+ if self.date:
486+ args_list.append('--date')
487+ args_list.append(self.date)
488+ if self.build:
489+ args_list.append('--build')
490+ args_list.append(self.build)
491+ if self.revid:
492+ args_list.append('--revid')
493+ args_list.append(self.revid)
494+ args = get_args(args_list)
495+ self.assertEqual('source', args.command)
496+ self.assertEqual('my_2.0-a.tar.gz', args.tar_file)
497+ self.assertEqual(DEFAULT_SPB2, args.branch)
498+
499+ def test_get_args_source_with_branch(self):
500+ shell_env = {'DEBEMAIL': 'me@email', 'DEBFULLNAME': 'me'}
501+ with patch.dict('os.environ', shell_env):
502+ args_list = ['prog', 'source', 'my_2.0-a.tar.gz', '~/workspace',
503+ 'trusty', '123', '456', '--branch', '~/my-branch']
504+ if self.date:
505+ args_list.append('--date')
506+ args_list.append(self.date)
507+ if self.build:
508+ args_list.append('--build')
509+ args_list.append(self.build)
510+ if self.revid:
511+ args_list.append('--revid')
512+ args_list.append(self.revid)
513+ args = get_args(args_list)
514+ self.assertEqual('source', args.command)
515+ self.assertEqual('my_2.0-a.tar.gz', args.tar_file)
516+ self.assertEqual('~/my-branch', args.branch)
517+
518+ def test_get_args_source_with_living(self):
519+ with patch('build_package.juju_series.get_living_names', autospec=True,
520+ return_value=['precise', 'trusty']) as js_mock:
521+ args_list = ['prog', 'source', 'my.tar.gz', '~/workspace',
522+ 'LIVING', '123', '456']
523+ if self.date:
524+ args_list.append('--date')
525+ args_list.append(self.date)
526+ if self.build:
527+ args_list.append('--build')
528+ args_list.append(self.build)
529+ if self.revid:
530+ args_list.append('--revid')
531+ args_list.append(self.revid)
532+ args = get_args(args_list)
533+ self.assertEqual(['precise', 'trusty'], args.series)
534+ self.assertEqual(1, js_mock.call_count)
535+ args = get_args(
536+ ['prog', 'source', 'my.tar.gz', '~/workspace', 'LIVING',
537+ '123', '456'])
538+ self.assertEqual(juju_series.get_living_names(), args.series)
539+
540+ def test_main_source(self):
541+ with patch('build_package.build_source', autospec=True,
542+ return_value=0) as bs_mock:
543+ args_list = ['prog', 'source', '--debemail', 'me@email',
544+ '--debfullname', 'me', 'my.tar.gz', '~/workspace',
545+ 'trusty', '123', '456']
546+ if self.date:
547+ args_list.append('--date')
548+ args_list.append(self.date)
549+ if self.build:
550+ args_list.append('--build')
551+ args_list.append(self.build)
552+ if self.revid:
553+ args_list.append('--revid')
554+ args_list.append(self.revid)
555+ code = main(args_list)
556+ self.assertEqual(0, code)
557+ bs_mock.assert_called_with(
558+ 'my.tar.gz', '~/workspace', 'trusty', ['123', '456'],
559+ debemail='me@email', debfullname='me', gpgcmd=None,
560+ branch=DEFAULT_SPB, upatch='1', verbose=False,
561+ date=self.date, build=self.build, revid=self.revid)

Subscribers

People subscribed via source and target branches