Merge lp:~sil2100/ubuntu-archive-tools/kernel-sru-review-cache into lp:ubuntu-archive-tools

Proposed by Łukasz Zemczak
Status: Merged
Merged at revision: 1106
Proposed branch: lp:~sil2100/ubuntu-archive-tools/kernel-sru-review-cache
Merge into: lp:ubuntu-archive-tools
Diff against target: 169 lines (+88/-6)
1 file modified
kernel-sru-review (+88/-6)
To merge this branch: bzr merge lp:~sil2100/ubuntu-archive-tools/kernel-sru-review-cache
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Adam Conrad Pending
Review via email: mp+322468@code.launchpad.net

Commit message

Add an option to provide a kernel tarball cache directory to kernel-sru-review from which the orig tarballs will be used and stored for later script re-runs.

Description of the change

Add an option to provide a kernel tarball cache directory to kernel-sru-review from which the orig tarballs will be used and stored for later script re-runs.

Rationale: currently every run of kernel-sru-review pulls the orig tarball for the kernel as we work in a temporary directory that gets cleaned up after termination. Considering how infrequently the upstream versions are changed this way we can save a lot of time.

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) wrote :

LGTM with a few changes.

I would also like to get Adam's review, since I know he has some sort of local mirroring setup he references, to know if this would meet his needs or if something different is needed for his use case.

review: Needs Fixing
1092. By Łukasz Zemczak

Fixes as per Steve's review.

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Is there anything else I could do to get this merged? I would opt to just get it in and modify later on if Adam has some additional requirements.

1093. By Łukasz Zemczak

Attempt to hard link before doing a copy of the tarballs.

1094. By Łukasz Zemczak

As per Adam's suggestions, add a default cache tarball directory and make sure we look at the cwd for the tarballs first.

1095. By Łukasz Zemczak

By accident commited a debug-only change.

1096. By Łukasz Zemczak

Another change - make sure that we don't copy when link already exists. Don't do anything unnecessary.

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

The latest changes have been tested in production - I used those for recent kernel reviews. All cases have been verified: setting an explicit tarball directory, using the default tarball directory and using the current working directory. Everything seemed to work as expected.

Could we get a final review on this one?

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Any movement on this one? I have addressed Adam's concerns with the last batch of changes. Since I have been using this since 3 or 4 kernel releases already, I would really like the permission to get this merged. It should also fit more Adam's workflow as well as he can just execute it from the tarball cache directory and all works like a charm.

Revision history for this message
Steve Langasek (vorlon) wrote :

Sorry for the delays in review... a few more changes requested :(

review: Needs Fixing
1097. By Łukasz Zemczak

Do not cache tarballs by default, but still use tarballs from the tardir if available.

1098. By Łukasz Zemczak

Slightly rename some variables + also pass the work directory as context.

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

The reason why I was passing only the 'main directory' in the context field was that I knew that I could always get the work directory through getcwd() inside any function, not having to pass it through the context. Since for tarball cache handling I need to know both directories - the work directory (i.e. the temporary dir that we create) and the start directory. The work one for known reasons - we need to know where we're copying the tarballs to. The start directory, on the other hand, is also needed as per Adam's request we are supposed to look for tarballs also in the directory where the script was executed in.

Passing only the start directory allowed me to not skip passing one directory. But yeah, there's no harm in passing it I guess, so I did that now.

After the latest changes, all concerns should have been addressed. Currently tarball caching is not enabled by default but we do try to fetch tarballs from cache directories (or the cwd) if available always. This way we should also satisfy Adam's needs.

Revision history for this message
Steve Langasek (vorlon) wrote :

I like this very much.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'kernel-sru-review'
--- kernel-sru-review 2017-03-17 12:17:00 +0000
+++ kernel-sru-review 2017-07-11 09:42:52 +0000
@@ -28,6 +28,7 @@
28 kernel-sru-review [-s precise] linux28 kernel-sru-review [-s precise] linux
29"""29"""
3030
31import glob
31import datetime32import datetime
32import os33import os
33import pytz34import pytz
@@ -59,13 +60,58 @@
59 for source in full_packages:60 for source in full_packages:
60 process_source_package(61 process_source_package(
61 source, release, context['archive'], context['ppa'],62 source, release, context['archive'], context['ppa'],
62 context['ubuntu'])63 context['ubuntu'], context['startdir'], context['workdir'],
64 context['tardir'], context['tarcache'])
63 tasks['proposed'].status = 'Fix Committed'65 tasks['proposed'].status = 'Fix Committed'
64 tasks['proposed'].assignee = lp.me66 tasks['proposed'].assignee = lp.me
65 tasks['proposed'].lp_save()67 tasks['proposed'].lp_save()
6668
6769
68def process_source_package(source, release, archive, ppa, ubuntu):70def fetch_tarball_from_cache(directory, tardir, source, version, cwd):
71 actual_tardir = None
72 tarballs = []
73 # if a tarball directory is given, try to find the tarball there
74 if tardir:
75 glob_pattern = '%s_%s.orig.tar.*' % (source, version)
76 # first we look in the current working directory where the command was
77 # called from
78 actual_tardir = cwd
79 tarballs = glob.glob(os.path.join(cwd, glob_pattern))
80 if not tarballs:
81 actual_tardir = tardir
82 tarballs = glob.glob(os.path.join(tardir, glob_pattern))
83 if tarballs:
84 target = os.path.join(directory, os.path.basename(tarballs[0]))
85 try:
86 os.link(tarballs[0], target)
87 except FileExistsError:
88 pass
89 except:
90 # if the hard linking fails, do a copy operation
91 shutil.copy(tarballs[0], target)
92 else:
93 actual_tardir = None
94 return actual_tardir
95
96
97def save_tarball_to_cache(directory, tardir, source, version):
98 # if we use a tarball directory and downloaded a new tarball, copy it over
99 if tardir:
100 glob_pattern = '%s_%s.orig.tar.*' % (source, version)
101 to_copy = glob.glob(os.path.join(directory, glob_pattern))
102 for tarball in to_copy:
103 target = os.path.join(tardir, os.path.basename(tarball))
104 try:
105 os.link(tarball, target)
106 except FileExistsError:
107 pass
108 except:
109 # if the hard linking fails, do a copy operation
110 shutil.copy(tarball, target)
111
112
113def process_source_package(source, release, archive, ppa, ubuntu,
114 start_dir, work_dir, tardir=None, tar_cache=False):
69 series = ubuntu.getSeries(name_or_version=release)115 series = ubuntu.getSeries(name_or_version=release)
70116
71 ppa_src = ppa.getPublishedSources(order_by_date=True,117 ppa_src = ppa.getPublishedSources(order_by_date=True,
@@ -103,6 +149,9 @@
103 old_majorabi = re.sub(r"\.[^.]+$", '', old_fullabi)149 old_majorabi = re.sub(r"\.[^.]+$", '', old_fullabi)
104 old_upstream = old_fullabi.split('-')[0]150 old_upstream = old_fullabi.split('-')[0]
105151
152 real_tardir = fetch_tarball_from_cache(
153 work_dir, tardir, source, old_upstream, start_dir)
154
106 # grab the old source first155 # grab the old source first
107 pull_cmd = ['pull-lp-source', source, source_ver]156 pull_cmd = ['pull-lp-source', source, source_ver]
108 try:157 try:
@@ -125,9 +174,15 @@
125 (source, source_ver))174 (source, source_ver))
126 raise e175 raise e
127176
177 if not real_tardir and tar_cache:
178 save_tarball_to_cache(work_dir, tardir, source, old_upstream)
179
128 # move the source dir aside so that it doesn't clobber.180 # move the source dir aside so that it doesn't clobber.
129 os.rename(source + '-' + old_upstream, source + '-' + old_upstream + '.old')181 os.rename(source + '-' + old_upstream, source + '-' + old_upstream + '.old')
130182
183 real_tardir = fetch_tarball_from_cache(
184 work_dir, tardir, source, new_upstream, start_dir)
185
131 # grab the new source186 # grab the new source
132 dget_cmd = ['dget', '-u', ppa_dsc]187 dget_cmd = ['dget', '-u', ppa_dsc]
133 try:188 try:
@@ -137,6 +192,9 @@
137 (source, ppa_ver))192 (source, ppa_ver))
138 raise e193 raise e
139194
195 if not real_tardir and tar_cache:
196 save_tarball_to_cache(work_dir, tardir, source, new_upstream)
197
140 # look at the diff198 # look at the diff
141 diff_cmd = ('diff -uNr "{}-{}.old" "{}-{}" | filterdiff -x \'**/abi/**\''199 diff_cmd = ('diff -uNr "{}-{}.old" "{}-{}" | filterdiff -x \'**/abi/**\''
142 + ' | sensible-pager').format(200 + ' | sensible-pager').format(
@@ -186,16 +244,37 @@
186 parser = OptionParser(244 parser = OptionParser(
187 usage="Usage: %prog [options] bug [bug ...]")245 usage="Usage: %prog [options] bug [bug ...]")
188246
247 cachedir = os.path.expanduser(
248 '~/.cache/ubuntu-archive-tools/kernel-tarballs')
249
189 parser.add_option(250 parser.add_option(
190 "-l", "--launchpad", dest="launchpad_instance", default="production")251 "-l", "--launchpad", dest="launchpad_instance", default="production")
191 parser.add_option(252 parser.add_option(
192 "-k", "--keep-files", dest="keep_files", action="store_true")253 "-k", "--keep-files", dest="keep_files", action="store_true")
254 parser.add_option(
255 "-C", "--cache-tarballs", dest="caching", action="store_true")
256 parser.add_option(
257 "-t", "--tarball-directory", dest="tardir", default=cachedir)
193258
194 opts, bugs = parser.parse_args()259 opts, bugs = parser.parse_args()
195260
196 if len(bugs) < 1:261 if len(bugs) < 1:
197 parser.error('Need to specify at least one bug number')262 parser.error('Need to specify at least one bug number')
198263
264 if opts.tardir:
265 tardir = os.path.abspath(opts.tardir)
266 else:
267 tardir = None
268
269 if opts.caching:
270 # if we enabled tarball caching, make sure the tarball directory exists
271 if tardir and not os.path.isdir(tardir):
272 try:
273 os.makedirs(tardir)
274 except:
275 parser.error(
276 'Invalid tarball directory specified (%s)' % tardir)
277
199 launchpad = Launchpad.login_with(278 launchpad = Launchpad.login_with(
200 'ubuntu-archive-tools', opts.launchpad_instance, version='devel')279 'ubuntu-archive-tools', opts.launchpad_instance, version='devel')
201280
@@ -204,15 +283,18 @@
204 ppa = launchpad.people['canonical-kernel-team'].getPPAByName(283 ppa = launchpad.people['canonical-kernel-team'].getPPAByName(
205 distribution=ubuntu, name='ppa')284 distribution=ubuntu, name='ppa')
206285
207 context = {'archive': archive, 'ppa': ppa, 'ubuntu': ubuntu}286 start_dir = os.getcwd()
208 main_dir = os.getcwd()287 context = {
288 'archive': archive, 'ppa': ppa, 'ubuntu': ubuntu,
289 'tardir': tardir, 'tarcache': opts.caching, 'startdir': start_dir }
209 for bugnum in bugs:290 for bugnum in bugs:
210 with ExitStack() as resources:291 with ExitStack() as resources:
211 cwd = mkdtemp(prefix='kernel-sru-{}-'.format(bugnum), dir=main_dir)292 cwd = mkdtemp(prefix='kernel-sru-%s-' % bugnum, dir=start_dir)
212 if not opts.keep_files:293 if not opts.keep_files:
213 resources.callback(shutil.rmtree, cwd)294 resources.callback(shutil.rmtree, cwd)
214 os.chdir(cwd)295 os.chdir(cwd)
296 context['workdir'] = cwd
215 process_sru_bug(297 process_sru_bug(
216 launchpad, bugnum, review_task_callback,298 launchpad, bugnum, review_task_callback,
217 review_source_callback, context)299 review_source_callback, context)
218 os.chdir(main_dir)300 os.chdir(start_dir)

Subscribers

People subscribed via source and target branches