~linaro-infrastructure/linaro-ci-dashboard/run_stop_jenkins_command

« back to all changes in this revision

Viewing changes to dashboard/frontend/tests/test_custom_commands.py

  • Committer: Deepti B. Kalakeri
  • Date: 2012-07-18 08:31:17 UTC
  • Revision ID: deepti.kalakeri@linaro.org-20120718083117-owkkfwe1vcir3wm9
some more changes for check where jenkins is already running on the same port

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import frontend.management.commands.runjenkins as runjenkins
20
20
import frontend.management.commands.stopjenkins as stopjenkins
21
21
from django.core.management.base import CommandError
 
22
from django.conf import settings
22
23
from subprocess import  CalledProcessError
23
24
from django.core import management
24
25
from StringIO import StringIO
32
33
       
33
34
    def setUp(self):
34
35
        self.command = runjenkins.Command()
35
 
        self.port = '9191'
 
36
        self.command.port = '9191'
 
37
        settings.JENKINS_PORT = self.command.port 
36
38
        self.url = 'http://updates.jenkins-ci.org/latest/bazaar.hpi'
37
39
        os.environ["JENKINS_HOME"] = os.path.join(self.orig_dir, 'tmp/', 
38
40
                                     'jenkins_home') 
71
73
    def test_install_package(self):
72
74
        orig_stdout = sys.stdout
73
75
        stdout = sys.stdout = StringIO()
74
 
        cmd = "lsof -w -n -i tcp:%s | awk -F ' ' '{print $2}' | tail -n 1" \
75
 
              % self.port
76
 
        pid = self.command.run(cmd)
77
 
        management.call_command('runjenkins', interactive=False)
78
 
        if pid:
 
76
        cmd = "lsof -w -n -i tcp:%s | awk -F ' ' '{print $2}' | tail -n 1 | "\
 
77
               "sed '/^$/d'"  % self.command.port
 
78
        self.command.jenkins_pid = self.command.run(cmd)
 
79
        if len(self.command.jenkins_pid) != 0:
79
80
            msg = "Jenkins with pid '%s' is already running on port %s"\
80
 
                  % (pid.strip(), self.command.port)
 
81
                  % (self.command.jenkins_pid, self.command.port)
81
82
        else:
82
 
            msg = "Successfully configured jenkins"
 
83
            msg = "Successfully configured jenkins with pid"
 
84
        management.call_command('runjenkins', interactive=False)
83
85
        sys.stdout = orig_stdout
84
86
        stdout.seek(0)
85
87
        self.assertIn(msg, stdout.read())
100
102
        self.runcommand = runjenkins.Command()
101
103
        self.stopcommand = stopjenkins.Command()
102
104
        self.runcommand.port = '9191'
 
105
        settings.JENKINS_PORT = self.runcommand.port 
103
106
        os.environ["JENKINS_HOME"] = os.path.join(self.orig_dir, 'tmp/', 
104
107
                                     'jenkins_home') 
105
108
        self.runcommand.jenkins_home = os.getenv("JENKINS_HOME") 
128
131
    def test_jenkins_terminate(self):
129
132
        orig_stdout = sys.stdout
130
133
        stdout = sys.stdout = StringIO()
131
 
        cmd = "lsof -w -n -i tcp:%s | awk -F ' ' '{print $2}' | tail -n 1" \
132
 
              % self.runcommand.port
 
134
        cmd = "lsof -w -n -i tcp:%s | awk -F ' ' '{print $2}' | tail -n 1 | "\
 
135
               "sed '/^$/d'"  % self.runcommand.port
133
136
        pid = self.runcommand.run(cmd)
134
137
        management.call_command('runjenkins', interactive=False)
135
 
        if pid:
 
138
        if len(pid) != 0:
136
139
            msg = "Jenkins with pid '%s' is already running on port %s"\
137
140
                  % (pid.strip(), self.runcommand.port)
138
141
        else: