Change verify to throw an error if it fails, and record things
correctly

Signed-off-by: Martin Bligh <mbligh@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@1188 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/server_job.py b/server/server_job.py
index ae92172..c4624ca 100755
--- a/server/server_job.py
+++ b/server/server_job.py
@@ -95,19 +95,6 @@
 repair = load_control_segment("site_repair")
 repair += load_control_segment("repair")
 
-def verify_machines(machines):
-	if not machines:
-		raise AutoservError('No machines specified to verify')
-	namespace = {'machines' : machines, 'job' : None}
-	exec(preamble + verify, namespace, namespace)
-
-
-def repair_machines(machines):
-	if not machines:
-		raise AutoservError('No machines specified to repair')
-	namespace = {'machines' : machines, 'job' : None}
-	exec(preamble + repair, namespace, namespace)
-
 
 class server_job:
 	"""The actual job against which we do everything.
@@ -150,7 +137,11 @@
 		self.tmpdir    = os.path.join(self.serverdir, 'tmp')
 		self.conmuxdir = os.path.join(self.autodir, 'conmux')
 		self.clientdir = os.path.join(self.autodir, 'client')
-		self.control = re.sub('\r\n', '\n', open(control, 'r').read())
+		if control:
+			self.control = open(control, 'r').read()
+			self.control = re.sub('\r', '', self.control)
+		else:
+			self.control = None
 		self.resultdir = resultdir
 		if not os.path.exists(resultdir):
 			os.mkdir(resultdir)
@@ -175,6 +166,26 @@
 		write_keyval(self.resultdir, job_data)
 
 
+	def verify(self):
+		if not self.machines:
+			raise AutoservError('No machines specified to verify')
+		try:
+			namespace = {'machines' : self.machines, 'job' : self}
+			exec(preamble + verify, namespace, namespace)
+		except Exception, e:
+			msg = 'Verify failed\n' + str(e) + '\n' + format_error()
+			self.record('ABORT', None, None, msg)
+			raise
+
+
+	def repair(self):
+		if not self.machines:
+			raise AutoservError('No machines specified to repair')
+		namespace = {'machines' : self.machines, 'job' : self}
+		exec(preamble + repair, namespace, namespace)
+		self.repair()
+
+
 	def run(self, reboot = False, install_before = False,
 					install_after = False, namespace = {}):
 		# use a copy so changes don't affect the original dictionary
@@ -324,6 +335,8 @@
 		if not re.match(r'(START|(END )?(GOOD|WARN|FAIL|ABORT))$', \
 								status_code):
 			raise ValueError('Invalid status code supplied: %s' % status_code)
+		if not operation:
+			operation = '----'
 		if re.match(r'[\n\t]', operation):
 			raise ValueError('Invalid character in operation string')
 		operation = operation.rstrip()