Merge lp:~ce-infrastructure/capomastro/capomastro-jenkins-exposure-1155 into lp:capomastro

Proposed by Caio Begotti
Status: Merged
Approved by: Daniel Manrique
Approved revision: 154
Merged at revision: 141
Proposed branch: lp:~ce-infrastructure/capomastro/capomastro-jenkins-exposure-1155
Merge into: lp:capomastro
Diff against target: 218 lines (+75/-3)
10 files modified
capomastro/local_settings.py (+1/-2)
debian/changelog (+7/-0)
projects/templates/projects/dependency_detail.html (+1/-0)
projects/templates/projects/dependency_form.html (+1/-0)
projects/templates/projects/missing_archiver_alert.html (+4/-0)
projects/templates/projects/project_detail.html (+1/-0)
projects/templates/projects/project_form.html (+1/-0)
projects/templates/projects/projectbuild_detail.html (+1/-1)
projects/tests/test_views.py (+21/-0)
projects/views.py (+37/-0)
To merge this branch: bzr merge lp:~ce-infrastructure/capomastro/capomastro-jenkins-exposure-1155
Reviewer Review Type Date Requested Status
Sheila Miguez (community) Approve
Daniel Manrique (community) Approve
Review via email: mp+242412@code.launchpad.net

Description of the change

This is part of a task to story 1155 about investigating whether we need to expose Jenkins for real or not. If this merge is accepted I think it's fairly safe to commit and push directly the following change to the deploy branch of Capomastro, too:

=== modified file 'deploy.sh'
--- deploy.sh 2014-11-13 02:51:13 +0000
+++ deploy.sh 2014-11-19 21:52:22 +0000
@@ -43,5 +43,4 @@
 juju add-relation apache2:reverseproxy capomastro:website && sleep 30

 # Expose web services
-juju expose jenkins
 juju expose apache2

The tl;dr of these commits is: we don't need to overexpose Jenkins really, but some warning to the users about not having an archiver setup is good since the archiver is the one which would replace the Jenkins URLs so users can download artifacts.

To post a comment you must log in.
Revision history for this message
Caio Begotti (caio1982) :
Revision history for this message
Daniel Manrique (roadmr) wrote :

I made an inline comment, plus I notice there are no tests for this and I'm wondering if it's worth somehow testing it. Perhaps checking that the context has no "archive" value, then creating an Archive and checking again, this time that the context has the archive attribute.

I found a possibly related snippet in archives/tests/test_helpers.py, that may prove helpful.

It may also be possible to do a test where we actually verify that the rendered template has the warning string if there's no archive.

Apologies if this is vague, it's just showing my incomplete knowledge of django templates and testing :/

review: Needs Information
Revision history for this message
Sheila Miguez (codersquid) wrote :

I added a diff command about using "include" as an option.

Revision history for this message
Caio Begotti (caio1982) wrote :
Download full text (7.5 KiB)

Thanks for the Django tips, I didn't know how we could tests a template but
I'll take a look at it and use a small template just for this alert then.

On Thu, Nov 20, 2014 at 8:23 PM, Sheila Miguez <email address hidden>
wrote:

> I added a diff command about using "include" as an option.
>
> Diff comments:
>
> > === modified file 'capomastro/local_settings.py'
> > --- capomastro/local_settings.py 2014-11-03 19:06:32 +0000
> > +++ capomastro/local_settings.py 2014-11-20 20:20:15 +0000
> > @@ -1,6 +1,5 @@
> > # SECURITY WARNING: don't run with debug turned on in production!
> > -DEBUG = False
> > -
> > +DEBUG = True
> > TEMPLATE_DEBUG = True
> > ALLOWED_HOSTS = []
> >
> >
> > === modified file 'debian/changelog'
> > --- debian/changelog 2014-11-03 19:06:32 +0000
> > +++ debian/changelog 2014-11-20 20:20:15 +0000
> > @@ -1,3 +1,10 @@
> > +capomastro (20141120) trusty; urgency=high
> > +
> > + * Adds warning to avoid overexposing the Jenkins server.
> > + * Adds two testing scripts to use with LXC and Vagrant.
> > +
> > + -- Caio Begotti <email address hidden> Thu, 20 Nov 2014
> 10:41:23 -0200
> > +
> > capomastro (20141103) trusty; urgency=high
> >
> > * Partially fixes https://bugs.launchpad.net/capomastro/+bug/1388936
> >
> > === modified file 'projects/templates/projects/dependency_detail.html'
> > --- projects/templates/projects/dependency_detail.html 2014-07-18
> 12:07:38 +0000
> > +++ projects/templates/projects/dependency_detail.html 2014-11-20
> 20:20:15 +0000
> > @@ -11,6 +11,9 @@
> > <div class="container">
> > <div class="row">
> > <div>
> > + {% if not archiver %}
> > + {% bootstrap_alert "Could not find a default archiver in the
> configuration. <a href='/admin/archives/archive/'>Please set up one</a>,
> otherwise artifacts of this dependency will only be available through an
> exposed Jenkins server." alert_type='warning' %}
> > + {% endif %}
>
> One way to handle it is to use an include.
>
> {% include "archiver_alert.html" %}
>
> you can also pass objects to it in case you want to tweak the snippet, for
> example
>
> {% include "archiver_alert.html" with somevar="foobar"%}
>
> > <h2>{{ dependency.name }}</h2>
> > {% if dependency.get_build_parameters %}
> > <table class="table table-striped">
> >
> > === modified file 'projects/templates/projects/dependency_form.html'
> > --- projects/templates/projects/dependency_form.html 2014-06-02
> 10:55:15 +0000
> > +++ projects/templates/projects/dependency_form.html 2014-11-20
> 20:20:15 +0000
> > @@ -8,6 +8,9 @@
> > <div class="container">
> > <div class="row">
> > <div>
> > + {% if not archiver %}
> > + {% bootstrap_alert "Could not find a default archiver in the
> configuration. <a href='/admin/archives/archive/'>Please set up one</a>,
> otherwise artifacts of this dependency will only be available through an
> exposed Jenkins server." alert_type='warning' %}
> > + {% endif %}
> > <h2>Dependency</h2>
> > <form action="" method="post" class="form" id="dependency">
> > {% csrf_token %}
> >
> > === modified file 'projects/templates/projects/projec...

Read more...

150. By Caio Begotti

moving all these alerts to a specific template should have been done in the first place i guess

151. By Caio Begotti

dunno why django ignores the none value of get_default_archive when passing it to the template's context, thus here it's simply assertingequal to '' instead

152. By Caio Begotti

we better not mess with the form submission so it is now tested before the submit happens just in case we want/need to change the form tests later so there is no need to change the archiver ones too

153. By Caio Begotti

trailing space leftover

154. By Caio Begotti

yet another trailing space leftover

Revision history for this message
Caio Begotti (caio1982) wrote :

Hey, what do you guys think about it now? I figure that we should not (and are not) test visual elements in the views (i.e. the bootstrap alert) but simply checking if the context has the archiver available for the test is fair enough. I thought the contexts checks would be duplicated but that's how the other tests are doing it so no need to worry about it I think.

Revision history for this message
Caio Begotti (caio1982) :
Revision history for this message
Daniel Manrique (roadmr) wrote :

Looks good to me, the extracted template looks much neater, and thanks for adding the tests. I agree that for something this simple it's OK to just check the context for the archiver data, not validating the actual rendering since it's just a static chunk with no extra functionality.

review: Approve
Revision history for this message
Sheila Miguez (codersquid) wrote :

I haven't set up tests locally to see if I could help with understanding why the context is populated with archiver. I would have expected the test to blow up because of it not being a key.

if it shouldn't be there, I would assert that archiver is not in the keys. I am okay with committing this anyway even though the test is weird. None or '' is falsy and the template shouldn't barf.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'capomastro/local_settings.py'
--- capomastro/local_settings.py 2014-11-03 19:06:32 +0000
+++ capomastro/local_settings.py 2014-11-21 12:19:03 +0000
@@ -1,6 +1,5 @@
1# SECURITY WARNING: don't run with debug turned on in production!1# SECURITY WARNING: don't run with debug turned on in production!
2DEBUG = False2DEBUG = True
3
4TEMPLATE_DEBUG = True3TEMPLATE_DEBUG = True
5ALLOWED_HOSTS = []4ALLOWED_HOSTS = []
65
76
=== modified file 'debian/changelog'
--- debian/changelog 2014-11-03 19:06:32 +0000
+++ debian/changelog 2014-11-21 12:19:03 +0000
@@ -1,3 +1,10 @@
1capomastro (20141120) trusty; urgency=high
2
3 * Adds warning to avoid overexposing the Jenkins server.
4 * Adds two testing scripts to use with LXC and Vagrant.
5
6 -- Caio Begotti <caio.begotti@canonical.com> Thu, 20 Nov 2014 10:41:23 -0200
7
1capomastro (20141103) trusty; urgency=high8capomastro (20141103) trusty; urgency=high
29
3 * Partially fixes https://bugs.launchpad.net/capomastro/+bug/138893610 * Partially fixes https://bugs.launchpad.net/capomastro/+bug/1388936
411
=== modified file 'projects/templates/projects/dependency_detail.html'
--- projects/templates/projects/dependency_detail.html 2014-07-18 12:07:38 +0000
+++ projects/templates/projects/dependency_detail.html 2014-11-21 12:19:03 +0000
@@ -11,6 +11,7 @@
11<div class="container">11<div class="container">
12 <div class="row">12 <div class="row">
13 <div>13 <div>
14 {% include "projects/missing_archiver_alert.html" with archiver=archiver %}
14 <h2>{{ dependency.name }}</h2>15 <h2>{{ dependency.name }}</h2>
15 {% if dependency.get_build_parameters %}16 {% if dependency.get_build_parameters %}
16 <table class="table table-striped">17 <table class="table table-striped">
1718
=== modified file 'projects/templates/projects/dependency_form.html'
--- projects/templates/projects/dependency_form.html 2014-06-02 10:55:15 +0000
+++ projects/templates/projects/dependency_form.html 2014-11-21 12:19:03 +0000
@@ -8,6 +8,7 @@
8<div class="container">8<div class="container">
9 <div class="row">9 <div class="row">
10 <div>10 <div>
11 {% include "projects/missing_archiver_alert.html" with archiver=archiver %}
11 <h2>Dependency</h2>12 <h2>Dependency</h2>
12 <form action="" method="post" class="form" id="dependency">13 <form action="" method="post" class="form" id="dependency">
13 {% csrf_token %}14 {% csrf_token %}
1415
=== added file 'projects/templates/projects/missing_archiver_alert.html'
--- projects/templates/projects/missing_archiver_alert.html 1970-01-01 00:00:00 +0000
+++ projects/templates/projects/missing_archiver_alert.html 2014-11-21 12:19:03 +0000
@@ -0,0 +1,4 @@
1{% load bootstrap3 %}
2{% if not archiver %}
3{% bootstrap_alert "Could not find a default archiver in the configuration. <a href='/admin/archives/archive/'>Please set up one</a>, otherwise built artifacts will only be available through an exposed Jenkins server." alert_type='warning' %}
4{% endif %}
05
=== modified file 'projects/templates/projects/project_detail.html'
--- projects/templates/projects/project_detail.html 2014-07-25 11:37:42 +0000
+++ projects/templates/projects/project_detail.html 2014-11-21 12:19:03 +0000
@@ -8,6 +8,7 @@
8<div class="container">8<div class="container">
9 <div class="row">9 <div class="row">
10 <div>10 <div>
11 {% include "projects/missing_archiver_alert.html" with archiver=archiver %}
11 <h2>{{ project.name }}</h2>12 <h2>{{ project.name }}</h2>
12 </div>13 </div>
13 </div>14 </div>
1415
=== modified file 'projects/templates/projects/project_form.html'
--- projects/templates/projects/project_form.html 2014-03-20 16:17:58 +0000
+++ projects/templates/projects/project_form.html 2014-11-21 12:19:03 +0000
@@ -8,6 +8,7 @@
8<div class="container">8<div class="container">
9 <div class="row">9 <div class="row">
10 <div>10 <div>
11 {% include "projects/missing_archiver_alert.html" with archiver=archiver %}
11 <h2>Project</h2>12 <h2>Project</h2>
12 <form action="" method="post" class="form" id="project">13 <form action="" method="post" class="form" id="project">
13 {% csrf_token %}14 {% csrf_token %}
1415
=== modified file 'projects/templates/projects/projectbuild_detail.html'
--- projects/templates/projects/projectbuild_detail.html 2014-07-25 11:37:42 +0000
+++ projects/templates/projects/projectbuild_detail.html 2014-11-21 12:19:03 +0000
@@ -31,7 +31,7 @@
31 <td>{{ dependency.build.number }}</td>31 <td>{{ dependency.build.number }}</td>
32 <td>{{ dependency.dependency.name }}</td>32 <td>{{ dependency.dependency.name }}</td>
33 <td>{{ dependency.build.status }}</td>33 <td>{{ dependency.build.status }}</td>
34 <td><a href="{{ dependency.build.url }}">{{ dependency.build.phase }}</a></td>34 <td>{{ dependency.build.phase }}</td>
35 {% else %}35 {% else %}
36 <td colspan="4">Waiting for build of job {{ dependency.job }}</td>36 <td colspan="4">Waiting for build of job {{ dependency.job }}</td>
37 {% endif %}37 {% endif %}
3838
=== modified file 'projects/tests/test_views.py'
--- projects/tests/test_views.py 2014-07-25 14:58:58 +0000
+++ projects/tests/test_views.py 2014-11-21 12:19:03 +0000
@@ -54,6 +54,11 @@
54 self.assertEqual(project, response.context["project"])54 self.assertEqual(project, response.context["project"])
55 self.assertEqual([dependency], list(response.context["dependencies"]))55 self.assertEqual([dependency], list(response.context["dependencies"]))
5656
57 self.assertEqual('', response.context["archiver"])
58 archive = ArchiveFactory.create(policy="cdimage", default=True)
59 response = self.app.get(project_url, user="testing")
60 self.assertEqual(archive, response.context["archiver"])
61
57 self.assertEqual(62 self.assertEqual(
58 sorted(projectbuilds[1:], key=lambda x: x.build_id, reverse=True),63 sorted(projectbuilds[1:], key=lambda x: x.build_id, reverse=True),
59 list(response.context["projectbuilds"]))64 list(response.context["projectbuilds"]))
@@ -158,6 +163,12 @@
158 """163 """
159 project_url = reverse("project_create")164 project_url = reverse("project_create")
160 response = self.app.get(project_url, user="testing")165 response = self.app.get(project_url, user="testing")
166
167 self.assertEqual('', response.context["archiver"])
168 archive = ArchiveFactory.create(policy="cdimage", default=True)
169 response = self.app.get(project_url, user="testing")
170 self.assertEqual(archive, response.context["archiver"])
171
161 form = response.forms["project"]172 form = response.forms["project"]
162 self.assertTrue(173 self.assertTrue(
163 form["auto_track"].value, "auto_track not defaulting to True")174 form["auto_track"].value, "auto_track not defaulting to True")
@@ -367,6 +378,11 @@
367 project_url = reverse("dependency_create")378 project_url = reverse("dependency_create")
368 response = self.app.get(project_url, user="testing")379 response = self.app.get(project_url, user="testing")
369380
381 self.assertEqual('', response.context["archiver"])
382 archive = ArchiveFactory.create(policy="cdimage", default=True)
383 response = self.app.get(project_url, user="testing")
384 self.assertEqual(archive, response.context["archiver"])
385
370 form = response.forms["dependency"]386 form = response.forms["dependency"]
371 form["jobtype"].select(self.jobtype.pk)387 form["jobtype"].select(self.jobtype.pk)
372 form["server"].select(self.server.pk)388 form["server"].select(self.server.pk)
@@ -426,6 +442,11 @@
426 self.assertEqual([project], list(response.context["projects"]))442 self.assertEqual([project], list(response.context["projects"]))
427 self.assertNotContains(response, "Dependency currently building")443 self.assertNotContains(response, "Dependency currently building")
428444
445 self.assertEqual('', response.context["archiver"])
446 archive = ArchiveFactory.create(policy="cdimage", default=True)
447 response = self.app.get(url, user="testing")
448 self.assertEqual(archive, response.context["archiver"])
449
429 def test_dependency_detail_with_currently_building(self):450 def test_dependency_detail_with_currently_building(self):
430 """451 """
431 If the Dependency is currently building, we should get an info message452 If the Dependency is currently building, we should get an info message
432453
=== modified file 'projects/views.py'
--- projects/views.py 2014-07-25 14:58:58 +0000
+++ projects/views.py 2014-11-21 12:19:03 +0000
@@ -46,6 +46,19 @@
46 initial["auto_track"] = True46 initial["auto_track"] = True
47 return initial47 return initial
4848
49 def get_context_data(self, **kwargs):
50 """
51 Supplement the project view with an archive check
52 """
53 context = super(
54 ProjectCreateView, self).get_context_data(**kwargs)
55
56 archive = get_default_archive()
57 if archive:
58 context["archiver"] = archive
59
60 return context
61
4962
50class ProjectListView(LoginRequiredMixin, ListView):63class ProjectListView(LoginRequiredMixin, ListView):
5164
@@ -194,6 +207,11 @@
194 for artifact in current_projectbuild.get_current_artifacts():207 for artifact in current_projectbuild.get_current_artifacts():
195 items.append(self.item_from_artifact(artifact))208 items.append(self.item_from_artifact(artifact))
196 context["current_artifacts"] = items209 context["current_artifacts"] = items
210
211 archive = get_default_archive()
212 if archive:
213 context["archiver"] = archive
214
197 return context215 return context
198216
199 @staticmethod217 @staticmethod
@@ -237,6 +255,20 @@
237 url_args = {"pk": self.object.pk}255 url_args = {"pk": self.object.pk}
238 return reverse("dependency_detail", kwargs=url_args)256 return reverse("dependency_detail", kwargs=url_args)
239257
258 def get_context_data(self, **kwargs):
259 """
260 Supplement the dependency view with an archive check
261 """
262 context = super(
263 DependencyCreateView, self).get_context_data(**kwargs)
264
265 archive = get_default_archive()
266 if archive:
267 context["archiver"] = archive
268
269 return context
270
271
240272
241class DependencyListView(LoginRequiredMixin, ListView):273class DependencyListView(LoginRequiredMixin, ListView):
242274
@@ -285,6 +317,11 @@
285 messages.add_message(317 messages.add_message(
286 self.request, messages.INFO,318 self.request, messages.INFO,
287 "Dependency currently building")319 "Dependency currently building")
320
321 archive = get_default_archive()
322 if archive:
323 context["archiver"] = archive
324
288 return context325 return context
289326
290 def post(self, request, pk):327 def post(self, request, pk):

Subscribers

People subscribed via source and target branches