Merge lp:~stevenk/launchpad/deal-with-no-authorized_size into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 15955
Proposed branch: lp:~stevenk/launchpad/deal-with-no-authorized_size
Merge into: lp:launchpad
Diff against target: 121 lines (+50/-20)
4 files modified
lib/lp/archiveuploader/tests/test_ppauploadprocessor.py (+11/-0)
lib/lp/archiveuploader/uploadpolicy.py (+10/-13)
lib/lp/soyuz/browser/archive.py (+10/-7)
lib/lp/soyuz/browser/tests/archive-views.txt (+19/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/deal-with-no-authorized_size
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+124097@code.launchpad.net

Commit message

Correctly deal with Archives that have a NULL authorized_size during policySpecificChecks, and now check all archives for quota.

Description of the change

Correctly deal with Archives that have a NULL authorized_size during policySpecificChecks for PPA uploads and on Archive:+repository_size. Also check every archive for quota now that we do handle NULL authorized_size correctly.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archiveuploader/tests/test_ppauploadprocessor.py'
2--- lib/lp/archiveuploader/tests/test_ppauploadprocessor.py 2012-06-26 16:50:00 +0000
3+++ lib/lp/archiveuploader/tests/test_ppauploadprocessor.py 2012-09-13 05:02:21 +0000
4@@ -1250,6 +1250,17 @@
5 "if you need more space."]
6 self.assertEmail(contents)
7
8+ def testPPASizeNoQuota(self):
9+ self.name16.archive.authorized_size = None
10+ upload_dir = self.queueUpload("bar_1.0-1", "~name16/ubuntu")
11+ self.processUpload(self.uploadprocessor, upload_dir)
12+ contents = [
13+ "Subject: [PPA name16] [ubuntu/breezy] bar 1.0-1 (Accepted)"]
14+ self.assertEmail(contents)
15+ self.assertEqual(
16+ self.uploadprocessor.last_processed_upload.queue_root.status,
17+ PackageUploadStatus.DONE)
18+
19 def testPPASizeQuotaSourceWarning(self):
20 """Verify the size quota warning for PPA near size limit.
21
22
23=== modified file 'lib/lp/archiveuploader/uploadpolicy.py'
24--- lib/lp/archiveuploader/uploadpolicy.py 2012-08-22 17:06:08 +0000
25+++ lib/lp/archiveuploader/uploadpolicy.py 2012-09-13 05:02:21 +0000
26@@ -212,8 +212,8 @@
27 size quota.Binary upload will be skipped to avoid unnecessary hassle
28 dealing with FAILEDTOUPLOAD builds.
29 """
30- # Skip the check for binary uploads.
31- if upload.binaryful:
32+ # Skip the check for binary uploads or archives with no quota.
33+ if upload.binaryful or self.archive.authorized_size is None:
34 return
35
36 # Calculate the incoming upload total size.
37@@ -247,18 +247,15 @@
38 def policySpecificChecks(self, upload):
39 """The insecure policy does not allow SECURITY uploads for now.
40
41- If the upload is targeted to any PPA, checks if the upload is within
42- the allowed quota.
43+ Also check if the upload is within the allowed quota.
44 """
45- if upload.is_ppa:
46- self.checkArchiveSizeQuota(upload)
47- else:
48- # XXX cjwatson 2012-07-20 bug=1026665: For now, direct uploads
49- # to SECURITY will not be built. See
50- # BuildPackageJob.postprocessCandidate.
51- if self.pocket == PackagePublishingPocket.SECURITY:
52- upload.reject(
53- "This upload queue does not permit SECURITY uploads.")
54+ self.checkArchiveSizeQuota(upload)
55+ # XXX cjwatson 2012-07-20 bug=1026665: For now, direct uploads
56+ # to SECURITY will not be built. See
57+ # BuildPackageJob.postprocessCandidate.
58+ if self.pocket == PackagePublishingPocket.SECURITY:
59+ upload.reject(
60+ "This upload queue does not permit SECURITY uploads.")
61
62 def autoApprove(self, upload):
63 """The insecure policy auto-approves RELEASE/PROPOSED pocket stuff.
64
65=== modified file 'lib/lp/soyuz/browser/archive.py'
66--- lib/lp/soyuz/browser/archive.py 2012-08-19 00:32:32 +0000
67+++ lib/lp/soyuz/browser/archive.py 2012-09-13 05:02:21 +0000
68@@ -633,14 +633,17 @@
69 binary_label = '%s binary %s' % (
70 number_of_binaries, package_plural(number_of_binaries))
71
72- # Quota is stored in MiB, convert it to bytes.
73- quota = self.context.authorized_size * (2 ** 20)
74 used = self.context.estimated_size
75-
76- # Calculate the usage factor and limit it to 100%.
77- used_factor = (float(used) / quota)
78- if used_factor > 1:
79- used_factor = 1
80+ if self.context.authorized_size:
81+ # Quota is stored in MiB, convert it to bytes.
82+ quota = self.context.authorized_size * (2 ** 20)
83+ # Calculate the usage factor and limit it to 100%.
84+ used_factor = (float(used) / quota)
85+ if used_factor > 1:
86+ used_factor = 1
87+ else:
88+ quota = 0
89+ used_factor = 0
90
91 # Calculate the appropriate CSS class to be used with the usage
92 # factor. Highlight it (in red) if usage is over 90% of the quota.
93
94=== modified file 'lib/lp/soyuz/browser/tests/archive-views.txt'
95--- lib/lp/soyuz/browser/tests/archive-views.txt 2012-08-17 10:37:13 +0000
96+++ lib/lp/soyuz/browser/tests/archive-views.txt 2012-09-13 05:02:21 +0000
97@@ -172,6 +172,25 @@
98 used_css_class: green
99 used_percentage: 0.92
100
101+The authorized_size of a PPA can also be None (IE: no limit.)
102+
103+ >>> login('foo.bar@canonical.com')
104+ >>> mark.archive.authorized_size = None
105+ >>> login(ANONYMOUS)
106+
107+ >>> mark_archive_view = create_initialized_view(
108+ ... mark.archive, name="+index")
109+ >>> mark_repository_usage = mark_archive_view.repository_usage
110+ >>> print_repository_usage(mark_repository_usage)
111+ binaries_size: 0
112+ binary_label: 1 binary package
113+ quota: 0
114+ source_label: 1 source package
115+ sources_size: 9922683
116+ used: 9924731
117+ used_css_class: green
118+ used_percentage: 0.00
119+
120 An ArchiveView provides a batched_sources property that can be used
121 to get the current batch of publishing records for an archive:
122