diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-07-26 11:36:20 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-07-26 12:03:36 +0100 |
commit | 5300fdafdf891de473529c1bec618d5d3f88fa59 (patch) | |
tree | 23bbcce148971f715420ac51d4f30509194f78ff /morphlib | |
parent | e20f9de6e4235d7ab2087031d405827253faeccb (diff) | |
download | morph-5300fdafdf891de473529c1bec618d5d3f88fa59.tar.gz |
Refactor: move kernel artifact creation into base class
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/builder2.py | 19 | ||||
-rw-r--r-- | morphlib/plugins/syslinux-disk-systembuilder_plugin.py | 10 | ||||
-rw-r--r-- | morphlib/plugins/tarball-systembuilder_plugin.py | 8 |
3 files changed, 21 insertions, 16 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 83f5ae84..5820dc44 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -550,6 +550,25 @@ class SystemKindBuilder(BuilderBase): # pragma: no cover f.write('sysfs /sys sysfs defaults 0 0\n') f.write('/dev/sda1 / btrfs defaults,rw,noatime 0 1\n') + def copy_kernel_into_artifact_cache(self, path): + '''Copy the installed kernel image into the local artifact cache. + + The kernel image will be a separate artifact from the root + filesystem/disk image/whatever. This is sometimes useful with + funky bootloaders or virtualisation. + + ''' + + name = self.artifact.source.morphology['name']+'-kernel' + a = self.new_artifact(name) + with self.local_artifact_cache.put(a) as dest: + for basename in ['zImage', 'vmlinuz']: + installed_path = os.path.join(path, 'boot', basename) + if os.path.exists(installed_path): + with open(installed_path) as kernel: + shutil.copyfileobj(kernel, dest) + break + class SystemKindBuilderFactory(object): # pragma: no cover diff --git a/morphlib/plugins/syslinux-disk-systembuilder_plugin.py b/morphlib/plugins/syslinux-disk-systembuilder_plugin.py index 3728f553..4c6f25ad 100644 --- a/morphlib/plugins/syslinux-disk-systembuilder_plugin.py +++ b/morphlib/plugins/syslinux-disk-systembuilder_plugin.py @@ -66,15 +66,7 @@ class SyslinuxDiskBuilder(SystemKindBuilder): # pragma: no cover factory_run_path = os.path.join(mount_point, 'factory-run') self._install_boot_files(arch, factory_run_path, mount_point) self._install_extlinux(mount_point) - - a = self.new_artifact( - self.artifact.source.morphology['name']+'-kernel') - with self.local_artifact_cache.put(a) as dest: - with open(os.path.join(factory_path, - 'boot', - 'vmlinuz')) as kernel: - shutil.copyfileobj(kernel, dest) - + self.copy_kernel_into_artifact_cache(factory_path) self._unmount(mount_point) except BaseException, e: logging.error(traceback.format_exc()) diff --git a/morphlib/plugins/tarball-systembuilder_plugin.py b/morphlib/plugins/tarball-systembuilder_plugin.py index fecf30a6..5975a5c3 100644 --- a/morphlib/plugins/tarball-systembuilder_plugin.py +++ b/morphlib/plugins/tarball-systembuilder_plugin.py @@ -51,13 +51,7 @@ class RootfsTarballBuilder(SystemKindBuilder): # pragma: no cover factory_path = mount_point self.unpack_strata(factory_path) self.create_fstab(factory_path) - a = self.new_artifact( - self.artifact.source.morphology['name']+'-kernel') - with self.local_artifact_cache.put(a) as dest: - with open(os.path.join(factory_path, - 'boot', - 'zImage')) as kernel: - shutil.copyfileobj(kernel, dest) + self.copy_kernel_into_artifact_cache(factory_path) except BaseException, e: logging.error(traceback.format_exc()) self.app.status(msg='Error while building system', |