Merge lp:~psivaa/charms/trusty/jenkaas/example-job into lp:~canonical-ci-engineering/charms/trusty/jenkaas/trunk

Proposed by Para Siva
Status: Merged
Approved by: Para Siva
Approved revision: 17
Merged at revision: 7
Proposed branch: lp:~psivaa/charms/trusty/jenkaas/example-job
Merge into: lp:~canonical-ci-engineering/charms/trusty/jenkaas/trunk
Diff against target: 162 lines (+84/-29)
4 files modified
files/templates/example_job/config.xml (+40/-0)
hooks/actions.py (+37/-1)
hooks/services.py (+7/-8)
templates/upstart.conf (+0/-20)
To merge this branch: bzr merge lp:~psivaa/charms/trusty/jenkaas/example-job
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Evan (community) Needs Information
Joe Talbott (community) Approve
Review via email: mp+262129@code.launchpad.net

Commit message

Create an example job from a simple template. Using start and stop helpers.

Description of the change

Create an example job from a simple template. This can now be deployed. There are races as to when it's actually possible to create the example job, pragmatically.

I'm not sure if risking this race for an example job creation, which does not imho add a lot of values.

http://162.213.33.201:8080/job/example_job/

is the job that was created using this MP

To post a comment you must log in.
12. By Para Siva

Use service stop start for example job creation

13. By Para Siva

Rename template

Revision history for this message
Joe Talbott (joetalbott) wrote :

This looks good to me.

review: Approve
Revision history for this message
Francis Ginther (fginther) wrote :

A couple of comments on the jenkins service stop and start when updating the job templates. I think you've already discussed doing this differently in IRC.

review: Needs Fixing
14. By Para Siva

Block jenkins service starting whilst deb installations via policy-rc.d

Revision history for this message
Para Siva (psivaa) wrote :

Thanks for the reviews. Rev 14 is now using policy-rc.d to stop jenkins from starting. Could you please re-review?

Revision history for this message
Evan (ev) :
review: Needs Fixing
Revision history for this message
Francis Ginther (fginther) wrote :

Looks good. I would change the missing "#!/bin/sh" though. I agree it isn't strictly necessary, but it will more then likely lead to confusion if it's not there.

review: Approve
15. By Para Siva

Add shebang to the polic-rc.d

Revision history for this message
Para Siva (psivaa) wrote :

"#!/bin/sh" is now added to the policy-rc.d. Thanks for the reviews.

Revision history for this message
Francis Ginther (fginther) wrote :

Approve

review: Approve
Revision history for this message
Joe Talbott (joetalbott) wrote :

LGTM

review: Approve
Revision history for this message
Evan (ev) wrote :

Mostly looks good, but I don't understand the point of the upstart job.

review: Needs Information
16. By Para Siva

Remove upstart job and use service_start to start jenkins

17. By Para Siva

Remove empty folder

Revision history for this message
Para Siva (psivaa) wrote :

Thanks. The upstart job was to follow the 'pattern' of the other charms that we were using. Now removed it and using service start.

Revision history for this message
Francis Ginther (fginther) wrote :

Siva, I'm all for merging this now. The removal of the upstart job and service_start() look good.

review: Approve
Revision history for this message
Para Siva (psivaa) wrote :

Thanks Francis. I'll go ahead and merge it. If Evan has further comments, i'll address them in another MP.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'files/templates/example_job'
=== added file 'files/templates/example_job/config.xml'
--- files/templates/example_job/config.xml 1970-01-01 00:00:00 +0000
+++ files/templates/example_job/config.xml 2015-06-22 17:01:19 +0000
@@ -0,0 +1,40 @@
1<?xml version='1.0' encoding='UTF-8'?>
2<project>
3 <actions/>
4 <description>This is the example job.</description>
5 <keepDependencies>false</keepDependencies>
6 <properties>
7 <hudson.queueSorter.PrioritySorterJobProperty>
8 <priority>100</priority>
9 </hudson.queueSorter.PrioritySorterJobProperty>
10 <hudson.plugins.throttleconcurrents.ThrottleJobProperty>
11 <maxConcurrentPerNode>0</maxConcurrentPerNode>
12 <maxConcurrentTotal>0</maxConcurrentTotal>
13 <throttleEnabled>false</throttleEnabled>
14 <throttleOption>project</throttleOption>
15 </hudson.plugins.throttleconcurrents.ThrottleJobProperty>
16 </properties>
17 <scm class="hudson.scm.NullSCM"/>
18 <assignedNode>master</assignedNode>
19 <canRoam>false</canRoam>
20 <disabled>false</disabled>
21 <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
22 <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
23 <triggers class="vector"/>
24 <concurrentBuild>false</concurrentBuild>
25 <builders>
26 <hudson.tasks.Shell>
27 <command>echo &quot;This is an example job&quot;
28echo &quot;Please add your logic here&quot;
29touch result.xml
30 </command>
31 </hudson.tasks.Shell>
32 </builders>
33 <publishers>
34 <hudson.tasks.ArtifactArchiver>
35 <artifacts>**/*</artifacts>
36 <latestOnly>false</latestOnly>
37 </hudson.tasks.ArtifactArchiver>
38 </publishers>
39 <buildWrappers/>
40</project>
041
=== modified file 'hooks/actions.py'
--- hooks/actions.py 2015-06-19 02:59:34 +0000
+++ hooks/actions.py 2015-06-22 17:01:19 +0000
@@ -12,7 +12,10 @@
1212
13SERVICE_NAME = 'jenkaas'13SERVICE_NAME = 'jenkaas'
14SERVICE_CONFIGNAME = 'jenkaas.conf'14SERVICE_CONFIGNAME = 'jenkaas.conf'
15DEPS_PKGES = ["daemon", "adduser", "psmisc", "default-jre", "pwgen"]15DEPS_PKGES = [
16 "daemon", "adduser", "psmisc", "default-jre",
17 "pwgen",
18 ]
1619
17config = hookenv.config()20config = hookenv.config()
1821
@@ -93,3 +96,36 @@
93def install_slaves(service_name):96def install_slaves(service_name):
94 hookenv.log('Installing slaves')97 hookenv.log('Installing slaves')
95 hookenv.log(hookenv.relations())98 hookenv.log(hookenv.relations())
99
100
101def block_jenkins_start(service_name):
102 hookenv.log('Blocking jenkins from starting')
103 policy_file = '/usr/sbin/policy-rc.d'
104 with open(policy_file, 'w') as pol_file:
105 pol_file.write('#!/bin/sh\nexit 101')
106 os.chmod(policy_file, 0o755)
107
108
109def unblock_jenkins_start(service_name):
110 hookenv.log('Unblocking jenkins from starting')
111 policy_file = '/usr/sbin/policy-rc.d'
112 if os.path.exists(policy_file):
113 os.remove(policy_file)
114
115
116def create_example_job(service_name):
117 example_job_dir = os.path.join(_service_dir(), 'jobs/example_job')
118 example_job_template = os.path.join(example_job_dir, 'config.xml')
119 if os.path.exists(example_job_template):
120 hookenv.log('Example job already exists')
121 return
122 template = os.path.join(hookenv.charm_dir(),
123 'files/templates/example_job/config.xml')
124 if not os.path.exists(example_job_dir):
125 host.mkdir(example_job_dir, 'jenkins', 'jenkins', 0o755)
126
127 shutil.copy(template, example_job_dir)
128
129
130def start_jenkins(service_name):
131 host.service_start('jenkins')
96132
=== modified file 'hooks/services.py'
--- hooks/services.py 2015-06-19 02:59:34 +0000
+++ hooks/services.py 2015-06-22 17:01:19 +0000
@@ -1,9 +1,7 @@
1from charmhelpers.core import hookenv1from charmhelpers.core import hookenv
2from charmhelpers.core.services.base import ServiceManager2from charmhelpers.core.services.base import ServiceManager
3from charmhelpers.core.services.helpers import (3from charmhelpers.core.services.helpers import RelationContext
4 RelationContext,4
5 render_template,
6)
75
8import actions6import actions
97
@@ -32,16 +30,17 @@
32 'data_ready': [30 'data_ready': [
33 actions.basenode,31 actions.basenode,
34 actions.install_jenkins_dep_pkges,32 actions.install_jenkins_dep_pkges,
33 actions.block_jenkins_start,
35 actions.install_jenkins,34 actions.install_jenkins,
35 actions.unblock_jenkins_start,
36 actions.install_plugins,
37 actions.create_example_job,
36 actions.install_jenkins_config,38 actions.install_jenkins_config,
37 actions.install_plugins,
38 actions.configure_default_user,39 actions.configure_default_user,
39 render_template(
40 source='upstart.conf',
41 target='/etc/init/jenkaas.conf'),
42 actions.install_slaves,40 actions.install_slaves,
43 actions.log_start,41 actions.log_start,
44 ],42 ],
43 'start': actions.start_jenkins,
45 'ports': [8080],44 'ports': [8080],
46 },45 },
47 ])46 ])
4847
=== removed directory 'templates'
=== removed file 'templates/upstart.conf'
--- templates/upstart.conf 2015-06-11 18:26:32 +0000
+++ templates/upstart.conf 1970-01-01 00:00:00 +0000
@@ -1,20 +0,0 @@
1description "Starts a jenkaas process"
2
3start on (local-filesystems and net-device-up IFACE=eth0)
4stop on runlevel [!12345]
5
6# use sigint so python code just needs to catch KeyboardInterrupt
7kill signal SIGINT
8
9# If the process quits unexpectedly trigger respawn it
10respawn
11# unless it fails 15 times within 5 seconds
12respawn limit 15 5
13
14env SERVICE_USER=admin
15
16script
17
18 exec sudo -u ${SERVICE_USER} sh -c "service jenkins start || true >> logs/jenkaas.log 2>&1"
19
20end script

Subscribers

People subscribed via source and target branches