1 # Copyright 2007 Google Inc. Released under the GPL v2
4 This module defines the Kernel class
9 import os
, os
.path
, time
10 from autotest_lib
.client
.common_lib
import error
11 from autotest_lib
.server
import kernel
, utils
14 class DEBKernel(kernel
.Kernel
):
16 This class represents a .deb pre-built kernel.
18 It is used to obtain a built kernel and install it on a Host.
20 Implementation details:
21 This is a leaf class in an abstract class hierarchy, it must
22 implement the unimplemented methods in parent classes.
25 super(DEBKernel
, self
).__init
__()
28 def install(self
, host
, **kwargs
):
30 Install a kernel on the remote host.
32 This will also invoke the guest's bootloader to set this
33 kernel as the default kernel.
36 host: the host on which to install the kernel
37 [kwargs]: remaining keyword arguments will be passed
38 to Bootloader.add_kernel()
41 AutoservError: no package has yet been obtained. Call
42 DEBKernel.get() with a .deb package.
44 if self
.source_material
is None:
45 raise error
.AutoservError("A kernel must first be "
46 "specified via get()")
48 remote_tmpdir
= host
.get_tmp_dir()
49 basename
= os
.path
.basename(self
.source_material
)
50 remote_filename
= os
.path
.join(remote_tmpdir
, basename
)
51 host
.send_file(self
.source_material
, remote_filename
)
52 host
.run('dpkg -i "%s"' % (utils
.sh_escape(remote_filename
),))
53 host
.run('mkinitramfs -o "%s" "%s"' % (
54 utils
.sh_escape(self
.get_initrd_name()),
55 utils
.sh_escape(self
.get_version()),))
57 host
.bootloader
.add_kernel(self
.get_image_name(),
58 initrd
=self
.get_initrd_name(), **kwargs
)
61 def get_version(self
):
62 """Get the version of the kernel to be installed.
65 The version string, as would be returned
66 by 'make kernelrelease'.
69 AutoservError: no package has yet been obtained. Call
70 DEBKernel.get() with a .deb package.
72 if self
.source_material
is None:
73 raise error
.AutoservError("A kernel must first be "
74 "specified via get()")
76 retval
= utils
.run('dpkg-deb -f "%s" version' %
77 utils
.sh_escape(self
.source_material
),)
78 return retval
.stdout
.strip()
81 def get_image_name(self
):
82 """Get the name of the kernel image to be installed.
85 The full path to the kernel image file as it will be
86 installed on the host.
89 AutoservError: no package has yet been obtained. Call
90 DEBKernel.get() with a .deb package.
92 return "/boot/vmlinuz-%s" % (self
.get_version(),)
95 def get_initrd_name(self
):
96 """Get the name of the initrd file to be installed.
99 The full path to the initrd file as it will be
100 installed on the host. If the package includes no
101 initrd file, None is returned
104 AutoservError: no package has yet been obtained. Call
105 DEBKernel.get() with a .deb package.
107 if self
.source_material
is None:
108 raise error
.AutoservError("A kernel must first be "
109 "specified via get()")
111 return "/boot/initrd.img-%s" % (self
.get_version(),)
113 def extract(self
, host
):
114 """Extract the kernel package.
116 This function is only useful to access the content of the
117 package (for example the kernel image) without
118 installing it. It is not necessary to run this function to
122 host: the host on which to extract the kernel package.
125 The full path to the temporary directory on host where
126 the package was extracted.
129 AutoservError: no package has yet been obtained. Call
130 DEBKernel.get() with a .deb package.
132 if self
.source_material
is None:
133 raise error
.AutoservError("A kernel must first be "
134 "specified via get()")
136 remote_tmpdir
= host
.get_tmp_dir()
137 basename
= os
.path
.basename(self
.source_material
)
138 remote_filename
= os
.path
.join(remote_tmpdir
, basename
)
139 host
.send_file(self
.source_material
, remote_filename
)
140 content_dir
= os
.path
.join(remote_tmpdir
, "contents")
141 host
.run('dpkg -x "%s" "%s"' % (utils
.sh_escape(remote_filename
),
142 utils
.sh_escape(content_dir
),))