mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2007 Google Inc. Released under the GPL v2 |
| 4 | |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 5 | """ |
| 6 | This module defines the SourceKernel class |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 7 | |
| 8 | SourceKernel: an linux kernel built from source |
| 9 | """ |
| 10 | |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 11 | __author__ = """ |
| 12 | mbligh@google.com (Martin J. Bligh), |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 13 | poirier@google.com (Benjamin Poirier), |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 14 | stutsman@google.com (Ryan Stutsman) |
| 15 | """ |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 16 | |
| 17 | |
| 18 | import kernel |
| 19 | |
| 20 | |
| 21 | |
| 22 | class SourceKernel(kernel.Kernel): |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 23 | """ |
| 24 | This class represents a linux kernel built from source. |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 25 | |
| 26 | It is used to obtain a built kernel or create one from source and |
| 27 | install it on a Host. |
| 28 | |
| 29 | Implementation details: |
| 30 | This is a leaf class in an abstract class hierarchy, it must |
| 31 | implement the unimplemented methods in parent classes. |
| 32 | """ |
| 33 | def __init__(self): |
| 34 | super(kernel.Kernel, self).__init__() |
| 35 | self.__patch_list = [] |
| 36 | self.__config_file = None |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 37 | |
| 38 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 39 | def configure(self, configFile): |
| 40 | self.__config_file = configFile |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 41 | |
| 42 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 43 | def patch(self, patchFile): |
| 44 | self.__patch_list.append(patchFile) |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 45 | |
| 46 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 47 | def build(self, host): |
| 48 | at = autotest.Autotest() |
| 49 | at.install(host) |
| 50 | ctlfile = self.control_file(self.__kernel, self.__patch_list, |
| 51 | self.__config_file) |
| 52 | at.run(ctlfile, host.get_tmp_dir(), host) |
| 53 | |
mbligh | dc735a2 | 2007-08-02 16:54:37 +0000 | [diff] [blame] | 54 | |
mbligh | dcd57a8 | 2007-07-11 23:06:47 +0000 | [diff] [blame] | 55 | def __control_file(self, kernel, patch_list, config): |
| 56 | ctl = ("def step_init():\n" |
| 57 | "\tjob.next_step([step_test])\n" |
| 58 | "\ttestkernel = job.kernel('%s')\n" % kernel) |
| 59 | |
| 60 | if len(patch_list): |
| 61 | patches = ', '.join(["'%s'" % x for x in patch_list]) |
| 62 | ctl += "\ttestkernel.patch(%s)" % patches |
| 63 | |
| 64 | if config: |
| 65 | ctl += "\ttestkernel.config('%s')" % config |
| 66 | else: |
| 67 | ctl += "\ttestkernel.config('', None, True)" |
| 68 | |
| 69 | ctl += "\ttestkernel.build()" |
| 70 | |
| 71 | # copy back to server |
| 72 | |
| 73 | return ctl |