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
1=== added directory 'files/templates/example_job'
2=== added file 'files/templates/example_job/config.xml'
3--- files/templates/example_job/config.xml 1970-01-01 00:00:00 +0000
4+++ files/templates/example_job/config.xml 2015-06-22 17:01:19 +0000
5@@ -0,0 +1,40 @@
6+<?xml version='1.0' encoding='UTF-8'?>
7+<project>
8+ <actions/>
9+ <description>This is the example job.</description>
10+ <keepDependencies>false</keepDependencies>
11+ <properties>
12+ <hudson.queueSorter.PrioritySorterJobProperty>
13+ <priority>100</priority>
14+ </hudson.queueSorter.PrioritySorterJobProperty>
15+ <hudson.plugins.throttleconcurrents.ThrottleJobProperty>
16+ <maxConcurrentPerNode>0</maxConcurrentPerNode>
17+ <maxConcurrentTotal>0</maxConcurrentTotal>
18+ <throttleEnabled>false</throttleEnabled>
19+ <throttleOption>project</throttleOption>
20+ </hudson.plugins.throttleconcurrents.ThrottleJobProperty>
21+ </properties>
22+ <scm class="hudson.scm.NullSCM"/>
23+ <assignedNode>master</assignedNode>
24+ <canRoam>false</canRoam>
25+ <disabled>false</disabled>
26+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
27+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
28+ <triggers class="vector"/>
29+ <concurrentBuild>false</concurrentBuild>
30+ <builders>
31+ <hudson.tasks.Shell>
32+ <command>echo &quot;This is an example job&quot;
33+echo &quot;Please add your logic here&quot;
34+touch result.xml
35+ </command>
36+ </hudson.tasks.Shell>
37+ </builders>
38+ <publishers>
39+ <hudson.tasks.ArtifactArchiver>
40+ <artifacts>**/*</artifacts>
41+ <latestOnly>false</latestOnly>
42+ </hudson.tasks.ArtifactArchiver>
43+ </publishers>
44+ <buildWrappers/>
45+</project>
46
47=== modified file 'hooks/actions.py'
48--- hooks/actions.py 2015-06-19 02:59:34 +0000
49+++ hooks/actions.py 2015-06-22 17:01:19 +0000
50@@ -12,7 +12,10 @@
51
52 SERVICE_NAME = 'jenkaas'
53 SERVICE_CONFIGNAME = 'jenkaas.conf'
54-DEPS_PKGES = ["daemon", "adduser", "psmisc", "default-jre", "pwgen"]
55+DEPS_PKGES = [
56+ "daemon", "adduser", "psmisc", "default-jre",
57+ "pwgen",
58+ ]
59
60 config = hookenv.config()
61
62@@ -93,3 +96,36 @@
63 def install_slaves(service_name):
64 hookenv.log('Installing slaves')
65 hookenv.log(hookenv.relations())
66+
67+
68+def block_jenkins_start(service_name):
69+ hookenv.log('Blocking jenkins from starting')
70+ policy_file = '/usr/sbin/policy-rc.d'
71+ with open(policy_file, 'w') as pol_file:
72+ pol_file.write('#!/bin/sh\nexit 101')
73+ os.chmod(policy_file, 0o755)
74+
75+
76+def unblock_jenkins_start(service_name):
77+ hookenv.log('Unblocking jenkins from starting')
78+ policy_file = '/usr/sbin/policy-rc.d'
79+ if os.path.exists(policy_file):
80+ os.remove(policy_file)
81+
82+
83+def create_example_job(service_name):
84+ example_job_dir = os.path.join(_service_dir(), 'jobs/example_job')
85+ example_job_template = os.path.join(example_job_dir, 'config.xml')
86+ if os.path.exists(example_job_template):
87+ hookenv.log('Example job already exists')
88+ return
89+ template = os.path.join(hookenv.charm_dir(),
90+ 'files/templates/example_job/config.xml')
91+ if not os.path.exists(example_job_dir):
92+ host.mkdir(example_job_dir, 'jenkins', 'jenkins', 0o755)
93+
94+ shutil.copy(template, example_job_dir)
95+
96+
97+def start_jenkins(service_name):
98+ host.service_start('jenkins')
99
100=== modified file 'hooks/services.py'
101--- hooks/services.py 2015-06-19 02:59:34 +0000
102+++ hooks/services.py 2015-06-22 17:01:19 +0000
103@@ -1,9 +1,7 @@
104 from charmhelpers.core import hookenv
105 from charmhelpers.core.services.base import ServiceManager
106-from charmhelpers.core.services.helpers import (
107- RelationContext,
108- render_template,
109-)
110+from charmhelpers.core.services.helpers import RelationContext
111+
112
113 import actions
114
115@@ -32,16 +30,17 @@
116 'data_ready': [
117 actions.basenode,
118 actions.install_jenkins_dep_pkges,
119+ actions.block_jenkins_start,
120 actions.install_jenkins,
121+ actions.unblock_jenkins_start,
122+ actions.install_plugins,
123+ actions.create_example_job,
124 actions.install_jenkins_config,
125- actions.install_plugins,
126 actions.configure_default_user,
127- render_template(
128- source='upstart.conf',
129- target='/etc/init/jenkaas.conf'),
130 actions.install_slaves,
131 actions.log_start,
132 ],
133+ 'start': actions.start_jenkins,
134 'ports': [8080],
135 },
136 ])
137
138=== removed directory 'templates'
139=== removed file 'templates/upstart.conf'
140--- templates/upstart.conf 2015-06-11 18:26:32 +0000
141+++ templates/upstart.conf 1970-01-01 00:00:00 +0000
142@@ -1,20 +0,0 @@
143-description "Starts a jenkaas process"
144-
145-start on (local-filesystems and net-device-up IFACE=eth0)
146-stop on runlevel [!12345]
147-
148-# use sigint so python code just needs to catch KeyboardInterrupt
149-kill signal SIGINT
150-
151-# If the process quits unexpectedly trigger respawn it
152-respawn
153-# unless it fails 15 times within 5 seconds
154-respawn limit 15 5
155-
156-env SERVICE_USER=admin
157-
158-script
159-
160- exec sudo -u ${SERVICE_USER} sh -c "service jenkins start || true >> logs/jenkaas.log 2>&1"
161-
162-end script

Subscribers

People subscribed via source and target branches