Merge lp:~timrchavez/offspring/fix-lp-1133432 into lp:offspring

Proposed by Timothy R. Chavez
Status: Merged
Approved by: Kevin McDermott
Approved revision: 167
Merged at revision: 165
Proposed branch: lp:~timrchavez/offspring/fix-lp-1133432
Merge into: lp:offspring
Diff against target: 133 lines (+44/-9)
2 files modified
lib/offspring/slave/slave.py (+4/-2)
lib/offspring/slave/tests/test_slave.py (+40/-7)
To merge this branch: bzr merge lp:~timrchavez/offspring/fix-lp-1133432
Reviewer Review Type Date Requested Status
Kevin McDermott Approve
Review via email: mp+167196@code.launchpad.net

Description of the change

Add logging for failure conditions in getBuildName, so problems can be be properly investigated and resolved more quickly.

To post a comment you must log in.
166. By Timothy R. Chavez

Disambiguate error messages and add a test explicitly for the case we're now logging.

167. By Timothy R. Chavez

Remove crufty imports and fix log message.

Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Looks good to me, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/offspring/slave/slave.py'
2--- lib/offspring/slave/slave.py 2012-04-11 06:59:00 +0000
3+++ lib/offspring/slave/slave.py 2013-06-04 17:04:35 +0000
4@@ -2,8 +2,6 @@
5 # GNU Affero General Public License version 3 (see the file LICENSE).
6 import logging
7 import platform
8-import re
9-import tempfile
10 import time
11 import xmlrpclib
12
13@@ -283,6 +281,7 @@
14 if l.startswith("START"):
15 self.buildName = l.split(" ")[3].strip()
16 return self.buildName
17+ logging.error(self.stderrdata)
18 else:
19 try:
20 lfile = open(self.master.config.get("slave",
21@@ -295,6 +294,9 @@
22 if projectName == self.getProjectName():
23 self.buildName = buildName.strip("\n")
24 return self.buildName
25+ logging.error(
26+ "Error when trying to determine build name due to project "
27+ "name mismatch")
28 return LexbuilderSlaveServer.REQUEST_ERROR
29
30
31
32=== modified file 'lib/offspring/slave/tests/test_slave.py'
33--- lib/offspring/slave/tests/test_slave.py 2012-04-11 06:59:00 +0000
34+++ lib/offspring/slave/tests/test_slave.py 2013-06-04 17:04:35 +0000
35@@ -2,10 +2,7 @@
36 # GNU Affero General Public License version 3 (see the file LICENSE).
37
38 import logging
39-import os
40 import platform
41-import re
42-import subprocess
43 import xmlrpclib
44 from datetime import datetime
45
46@@ -18,6 +15,7 @@
47 from offspring.slave import (
48 LexbuilderSlave, ProjectBuildProcess, LexbuilderSlaveServer,
49 ShutdownThread)
50+from offspring.slave.taskmonitor import MonitoredProcess
51 from offspring.config import setup_logging
52
53
54@@ -274,7 +272,7 @@
55 log_file = self.capture_logging(log_level=logging.DEBUG)
56 self.config.set("slave", "request_timeout", "30.0")
57
58- slave_server = LexbuilderSlaveServer(
59+ LexbuilderSlaveServer(
60 self.fake_slave, ("localhost", 8760), self.config)
61 self.assertEqual("Request timeout set to 30.0 seconds\n",
62 log_file.getvalue())
63@@ -288,7 +286,7 @@
64 self.config.set("slave", "request_timeout", "broken value")
65
66
67- slave_server = LexbuilderSlaveServer(
68+ LexbuilderSlaveServer(
69 self.fake_slave, ("localhost", 8760), self.config)
70 self.assertEqual("Request timeout set to 60.0 seconds\n",
71 log_file.getvalue())
72@@ -706,7 +704,7 @@
73 def test_get_build_name_with_unknown_build_active_process(self):
74 """
75 If the build name is unknown, and the process is currently active,
76- then we ProjectBuildProcess.getBuildName should examine the the build
77+ then we ProjectBuildProcess.getBuildName should examine the build
78 statefile from the configuration and parse the project name and build
79 name from there.
80 """
81@@ -737,16 +735,51 @@
82 def test_get_build_name_with_unknown_build_active_process_error(self):
83 """
84 If the build name is unknown, and the process is currently active,
85- then we ProjectBuildProcess.getBuildName should examine the the build
86+ then we ProjectBuildProcess.getBuildName should examine the build
87 statefile from the configuration, any error reading this should result
88 in an error return.
89 """
90+ log_file = self.capture_logging()
91 self.build_process.state = self.build_process.STATE_ACTIVE
92 self.build_process.projectName = "newproject"
93 build_statefile_name = self.makeFile()
94 self.config.set("slave", "build_statefile", build_statefile_name)
95 self.assertEqual(LexbuilderSlaveServer.REQUEST_ERROR,
96 self.build_process.getBuildName())
97+ self.assertTrue(
98+ "Error when trying to determine build name" in log_file.getvalue())
99+
100+ def test_get_build_name_with_unknown_build_active_process_error_mismatch(self):
101+ """
102+ If the build name is unknown, and the process is currently active,
103+ then we ProjectBuildProcess.getBuildName should examine the build
104+ statefile from the configuration and parse the project name and build
105+ name from there. An error results if the statefile projectname does not
106+ match the process's project name.
107+ """
108+ log_file = self.capture_logging()
109+ self.build_process.state = self.build_process.STATE_ACTIVE
110+ self.build_process.projectName = "newproject"
111+ build_statefile_name = self.makeFile("oldproject oldbuildname")
112+ self.config.set("slave", "build_statefile", build_statefile_name)
113+ self.assertEqual(LexbuilderSlaveServer.REQUEST_ERROR,
114+ self.build_process.getBuildName())
115+ self.assertTrue(
116+ "Error when trying to determine build name due to project "
117+ "name mismatch" in log_file.getvalue())
118+
119+ def test_get_build_name_error_before_build_starts(self):
120+ """
121+ Test that errors which occur in shell scripts before a build starts
122+ are logged.
123+ """
124+ log_file = self.capture_logging()
125+ self.build_process.state = MonitoredProcess.STATE_FAILED
126+ self.build_process.stdoutdata = ""
127+ self.build_process.stderrdata = "This is a shell script error."
128+ self.build_process.getBuildName()
129+ self.assertTrue(
130+ "This is a shell script error." in log_file.getvalue())
131
132
133 class TestShutdownThread(MockerTestCase):

Subscribers

People subscribed via source and target branches