Merge lp:~linaro-infrastructure/linaro-ci-dashboard/create_job_jenkins_changes into lp:linaro-ci-dashboard

Proposed by Deepti B. Kalakeri
Status: Merged
Approved by: Stevan Radaković
Approved revision: 16
Merged at revision: 13
Proposed branch: lp:~linaro-infrastructure/linaro-ci-dashboard/create_job_jenkins_changes
Merge into: lp:linaro-ci-dashboard
Diff against target: 181 lines (+111/-3)
6 files modified
config_template/sample-job/config.xml (+22/-0)
dashboard/frontend/fixtures/initial_data.json (+9/-0)
dashboard/frontend/models/loop.py (+2/-1)
dashboard/jenkinsserver/models/jenkins_server.py (+48/-2)
dashboard/jenkinsserver/tests/test_jenkins_server.py (+27/-0)
dashboard/settings.py (+3/-0)
To merge this branch: bzr merge lp:~linaro-infrastructure/linaro-ci-dashboard/create_job_jenkins_changes
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Данило Шеган Pending
Review via email: mp+115802@code.launchpad.net

Description of the change

Adding changes to create /delete job on jenkins server

To post a comment you must log in.
15. By Deepti B. Kalakeri

Fix to check if the values are Null

Revision history for this message
Stevan Radaković (stevanr) wrote :

Hey Deepti, thanks for the good work..
Comments following:

initial_data.json is missing the jenkinsserver record as we talked. It is in my branch as well so you can leave it as it is, but someone else trying to run the application will be confused.

Also, create job method breaks when the name of the method has 'whitespace' in it. It creates job on jenkins, but only with the first string. I guess some escaping needs to be done here.

Basically we can't consider this done until we have a build actually working on the jenkins when it is scheduled to run. The following problems and possible solutions follow:
1. I also get a 'permission denied(public key)' on the job build when it tries to 'branch' the code from LP.
I've tried it an putting HOME=/tmp/ bzr branch... worked.
2. Also after the code is checked out, the script needs to position itself in the directory which is checkout.
i.e. cd branch_dir
3. We need to clean up the branch_dir either before the build or after (i think it's better before)

Let's get these few problems resolved then we can take a look at the code implementation.

review: Needs Fixing (code)
Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

> Hey Deepti, thanks for the good work..
> Comments following:
>
> initial_data.json is missing the jenkinsserver record as we talked. It is in
> my branch as well so you can leave it as it is, but someone else trying to run
> the application will be confused.

Yes, I did not wanted to overlap your changes, so did not make it part of the MP.
>
> Also, create job method breaks when the name of the method has 'whitespace' in
> it. It creates job on jenkins, but only with the first string. I guess some
> escaping needs to be done here.

I will fix this.
>
> Basically we can't consider this done until we have a build actually working
> on the jenkins when it is scheduled to run. The following problems and
> possible solutions follow:
> 1. I also get a 'permission denied(public key)' on the job build when it tries
> to 'branch' the code from LP.
I was able to get the jobs started to build once I Clicked on the Build button.
I did not see this error though. How does your input in the loopcreate form looks like?

> I've tried it an putting HOME=/tmp/ bzr branch... worked.

> 2. Also after the code is checked out, the script needs to position itself in
> the directory which is checkout.

Yes, correct, so my form inputs looks like this:
Name: Job_name
branch: linaro-ci-dashboard
precommand: cd linaro-ci-dashboard; make syncdb
command: make test

> i.e. cd branch_dir
> 3. We need to clean up the branch_dir either before the build or after (i
> think it's better before)
We can make it part of the command.
>
> Let's get these few problems resolved then we can take a look at the code
> implementation.

Revision history for this message
Stevan Radaković (stevanr) wrote :

> > Hey Deepti, thanks for the good work..
> > Comments following:
> >
> > initial_data.json is missing the jenkinsserver record as we talked. It is in
> > my branch as well so you can leave it as it is, but someone else trying to
> run
> > the application will be confused.
>
> Yes, I did not wanted to overlap your changes, so did not make it part of the
> MP.
> >
> > Also, create job method breaks when the name of the method has 'whitespace'
> in
> > it. It creates job on jenkins, but only with the first string. I guess some
> > escaping needs to be done here.
>
> I will fix this.
> >
> > Basically we can't consider this done until we have a build actually working
> > on the jenkins when it is scheduled to run. The following problems and
> > possible solutions follow:
> > 1. I also get a 'permission denied(public key)' on the job build when it
> tries
> > to 'branch' the code from LP.
> I was able to get the jobs started to build once I Clicked on the Build
> button.
> I did not see this error though. How does your input in the loopcreate form
> looks like?
>
>
> > I've tried it an putting HOME=/tmp/ bzr branch... worked.
>
> > 2. Also after the code is checked out, the script needs to position itself
> in
> > the directory which is checkout.
>
> Yes, correct, so my form inputs looks like this:
> Name: Job_name
> branch: linaro-ci-dashboard
> precommand: cd linaro-ci-dashboard; make syncdb
> command: make test
>

We don't want user to think about these things. If we can do it easy (and we can), why shouldn't we. Furthermore we can use some different directory name to check out to (it does not to be same as branch name).
We dont want to end up writing scripts in our command or precommand field.
Same goes for 1. and 3.
We need to add the environment prefix in 1. from code, but what I gave is just an example, it should be some /tmp/tmp_dir/ from i.e. gettempdir() in python.

>
> > i.e. cd branch_dir
> > 3. We need to clean up the branch_dir either before the build or after (i
> > think it's better before)
> We can make it part of the command.
> >
> > Let's get these few problems resolved then we can take a look at the code
> > implementation.

16. By Deepti B. Kalakeri

Addressing the review comments

Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

Changes are already submitted with the changes.

Revision history for this message
Stevan Radaković (stevanr) wrote :

Thanks for addressing the review comments.
Looks good now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'config_template/sample-job'
=== added file 'config_template/sample-job/config.xml'
--- config_template/sample-job/config.xml 1970-01-01 00:00:00 +0000
+++ config_template/sample-job/config.xml 2012-07-20 15:53:17 +0000
@@ -0,0 +1,22 @@
1<?xml version='1.0' encoding='UTF-8'?>
2<project>
3 <actions/>
4 <description></description>
5 <keepDependencies>false</keepDependencies>
6 <properties/>
7 <scm class="hudson.scm.NullSCM"/>
8 <canRoam>true</canRoam>
9 <disabled>false</disabled>
10 <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
11 <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
12 <triggers class="vector"/>
13 <concurrentBuild>false</concurrentBuild>
14 <builders>
15 <hudson.tasks.Shell>
16 <command> # Put your command here
17 </command>
18 </hudson.tasks.Shell>
19 </builders>
20 <publishers/>
21 <buildWrappers/>
22</project>
023
=== modified file 'dashboard/frontend/fixtures/initial_data.json'
--- dashboard/frontend/fixtures/initial_data.json 2012-07-16 11:14:43 +0000
+++ dashboard/frontend/fixtures/initial_data.json 2012-07-20 15:53:17 +0000
@@ -12,5 +12,14 @@
12 "fields": {12 "fields": {
13 "name": "linaro-infrastructure"13 "name": "linaro-infrastructure"
14 }14 }
15 },
16 {
17 "model": "jenkinsserver.JenkinsServer",
18 "pk": 1,
19 "fields": {
20 "url": "http://localhost:9090/jenkins",
21 "username": "admin",
22 "password": "admin"
23 }
15 }24 }
16]25]
17\ No newline at end of file26\ No newline at end of file
1827
=== modified file 'dashboard/frontend/models/loop.py'
--- dashboard/frontend/models/loop.py 2012-07-18 17:48:08 +0000
+++ dashboard/frontend/models/loop.py 2012-07-20 15:53:17 +0000
@@ -32,7 +32,8 @@
3232
33 def save(self, *args, **kwargs):33 def save(self, *args, **kwargs):
34 server = JenkinsServer.objects.get(id=1)34 server = JenkinsServer.objects.get(id=1)
35 server.add_integration_loop()35 self.server = server
36 server.add_integration_loop(self)
36 if (True):37 if (True):
37 super(Loop, self).save(*args, **kwargs)38 super(Loop, self).save(*args, **kwargs)
38 else:39 else:
3940
=== modified file 'dashboard/jenkinsserver/models/jenkins_server.py'
--- dashboard/jenkinsserver/models/jenkins_server.py 2012-07-19 08:00:53 +0000
+++ dashboard/jenkinsserver/models/jenkins_server.py 2012-07-20 15:53:17 +0000
@@ -17,6 +17,8 @@
17# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.17# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
1818
19from django.db import models19from django.db import models
20from django.conf import settings
21from xml.dom.minidom import parse, parseString
20import jenkins22import jenkins
2123
2224
@@ -42,8 +44,9 @@
42 loop.server = self44 loop.server = self
43 loop.save()45 loop.save()
4446
45 def add_integration_loop(self):47 def add_integration_loop(self, loop):
46 pass48 jxml = self.create_job_xml(loop)
49 self.create_job(loop.name, jxml)
4750
48 def sync_jobs(self):51 def sync_jobs(self):
49 """Sync jobs in dashboard DB with jobs in jenkins server.52 """Sync jobs in dashboard DB with jobs in jenkins server.
@@ -82,3 +85,46 @@
82 def unique_items(self, list_1, list_2):85 def unique_items(self, list_1, list_2):
83 """Return a list of items that are present in list_1 but not list_2."""86 """Return a list of items that are present in list_1 but not list_2."""
84 return [item for item in list_1 if item not in list_2]87 return [item for item in list_1 if item not in list_2]
88
89
90 def create_job(self, jname, jxml):
91 """ Creates a new job on jenkins if its not already present """
92 jname = jname.replace(' ', '%20').strip()
93 if not self.jenkins.job_exists(jname):
94 self.jenkins.create_job(jname, jxml)
95 self.jenkins.enable_job(jname)
96
97 def delete_job(self, jname):
98 """ Deleted a job on jenkins if present """
99 if self.jenkins.job_exists(jname):
100 self.jenkins.delete_job(jname)
101
102 def create_job_xml(self, loop):
103 """ Prepares the config.xml to be used for new job"""
104
105 dest_dir = 'dest_dir'
106 if not 'lp:' in loop.branch:
107 jbranch = 'bzr branch lp:%s %s '% (loop.branch, dest_dir)
108 else:
109 jbranch = 'bzr branch %s %s '% (loop.branch, dest_dir)
110
111 jcommands =''
112 rm_old_dest = 'rm -rf %s' % dest_dir
113 dest_command = 'cur_dir=$WORKSPACE; cd ./%s' % dest_dir
114 for command in [rm_old_dest, jbranch, dest_command, loop.precommand, \
115 loop.command]:
116 if command:
117 jcommands = '\n'.join([jcommands, command])
118
119 dest_command = "cd \"$cur_dir\""
120 jcommands = '\n'.join([jcommands, dest_command])
121
122 file = open(settings.JENKINS_JOB_CONFIG)
123 jdata = file.read()
124 file.close()
125
126 doc = parseString(jdata)
127 node = doc.getElementsByTagName('command')
128 node[0].firstChild.nodeValue = jcommands
129 jxml = doc.toprettyxml()
130 return jxml
85131
=== modified file 'dashboard/jenkinsserver/tests/test_jenkins_server.py'
--- dashboard/jenkinsserver/tests/test_jenkins_server.py 2012-07-19 10:44:27 +0000
+++ dashboard/jenkinsserver/tests/test_jenkins_server.py 2012-07-20 15:53:17 +0000
@@ -98,3 +98,30 @@
98 loops = [loop.name.encode("utf8") for loop in98 loops = [loop.name.encode("utf8") for loop in
99 self.server.loop_set.all()]99 self.server.loop_set.all()]
100 self.assertNotIn(self.test_job_name, loops)100 self.assertNotIn(self.test_job_name, loops)
101
102 def test_create_job_xml(self):
103 loop = Loop()
104 loop.name = 'sample-test'
105 loop.server = self.server
106 loop.branch = 'linaro-ci-dashboard'
107 loop.precommand = 'cd %s' % loop.branch
108 loop.command = 'make syncdb; make test'
109 jbranch = 'bzr branch lp:%s' % loop.branch
110 jcommands = '\n'.join([jbranch, loop.precommand, loop.command])
111 jxml = self.server.create_job_xml(loop)
112 self.assertIn(jcommands, jxml)
113
114 def test_create_new_job_delete_job(self):
115 loop = Loop()
116 loop.name = 'sample-test'
117 loop.server = self.server
118 loop.branch = 'linaro-ci-dashboard'
119 loop.precommand = 'cd %s' % loop.branch
120 loop.command = 'make syncdb; make test'
121 jbranch = 'bzr branch lp:%s' % loop.branch
122 jcommands = '\n'.join([jbranch, loop.precommand, loop.command])
123 jxml = self.server.create_job_xml(loop)
124 self.server.create_job(loop.name, jxml)
125 self.assertTrue(self.test_jenkins.job_exists(loop.name) == True)
126 self.server.delete_job(loop.name)
127 self.assertTrue(self.test_jenkins.job_exists(loop.name) == False)
101128
=== modified file 'dashboard/settings.py'
--- dashboard/settings.py 2012-07-19 10:44:27 +0000
+++ dashboard/settings.py 2012-07-20 15:53:17 +0000
@@ -188,5 +188,8 @@
188JENKINS_USER_CONFIG = os.path.join(ROOT_PATH,188JENKINS_USER_CONFIG = os.path.join(ROOT_PATH,
189 '../config_template/users/',189 '../config_template/users/',
190 'config.xml')190 'config.xml')
191JENKINS_JOB_CONFIG = os.path.join(ROOT_PATH,
192 '../config_template/sample-job/',
193 'config.xml')
191JENKINS_HOME = os.path.join(os.getenv('HOME'), ".jenkins_test")194JENKINS_HOME = os.path.join(os.getenv('HOME'), ".jenkins_test")
192JENKINS_LOG_NAME = 'jenkins.log'195JENKINS_LOG_NAME = 'jenkins.log'

Subscribers

People subscribed via source and target branches

to all changes: