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

Proposed by Deepti B. Kalakeri
Status: Merged
Approved by: Stevan Radaković
Approved revision: 17
Merged at revision: 10
Proposed branch: lp:~linaro-infrastructure/linaro-ci-dashboard/run_stop_jenkins_command
Merge into: lp:linaro-ci-dashboard
Diff against target: 468 lines (+395/-3)
6 files modified
README (+15/-1)
config_template/config.xml (+36/-0)
dashboard/frontend/management/commands/jenkins.py (+183/-0)
dashboard/frontend/tests/__init__.py (+2/-0)
dashboard/frontend/tests/test_custom_commands.py (+148/-0)
dashboard/settings.py (+11/-2)
To merge this branch: bzr merge lp:~linaro-infrastructure/linaro-ci-dashboard/run_stop_jenkins_command
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Данило Шеган Pending
Review via email: mp+115381@code.launchpad.net

Description of the change

Adding the custom command to start/stop the jenkins locally for development.
Please see the README for instruction on how to use the commands.

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

Adding code to handle the situation where jenkins is already running on the same port

14. By Deepti B. Kalakeri

some more changes for check where jenkins is already running on the same port

Revision history for this message
Stevan Radaković (stevanr) wrote :
Download full text (18.2 KiB)

One general comment. Code documentation is a bit scarce, it would be great to have method descriptions as py docs in the main code.

=== modified file 'README'
--- README 2012-07-11 10:20:55 +0000
+++ README 2012-07-18 08:37:18 +0000
@@ -14,7 +14,7 @@
   python-setuptools
   python-dev
   build-essential
-
+ openjdk-6-jre-headless

 Running the application
 -----------------------
@@ -22,6 +22,18 @@
   $ python dashboard/manage.py build # only for first time run
   $ python dashboard/manage.py runserver

+Other commands useful for development
+---------------------------------------
+To experiment with jenkins for development activities use the
+command below to run jenkins locally
+ $ python dashboard/manage.py runjenkins
+
+To stop the running jenkins use the command below:
+ $ python dashboard/manage.py stopjenkins <jenkins pid>
+
+PS: Please go through the settings.py JENKINS_* params to change
+jenkins related configurations
+

We basically want this to be part of the Makefile as well. This description is OK, but please add Jenkins run server as a target in make and set it to be mandatory for running tests, because our tests will be running on local Jenkins ran by this command. So we should run jenkins, run the tests, stop jenkins.

 Database migration with South
 -----------------------------
@@ -44,6 +56,8 @@

   python-mock

+ $ python dashboard/manager.py install_configure jenkins
+
 To run all tests:

   $ python dashboard/manage.py test

Let's also put this in the make file.. If it's necessary for run jenkins command then let's put it in 'dependencies' target or similar.

=== added directory 'config_template'
=== added file 'config_template/config.xml'
--- config_template/config.xml 1970-01-01 00:00:00 +0000
+++ config_template/config.xml 2012-07-18 08:37:18 +0000
@@ -0,0 +1,36 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<hudson>
+ <disabledAdministrativeMonitors/>
+ <numExecutors>2</numExecutors>
+ <mode>NORMAL</mode>
+ <useSecurity>true</useSecurity>
+ <authorizationStrategy class="hudson.security.LegacyAuthorizationStrategy"/>
+ <securityRealm class="hudson.security.LegacySecurityRealm"/>
+ <projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
+ <workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULLNAME}</workspaceDir>
+ <buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
+ <markupFormatter class="hudson.markup.RawHtmlMarkupFormatter">
+ <disableSyntaxHighlighting>false</disableSyntaxHighlighting>
+ </markupFormatter>
+ <jdks/>
+ <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
+ <myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
+ <clouds/>
+ <slaves/>
+ <quietPeriod>5</quietPeriod>
+ <scmCheckoutRetryCount>0</scmCheckoutRetryCount>
+ <views>
+ <hudson.model.AllView>
+ <owner class="hudson" reference="../../.."/>
+ <name>All</name>
+ <filterExecutors>false</filterExecutors>
+ <filterQueue>false</filterQueue>
+ <properties class="hudson.model.View$PropertyList"/>
+ </hudson.model.AllView>
+ </views>
+ <primaryView>All</primaryView>
+ <slaveAgentPort>0</slaveAgentPort>
+ <label></label>
+ <nodeProperties/...

review: Needs Fixing (code)
15. By Deepti B. Kalakeri

Merged the jenkins stop command to the same class as start.
Renamed the runjenkins command to jenkins and made changes to handle
commands like :
python manage.py jenkins start
python manage.py jenkins stop <pid>
Merged the tests into one class
Added/modified new tests to handle the changes made

16. By Deepti B. Kalakeri

README changes for jenkins

Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :
Download full text (19.4 KiB)

> One general comment. Code documentation is a bit scarce, it would be great to
> have method descriptions as py docs in the main code.
>
>
> === modified file 'README'
> --- README 2012-07-11 10:20:55 +0000
> +++ README 2012-07-18 08:37:18 +0000
> @@ -14,7 +14,7 @@
> python-setuptools
> python-dev
> build-essential
> -
> + openjdk-6-jre-headless
>
> Running the application
> -----------------------
> @@ -22,6 +22,18 @@
> $ python dashboard/manage.py build # only for first time run
> $ python dashboard/manage.py runserver
>
> +Other commands useful for development
> +---------------------------------------
> +To experiment with jenkins for development activities use the
> +command below to run jenkins locally
> + $ python dashboard/manage.py runjenkins
> +
> +To stop the running jenkins use the command below:
> + $ python dashboard/manage.py stopjenkins <jenkins pid>
> +
> +PS: Please go through the settings.py JENKINS_* params to change
> +jenkins related configurations
> +
>
>
>
> We basically want this to be part of the Makefile as well. This description is
> OK, but please add Jenkins run server as a target in make and set it to be
> mandatory for running tests, because our tests will be running on local
> Jenkins ran by this command. So we should run jenkins, run the tests, stop
> jenkins.
>
>

Well, we do not have Makefile yet in the branch and I dont want to redo your work.
So will add this once we have your changes in the branch.
> Database migration with South
> -----------------------------
> @@ -44,6 +56,8 @@
>
> python-mock
>
> + $ python dashboard/manager.py install_configure jenkins
> +
> To run all tests:
>
> $ python dashboard/manage.py test
>
>
> Let's also put this in the make file.. If it's necessary for run jenkins
> command then let's put it in 'dependencies' target or similar.
>
same as above. All the other changes are addressed
>
> === added directory 'config_template'
> === added file 'config_template/config.xml'
> --- config_template/config.xml 1970-01-01 00:00:00 +0000
> +++ config_template/config.xml 2012-07-18 08:37:18 +0000
> @@ -0,0 +1,36 @@
> +<?xml version='1.0' encoding='UTF-8'?>
> +<hudson>
> + <disabledAdministrativeMonitors/>
> + <numExecutors>2</numExecutors>
> + <mode>NORMAL</mode>
> + <useSecurity>true</useSecurity>
> + <authorizationStrategy
> class="hudson.security.LegacyAuthorizationStrategy"/>
> + <securityRealm class="hudson.security.LegacySecurityRealm"/>
> + <projectNamingStrategy
> class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
> + <workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULLNAME}</workspaceDir>
> + <buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
> + <markupFormatter class="hudson.markup.RawHtmlMarkupFormatter">
> + <disableSyntaxHighlighting>false</disableSyntaxHighlighting>
> + </markupFormatter>
> + <jdks/>
> + <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
> + <myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
> + <clouds/>
> + <slaves/>
> + <quietPeriod>5</quietPeriod>
> + <scmCheckoutRetryCount>0</scmCheckoutRetryCount>
> + <views>
> + <hudson.model.AllView>
...

17. By Stevan Radaković

Last minute change to use test JENKINS_HOME directory so existing jenkins instance is not jeopardised.

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

Thanks for the additional fixes Deepti.
Great work, once again.
Approve +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-07-11 10:20:55 +0000
3+++ README 2012-07-18 17:24:18 +0000
4@@ -14,7 +14,7 @@
5 python-setuptools
6 python-dev
7 build-essential
8-
9+ openjdk-6-jre-headless
10
11 Running the application
12 -----------------------
13@@ -22,6 +22,18 @@
14 $ python dashboard/manage.py build # only for first time run
15 $ python dashboard/manage.py runserver
16
17+Other commands useful for development
18+---------------------------------------
19+To experiment with jenkins for development activities use the
20+command below to run jenkins locally
21+ $ python dashboard/manage.py jenkins start
22+
23+To stop the running jenkins use the command below:
24+ $ python dashboard/manage.py jenkins stop <jenkins pid>
25+
26+PS: Please go through the settings.py JENKINS_* params to change
27+jenkins related configurations
28+
29
30 Database migration with South
31 -----------------------------
32@@ -44,6 +56,8 @@
33
34 python-mock
35
36+ $ python dashboard/manager.py install_configure jenkins
37+
38 To run all tests:
39
40 $ python dashboard/manage.py test
41
42=== added directory 'config_template'
43=== added file 'config_template/config.xml'
44--- config_template/config.xml 1970-01-01 00:00:00 +0000
45+++ config_template/config.xml 2012-07-18 17:24:18 +0000
46@@ -0,0 +1,36 @@
47+<?xml version='1.0' encoding='UTF-8'?>
48+<hudson>
49+ <disabledAdministrativeMonitors/>
50+ <numExecutors>2</numExecutors>
51+ <mode>NORMAL</mode>
52+ <useSecurity>true</useSecurity>
53+ <authorizationStrategy class="hudson.security.LegacyAuthorizationStrategy"/>
54+ <securityRealm class="hudson.security.LegacySecurityRealm"/>
55+ <projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
56+ <workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULLNAME}</workspaceDir>
57+ <buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
58+ <markupFormatter class="hudson.markup.RawHtmlMarkupFormatter">
59+ <disableSyntaxHighlighting>false</disableSyntaxHighlighting>
60+ </markupFormatter>
61+ <jdks/>
62+ <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
63+ <myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
64+ <clouds/>
65+ <slaves/>
66+ <quietPeriod>5</quietPeriod>
67+ <scmCheckoutRetryCount>0</scmCheckoutRetryCount>
68+ <views>
69+ <hudson.model.AllView>
70+ <owner class="hudson" reference="../../.."/>
71+ <name>All</name>
72+ <filterExecutors>false</filterExecutors>
73+ <filterQueue>false</filterQueue>
74+ <properties class="hudson.model.View$PropertyList"/>
75+ </hudson.model.AllView>
76+ </views>
77+ <primaryView>All</primaryView>
78+ <slaveAgentPort>0</slaveAgentPort>
79+ <label></label>
80+ <nodeProperties/>
81+ <globalNodeProperties/>
82+</hudson>
83
84=== added file 'dashboard/frontend/management/commands/jenkins.py'
85--- dashboard/frontend/management/commands/jenkins.py 1970-01-01 00:00:00 +0000
86+++ dashboard/frontend/management/commands/jenkins.py 2012-07-18 17:24:18 +0000
87@@ -0,0 +1,183 @@
88+# Copyright (C) 2012 Linaro
89+#
90+# This file is part of linaro-ci-dashboard.
91+#
92+# linaro-ci-dashboard is free software: you can redistribute it and/or modify
93+# it under the terms of the GNU Affero General Public License as published by
94+# the Free Software Foundation, either version 3 of the License, or
95+# (at your option) any later version.
96+#
97+# linaro-ci-dashboard is distributed in the hope that it will be useful,
98+# but WITHOUT ANY WARRANTY; without even the implied warranty of
99+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100+# GNU Affero General Public License for more details.
101+#
102+# You should have received a copy of the GNU Affero General Public License
103+# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
104+# Django settings for dashboard project.
105+
106+import os
107+import sys
108+import shutil
109+import urllib2
110+import urlparse
111+import shlex
112+from django.conf import settings
113+from django.core import management
114+from subprocess import check_output, CalledProcessError, Popen, STDOUT
115+from django.core.management.base import BaseCommand, CommandError
116+
117+class Command(BaseCommand):
118+ args = 'start or stop <pid>'
119+ help = 'Starts/Stops Jenkins service on machine.\n'\
120+ 'You need to specify pid of the jenkins process to stop'
121+
122+ def __init__(self):
123+ self.jenkins_war = None
124+ self.jenkins_pid = None
125+ self.port = settings.JENKINS_PORT
126+ self.jenkins_user = settings.JENKINS_ADMIN_USER
127+ self.jenkins_passwd = settings.JENKINS_ADMIN_PASSWD
128+ self.jenkins_home = settings.JENKINS_HOME
129+ self.jenkins_log = settings.JENKINS_LOG_NAME
130+ self.jenkins_war_url = settings.JENKKINS_WAR_URL
131+
132+
133+ def handle(self, *args, **options):
134+ try:
135+ if len(args) < 1:
136+ sys.stdout.write("Need to specify either start/stop\n")
137+ raise
138+
139+ if args[0] == 'start':
140+ self.install_run_jenkins()
141+ if self.jenkins_pid:
142+ msg = "Successfully configured jenkins with pid %s. \n"\
143+ % self.jenkins_pid
144+ self.stdout.write(msg)
145+
146+ jenkins_url='http://127.0.0.1:%s/jenkins' % self.port
147+ msg = "Use '%s' in your browser \n" % jenkins_url
148+ elif args[0] == 'stop':
149+ if len(args[1:]):
150+ for pid in args[1:]:
151+ self.stop_jenkins(pid)
152+ msg = 'Successfully terminated jenkins with pid %s\n' \
153+ % pid
154+ else:
155+ msg = "Missing pid value. Specify pid after stop argument\n"
156+ else:
157+ msg = "Invalid option. Supports only start/stop.\n"
158+
159+ self.stdout.write(msg)
160+ except:
161+ sys.stdout.write("Error processing the command\n")
162+
163+
164+ def install_run_jenkins(self):
165+ """
166+ Installs/configure/start the jenkins
167+ making sure another instance of jenkins is not running on the same self.port.
168+ """
169+ try:
170+ # Download openid plugin
171+ cmd = 'mkdir -p %s' % self.jenkins_home
172+ self.run(cmd)
173+
174+ # Stop any jenkins which is already running on the same port
175+ cmd = "lsof -w -n -i tcp:%s | awk -F ' ' '{print $2}' | tail -n 1 | "\
176+ "sed '/^$/d'" % self.port
177+ pid = self.run(cmd)
178+ if pid:
179+ msg = "Jenkins with pid '%s' is already running on port %s\n" \
180+ % (pid.strip(), self.port)
181+ self.stdout.write(msg)
182+ return
183+
184+ # start jenkins service
185+ self.jenkins_start()
186+
187+ cmd = 'cp %s %s' % (settings.JENKINS_CONFIG, self.jenkins_home)
188+ self.run(cmd)
189+
190+ except CalledProcessError:
191+ raise CalledProcessError(1, cmd, "Command Error")
192+
193+
194+ def stop_jenkins(self, pid):
195+ """
196+ Stops the jenkins process running with the pid specified.
197+ param :
198+ pid: pid of the jenkins service to stop
199+ """
200+ cmd = 'kill -9 %s' % pid
201+ try:
202+ self.run(cmd)
203+ except CalledProcessError:
204+ raise CalledProcessError(1, cmd, "Command Error")
205+
206+ def download(self, url, filename):
207+ """
208+ Downloads the jenkins.war file if it is not already
209+ present in the JENKINS_HOME dir
210+ param:
211+ filename: contains the location of the jenkins.war file
212+ """
213+ try:
214+ response = urllib2.urlopen(urllib2.quote(url, safe=":/"))
215+ if not (os.path.exists(filename) and os.path.isfile(filename)):
216+ fd = open(filename, 'wb')
217+ shutil.copyfileobj(response, fd)
218+ fd.close()
219+
220+ actual_size = int(response.headers['Content-Length'])
221+ downloaded_size = int(os.stat(filename).st_size)
222+ response.close()
223+ if actual_size != downloaded_size:
224+ raise
225+ except:
226+ raise CommandError("Could not retrieve %s" % url)
227+ sys.exit(1)
228+ return 0
229+
230+ def jenkins_start(self):
231+ """
232+ Start the jenkins service using the downloaded jenkins.war
233+ available in the JENKINS_HOME dir.
234+ Jenkins is started with admin JENKINS_USER/JENKINS_PASSWD
235+ credentials. Copy the template config.xml which enables
236+ options for user to login with JENKINS_USER/JENKINS_PASSWD credentials
237+ from browser.
238+ """
239+ # Download Jenkins war file
240+ self.jenkins_war = os.path.join(self.jenkins_home,
241+ os.path.basename(self.jenkins_war_url))
242+
243+ self.download(self.jenkins_war_url, self.jenkins_war)
244+
245+ # Start the jenkins service on port 9090
246+ cmd = '/usr/bin/java -jar %s --httpPort=%s --prefix=/jenkins \
247+ --argumentsRealm.passwd.%s=%s \
248+ --argumentsRealm.roles.%s=admin' \
249+ % (self.jenkins_war, self.port,
250+ self.jenkins_user, self.jenkins_passwd,
251+ self.jenkins_user)
252+
253+ cmd = shlex.split(cmd)
254+ log_fn = os.path.join(self.jenkins_home, self.jenkins_log)
255+ log_fd = open(log_fn, 'a')
256+ ret = Popen(cmd, stdout=log_fd, stderr=STDOUT, env={"JENKINS_HOME":self.jenkins_home})
257+
258+ if ret.returncode:
259+ raise CalledProcessError(1, cmd, 'cmd Failed')
260+ log_fd.close()
261+
262+ self.jenkins_pid = ret.pid
263+ return self.jenkins_pid
264+
265+ def run(self, cmd):
266+ try:
267+ ret = check_output(cmd, shell=True)
268+ return ret
269+ except CalledProcessError:
270+ raise CalledProcessError(1, cmd, "Command Error")
271
272=== modified file 'dashboard/frontend/tests/__init__.py'
273--- dashboard/frontend/tests/__init__.py 2012-07-09 19:29:31 +0000
274+++ dashboard/frontend/tests/__init__.py 2012-07-18 17:24:18 +0000
275@@ -1,5 +1,6 @@
276 from dashboard.frontend.tests.test_views import *
277 from dashboard.frontend.tests.test_clientresponse import *
278+from dashboard.frontend.tests.test_custom_commands import *
279
280
281 #starts the test suite
282@@ -7,4 +8,5 @@
283 'HomePageViewTests': HomePageViewTest,
284 'IndexViewTests': IndexViewTest,
285 'ClientResponseTests': ClientResponseTests,
286+ 'JenkinsCommandTest': JenkinsCommandTest,
287 }
288
289=== added file 'dashboard/frontend/tests/test_custom_commands.py'
290--- dashboard/frontend/tests/test_custom_commands.py 1970-01-01 00:00:00 +0000
291+++ dashboard/frontend/tests/test_custom_commands.py 2012-07-18 17:24:18 +0000
292@@ -0,0 +1,148 @@
293+#!/usr/bin/env python
294+# Copyright (C) 2012 Linaro
295+#
296+# This file is part of linaro-ci-dashboard.
297+#
298+# linaro-ci-dashboard is free software: you can redistribute it and/or modify
299+# it under the terms of the GNU Affero General Public License as published by
300+# the Free Software Foundation, either version 3 of the License, or
301+# (at your option) any later version.
302+#
303+# linaro-ci-dashboard is distributed in the hope that it will be useful,
304+# but WITHOUT ANY WARRANTY; without even the implied warranty of
305+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
306+# GNU Affero General Public License for more details.
307+#
308+# You should have received a copy of the GNU Affero General Public License
309+# along with linaro-ci-dashboard. If not, see <http://www.gnu.org/licenses/>.
310+
311+import frontend.management.commands.jenkins as jenkins
312+from django.core.management.base import CommandError
313+from django.conf import settings
314+from subprocess import CalledProcessError
315+from django.core import management
316+from StringIO import StringIO
317+from django.test import TestCase
318+import os, sys, shutil
319+
320+
321+class JenkinsCommandTest(TestCase):
322+
323+ orig_dir = os.getcwd()
324+
325+ def setUp(self):
326+ self.command = jenkins.Command()
327+ self.command.port = '9191'
328+ settings.JENKINS_PORT = self.command.port
329+ self.url = 'http://updates.jenkins-ci.org/latest/bazaar.hpi'
330+ os.environ["JENKINS_HOME"] = os.path.join(self.orig_dir, 'tmp/',
331+ 'jenkins_home')
332+ self.command.jenkins_home = os.getenv("JENKINS_HOME")
333+ self.command.jenkins_war = os.path.join(self.command.jenkins_home,
334+ os.path.basename(self.command.jenkins_war_url))
335+ self.download_filename = os.path.join(self.command.jenkins_home,
336+ os.path.basename(self.url))
337+
338+ if not os.path.exists(self.command.jenkins_home):
339+ os.makedirs(self.command.jenkins_home)
340+
341+ super(JenkinsCommandTest, self).setUp()
342+
343+ def tearDown(self):
344+ os.chdir(self.orig_dir)
345+ if os.path.exists(self.download_filename):
346+ cmd = 'rm %s' % self.download_filename
347+ self.command.run(cmd)
348+
349+ parent_dir = os.path.dirname(self.command.jenkins_home)
350+ if os.path.isdir(parent_dir):
351+ shutil.rmtree(parent_dir)
352+
353+ super(JenkinsCommandTest, self).tearDown()
354+
355+ def test_download_non_existing_package(self):
356+ url = 'http://mirrors.jenkins-ci.org/war/latest/jenkins1.war'
357+ filename = os.path.join('/tmp/', os.path.basename(url))
358+ self.assertRaises(CommandError, self.command.download, url, filename)
359+
360+ def test_download_existing_package(self):
361+ ret = self.command.download(self.url, self.download_filename)
362+ self.assertTrue(ret == 0)
363+
364+ def test_install_run_jenkins(self):
365+ orig_stdout = sys.stdout
366+ stdout = sys.stdout = StringIO()
367+ cmd = "lsof -w -n -i tcp:%s | awk -F ' ' '{print $2}' | tail -n 1 | "\
368+ "sed '/^$/d'" % self.command.port
369+ self.command.jenkins_pid = self.command.run(cmd)
370+ management.call_command('jenkins', 'start', interactive=False)
371+ if len(self.command.jenkins_pid) != 0:
372+ msg = "Jenkins with pid '%s' is already running on port %s"\
373+ % (self.command.jenkins_pid.strip(), self.command.port)
374+ else:
375+ msg = "Successfully configured jenkins with pid"
376+ sys.stdout = orig_stdout
377+ stdout.seek(0)
378+ self.assertIn(msg, stdout.read())
379+
380+ def test_invalid_run(self):
381+ cmd = 'rm /tmp/dummy'
382+ self.assertRaises(CalledProcessError, self.command.run, cmd)
383+
384+ def test_valid_run(self):
385+ ret = self.command.run(['whoami'])
386+ self.assertTrue(ret.strip() == os.getenv('USER'))
387+
388+
389+ def test_jenkins_stop_jenkins_non_existing_pid(self):
390+ pid = '123456'
391+ self.assertRaises(CalledProcessError, self.command.stop_jenkins, pid)
392+
393+
394+ def test_jenkins_stop_jenkins(self):
395+ orig_stdout = sys.stdout
396+ stdout = sys.stdout = StringIO()
397+ cmd = "lsof -w -n -i tcp:%s | awk -F ' ' '{print $2}' | tail -n 1 | "\
398+ "sed '/^$/d'" % self.command.port
399+ pid = self.command.run(cmd)
400+ management.call_command('jenkins', 'start', interactive=False)
401+ if len(pid) != 0:
402+ msg = "Jenkins with pid '%s' is already running on port %s"\
403+ % (pid.strip(), self.command.port)
404+ else:
405+ pid = self.command.jenkins_start()
406+ management.call_command('jenkins', 'stop', pid, interactive=False)
407+ msg = "Successfully terminated jenkins with pid"
408+ sys.stdout = orig_stdout
409+ stdout.seek(0)
410+ self.assertIn(msg, stdout.read())
411+
412+
413+ def test_jenkins_stop_missing_value(self):
414+ orig_stdout = sys.stdout
415+ stdout = sys.stdout = StringIO()
416+ management.call_command('jenkins', 'stop', interactive=False)
417+ msg = "Missing pid value. Specify pid after stop argument"
418+ sys.stdout = orig_stdout
419+ stdout.seek(0)
420+ self.assertIn(msg, stdout.read())
421+
422+
423+ def test_jenkins_invalid_option(self):
424+ orig_stdout = sys.stdout
425+ stdout = sys.stdout = StringIO()
426+ management.call_command('jenkins', 'Invalid', interactive=False)
427+ msg = "Invalid option. Supports only start/stop."
428+ sys.stdout = orig_stdout
429+ stdout.seek(0)
430+ self.assertIn(msg, stdout.read())
431+
432+
433+ def test_jenkins_invalid_option(self):
434+ orig_stdout = sys.stdout
435+ stdout = sys.stdout = StringIO()
436+ management.call_command('jenkins', interactive=False)
437+ msg = "Need to specify either start/stop"
438+ sys.stdout = orig_stdout
439+ stdout.seek(0)
440+ self.assertIn(msg, stdout.read())
441
442=== modified file 'dashboard/settings.py'
443--- dashboard/settings.py 2012-07-11 10:20:55 +0000
444+++ dashboard/settings.py 2012-07-18 17:24:18 +0000
445@@ -21,8 +21,8 @@
446 DEBUG = True
447 TEMPLATE_DEBUG = DEBUG
448
449-DEPS_INSTALL_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)),
450- "..", "lib")
451+ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
452+DEPS_INSTALL_PATH = os.path.join(ROOT_PATH, "..", "lib")
453
454 ADMINS = (
455 # ('Your Name', 'your_email@example.com'),
456@@ -175,3 +175,12 @@
457 },
458 }
459 }
460+
461+JENKKINS_WAR_URL = 'http://mirrors.jenkins-ci.org/war/latest/jenkins.war'
462+JENKINS_ADMIN_USER = 'admin'
463+JENKINS_ADMIN_PASSWD = 'admin'
464+JENKINS_PORT = '9090'
465+JENKINS_CONFIG = os.path.join(ROOT_PATH, '../config_template/', 'config.xml')
466+JENKINS_HOME = os.path.join(os.getenv('HOME'), ".jenkins_test")
467+JENKINS_LOG_NAME = 'jenkins.log'
468+

Subscribers

People subscribed via source and target branches

to all changes: