Add a proper machine table rather than just using the hostname
Should have done this in the first place ;-(

Added a new machine class to frontend, etc as well.

THIS WILL NECESSITATE REBUILDING THE DATABASE

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



git-svn-id: http://test.kernel.org/svn/autotest/trunk@730 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/db.py b/tko/db.py
index 151d4d4..1bb0afa 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -94,7 +94,10 @@
 
 
 	def insert_job(self, tag, job):
-		self.insert('jobs', {'tag':tag, 'machine':job.machine})
+		job.machine_idx = self.lookup_machine(job.machine)
+		if not job.machine_idx:
+			job.machine_idx = self.insert_machine(job.machine)
+		self.insert('jobs', {'tag':tag, 'machine_idx':job.machine_idx})
 		job.index = self.find_job(tag)
 		for test in job.tests:
 			self.insert_test(job, test)
@@ -105,7 +108,7 @@
 		data = {'job_idx':job.index, 'test':test.testname,
 			'subdir':test.subdir, 'kernel_idx':kver,
 			'status':self.status_idx[test.status],
-			'reason':test.reason, 'machine':test.machine }
+			'reason':test.reason, 'machine_idx':job.machine_idx }
 		self.insert('tests', data)
 		test_idx = self.find_test(job.index, test.subdir)
 		data = { 'test_idx':test_idx }
@@ -118,6 +121,20 @@
 				self.insert('iteration_result', data)
 
 
+	def insert_machine(self, hostname):
+		self.insert('machines', { 'hostname' : hostname })
+		return self.lookup_machine(hostname)
+
+
+	def lookup_machine(self, hostname):
+		where = { 'hostname' : hostname }
+		rows = self.select('machine_idx', 'machines', where)
+		if rows:
+			return rows[0][0]
+		else:
+			return None
+
+
 	def lookup_kernel(self, kernel):
 		rows = self.select('kernel_idx', 'kernels', 
 				{'kernel_hash':kernel.kernel_hash})