hook kernel class to add a newly built kernel to the bootloader.

I've been playing around with adding entries to the bootloader with and
without mkintrds and the following patch adds a simple method to the
kernel class for adding a newly built kernel to the bootloader.  I've
also included a new sample control file which exercises the new method.
This patch relies on patch 1 from this set to ensure the mkinitrd is
added to the bootloader entry.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@320 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/bin/kernel.py b/bin/kernel.py
index 5855823..8e93a56 100755
--- a/bin/kernel.py
+++ b/bin/kernel.py
@@ -234,24 +234,56 @@
 		
 		if not os.path.isdir(prefix):
 			os.mkdir(prefix)
-		boot_dir = os.path.join(prefix, 'boot')
-		if not os.path.isdir(boot_dir):
-			os.mkdir(boot_dir)
+		self.boot_dir = os.path.join(prefix, 'boot')
+		if not os.path.isdir(self.boot_dir):
+			os.mkdir(self.boot_dir)
 
-		arch = get_file_arch('vmlinux')
-		image = os.path.join('arch', arch, 'boot', self.build_target)
-		force_copy(image, boot_dir + '/vmlinuz-' + tag)
-		force_copy('vmlinux', boot_dir + '/vmlinux-' + tag)
-		force_copy('System.map', boot_dir + '/System.map-' + tag)
-		force_copy('.config', boot_dir + '/config-' + tag)
-	
+		self.arch = get_file_arch('vmlinux')
+		image = os.path.join('arch', self.arch, 'boot', self.build_target)
+
+		# remember installed files
+		self.image = self.boot_dir + '/vmlinuz-' + tag
+		self.vmlinux = self.boot_dir + '/vmlinux-' + tag
+		self.system_map = self.boot_dir + '/System.map-' + tag
+		self.config = self.boot_dir + '/config-' + tag
+		self.initrd = ''
+
+		# copy to boot dir
+		force_copy(image, self.image)
+		force_copy('vmlinux', self.vmlinux)
+		force_copy('System.map', self.system_map)
+		force_copy('.config', self.config)
+
 		if not kernel_config.modules_needed('.config'):
 			return
 
 		system('make modules_install INSTALL_MOD_PATH=%s' % prefix)
 		if prefix == '/':
-			self.mkinitrd(self.get_kernel_build_ver(), image, \
-				     'System.map', boot_dir + '/initrd-' + tag)
+			self.initrd = self.boot_dir + '/initrd-' + tag
+			self.mkinitrd(self.get_kernel_build_ver(), self.image, \
+						  self.system_map, self.initrd)
+
+
+	def add_to_bootloader(self, tag='autotest', args=''):
+		""" add this kernel to bootloader, taking an
+		    optional parameter of space separated parameters
+		    e.g.:  kernel.add_to_bootloader('mykernel', 'ro acpi=off')
+		"""
+
+		# remove existing entry if present
+		self.job.bootloader.remove_kernel(tag)
+
+		# add the kernel entry
+		# add_kernel(image, title='autotest', inird='')
+		self.job.bootloader.add_kernel(self.image, tag, self.initrd)
+
+		# if no args passed, populate from /proc/cmdline
+		if not args:
+			args = open('/proc/cmdline', 'r').readline().strip()
+
+		# add args to entry one at a time
+		for a in args.split(' '):
+			self.job.bootloader.add_args(tag, a)
 
 
 	def get_kernel_build_ver(self):
diff --git a/samples/test_add_kernel b/samples/test_add_kernel
new file mode 100644
index 0000000..50cff05
--- /dev/null
+++ b/samples/test_add_kernel
@@ -0,0 +1,22 @@
+print "TEST: initing kernel"
+testkernel = job.kernel(job.tmpdir+'/build', '/usr/local/src/linux-2.6.14.tar.bz2') # '2.4.16'
+testkernel.patch('/usr/local/src/patch-2.6.14-git6.bz2')
+testkernel.config('http://ftp.kernel.org/pub/linux/kernel/people/mbligh/config/config.up')
+
+print "TEST: building kernel"
+testkernel.build()
+
+print "TEST: installing kernel"
+testkernel.install('autotest')
+
+print "TEST: adding kernel to bootloader"
+testkernel.add_to_bootloader('autotest')
+
+print "TEST: adding kernel to bootloader"
+testkernel.add_to_bootloader('autotest') # using default boot args (/proc/cmdline)
+
+print "TEST: listing bootloader entries"
+job.bootloader.list_titles()
+
+print "TEST: initing kernbench"
+job.runtest(None, 'kernbench', 2, 5)