Merge lp:~pfalcon/linaro-android-frontend/reset-retention-for-official into lp:linaro-android-frontend

Proposed by Paul Sokolovsky
Status: Merged
Approved by: James Westby
Approved revision: 232
Merged at revision: 232
Proposed branch: lp:~pfalcon/linaro-android-frontend/reset-retention-for-official
Merge into: lp:linaro-android-frontend
Diff against target: 149 lines (+98/-2)
5 files modified
android_build/frontend/api.py (+18/-2)
android_build/tests/README (+3/-0)
android_build/tests/data/discard_builds_config.diff (+15/-0)
android_build/tests/data/discard_builds_config.xml (+46/-0)
android_build/tests/test_api.py (+16/-0)
To merge this branch: bzr merge lp:~pfalcon/linaro-android-frontend/reset-retention-for-official
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Michael Hudson-Doyle Pending
Alexander Sack Pending
Review via email: mp+72585@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

I'd appreciate a comment in the resetRetentionSettings about what
it's actually doing, as it's not particularly clear why deleting an
element named "logRotator" means that builds aren't deleted.

32 + "You are not allowed to create official build", status=403)

That should be "You are not allowed to create an official build."

Thanks,

James

review: Approve
Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

Fixed both.

233. By Paul Sokolovsky

Grammar fix.

234. By Paul Sokolovsky

resetRetentionSettings(): Add comment.

Revision history for this message
James Westby (james-w) wrote :

Looks great.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'android_build/frontend/api.py'
2--- android_build/frontend/api.py 2011-07-02 09:22:17 +0000
3+++ android_build/frontend/api.py 2011-08-24 07:48:26 +0000
4@@ -100,6 +100,19 @@
5 return etree.tostring(doc_root)
6
7
8+def resetRetentionSettings(configXml):
9+ "Reset retention setting for a job to 'infinite retention'."
10+ doc_root = etree.XML(configXml)
11+ # Remove <logRotator> element, which corresponds to UI
12+ # setting "Discard Old Builds".
13+ try:
14+ node = doc_root.xpath('//logRotator')[0]
15+ except IndexError:
16+ return configXml
17+ doc_root.remove(node)
18+ return etree.tostring(doc_root)
19+
20+
21 def postConfig(url, configXml):
22 try:
23 _authJenkins(url, configXml, {'Content-Type': 'text/xml'})
24@@ -170,10 +183,11 @@
25 @builder_required
26 def new(request):
27 try:
28- if request.POST.get('official', 'false') == 'true':
29+ is_official = request.POST.get('official', 'false') == 'true'
30+ if is_official:
31 if not is_official_builder(request):
32 return HttpResponse(
33- "You are not allowed to do that", status=403)
34+ "You are not allowed to create an official build", status=403)
35 ownerName = 'linaro-android'
36 else:
37 ownerName = request.user.username
38@@ -184,6 +198,8 @@
39 xml_base = getJobConfig(settings.TEMPLATE_JOB_NAME)
40 if isinstance(xml_base, HttpResponse):
41 return xml_base
42+ if is_official:
43+ xml_base = resetRetentionSettings(xml_base)
44 new_config = replaceConfigDefault(xml_base, request.POST['config'])
45 resp = postConfig('createItem?name=' + new_job_name, new_config)
46 if resp:
47
48=== added directory 'android_build/tests'
49=== added file 'android_build/tests/README'
50--- android_build/tests/README 1970-01-01 00:00:00 +0000
51+++ android_build/tests/README 2011-08-24 07:48:26 +0000
52@@ -0,0 +1,3 @@
53+To run tests, from top-level dir:
54+
55+DJANGO_SETTINGS_MODULE=android_build.settings nosetests android_build/tests/ -s
56
57=== added directory 'android_build/tests/data'
58=== added file 'android_build/tests/data/discard_builds_config.diff'
59--- android_build/tests/data/discard_builds_config.diff 1970-01-01 00:00:00 +0000
60+++ android_build/tests/data/discard_builds_config.diff 2011-08-24 07:48:26 +0000
61@@ -0,0 +1,15 @@
62+---
63++++
64+@@ -1,12 +1,6 @@
65+ <project>
66+ <actions/>
67+ <description/>
68+- <logRotator>
69+- <daysToKeep>30</daysToKeep>
70+- <numToKeep>10</numToKeep>
71+- <artifactDaysToKeep>-1</artifactDaysToKeep>
72+- <artifactNumToKeep>-1</artifactNumToKeep>
73+- </logRotator>
74+ <keepDependencies>false</keepDependencies>
75+ <properties>
76+ <hudson.model.ParametersDefinitionProperty>
77
78=== added file 'android_build/tests/data/discard_builds_config.xml'
79--- android_build/tests/data/discard_builds_config.xml 1970-01-01 00:00:00 +0000
80+++ android_build/tests/data/discard_builds_config.xml 2011-08-24 07:48:26 +0000
81@@ -0,0 +1,46 @@
82+<project>
83+ <actions/>
84+ <description/>
85+ <logRotator>
86+ <daysToKeep>30</daysToKeep>
87+ <numToKeep>10</numToKeep>
88+ <artifactDaysToKeep>-1</artifactDaysToKeep>
89+ <artifactNumToKeep>-1</artifactNumToKeep>
90+ </logRotator>
91+ <keepDependencies>false</keepDependencies>
92+ <properties>
93+ <hudson.model.ParametersDefinitionProperty>
94+ <parameterDefinitions>
95+ <hudson.model.StringParameterDefinition>
96+ <name>CONFIG</name>
97+ <description/>
98+ <defaultValue>TUFOSUZFU1RfUkVQTz1naXQ6Ly9odHRwOi8vYW5kcm9pZC5naXQua2VybmVsLm9yZy9wbGF0Zm9ybS9tYW5pZmVzdC5naXQKTUFOSUZFU1RfQlJBTkNIPW1hc3RlcgpUQVJHRVRfUFJPRFVDVD1mdWxsLWVuZw==</defaultValue>
99+ </hudson.model.StringParameterDefinition>
100+ </parameterDefinitions>
101+ </hudson.model.ParametersDefinitionProperty>
102+ </properties>
103+ <scm class="hudson.scm.NullSCM"/>
104+ <assignedNode>ec2</assignedNode>
105+ <canRoam>false</canRoam>
106+ <disabled>false</disabled>
107+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
108+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
109+ <triggers class="vector"/>
110+ <concurrentBuild>true</concurrentBuild>
111+ <builders>
112+ <hudson.tasks.Shell>
113+ <command>rm -rf build-tools
114+bzr get http://bazaar.launchpad.net/~linaro-infrastructure/linaro-android-build-tools/trunk build-tools
115+build-tools/node/build us-east-1.ec2-git-mirror.linaro.org "$CONFIG"
116+#build-tools/node/build "$HUDSON_URL" "$CONFIG"
117+</command>
118+ </hudson.tasks.Shell>
119+ </builders>
120+ <publishers>
121+ <hudson.tasks.ArtifactArchiver>
122+ <artifacts>build/out/target/*/*/*.img,build/out/target/*/*/*.tar.bz2,build/out/*.tar.bz2,build/out/*.xml,build/out/*.html</artifacts>
123+ <latestOnly>false</latestOnly>
124+ </hudson.tasks.ArtifactArchiver>
125+ </publishers>
126+ <buildWrappers/>
127+</project>
128\ No newline at end of file
129
130=== added file 'android_build/tests/test_api.py'
131--- android_build/tests/test_api.py 1970-01-01 00:00:00 +0000
132+++ android_build/tests/test_api.py 2011-08-24 07:48:26 +0000
133@@ -0,0 +1,16 @@
134+import os
135+import difflib
136+
137+from android_build.frontend import api
138+
139+datadir = os.path.dirname(__file__) + "/data"
140+
141+def assert_diff(text1, text2, diff_file):
142+ actual_diff = "".join(list(difflib.unified_diff(text1.splitlines(True), text2.splitlines(True))))
143+ expected_diff = open(diff_file).read()
144+ assert actual_diff == expected_diff
145+
146+def test_resetRetentionSettings():
147+ in_text = open(datadir + "/discard_builds_config.xml").read()
148+ out_text = api.resetRetentionSettings(in_text)
149+ assert_diff(in_text, out_text, datadir + "/discard_builds_config.diff")

Subscribers

People subscribed via source and target branches