summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-26 13:34:44 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-26 13:34:44 +0100
commit93a3d28ee51cc301cd79ff8bfabb2010defda09b (patch)
tree3d274d75f2e1adfd528e26edbad9cfa844c2a543
parent82ae6038c00ca7ceb0e1ed206bd07157e1658f50 (diff)
parentbc7cc75e6848f4215e522227c19d461473a85303 (diff)
downloadmorph-93a3d28ee51cc301cd79ff8bfabb2010defda09b.tar.gz
Merge branch 'liw/systemkindbuilder'
Reviewed-By: Daniel Silverstone
-rwxr-xr-xmorphlib/app.py13
-rw-r--r--morphlib/builder2.py233
-rw-r--r--morphlib/plugins/syslinux-disk-systembuilder_plugin.py202
-rw-r--r--morphlib/plugins/tarball-systembuilder_plugin.py73
-rwxr-xr-xtests.as-root/make-patch.script2
-rwxr-xr-xtests.as-root/rootfs-tarball-builds-rootfs-and-kernel.script (renamed from tests.as-root/arm-system-writes-kernel.script)43
-rwxr-xr-xtests.as-root/setup2
-rwxr-xr-xtests.as-root/syslinux-disk-builds-rootfs-and-kernel.script101
-rwxr-xr-xtests.as-root/system-overlap.script2
-rwxr-xr-xtests.branching/setup2
-rwxr-xr-xtests/setup2
-rw-r--r--without-test-modules3
12 files changed, 491 insertions, 187 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index 86575fcd..491adb16 100755
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -476,6 +476,8 @@ class Morph(cliapp.Application):
self.hookmgr = cliapp.HookManager()
self.hookmgr.new('new-build-command', cliapp.FilterHook())
+ self.system_kind_builder_factory = \
+ morphlib.builder2.SystemKindBuilderFactory()
def _itertriplets(self, args):
'''Generate repo, ref, filename triples from args.'''
@@ -732,10 +734,11 @@ class Morph(cliapp.Application):
return mount_point
def cleanup(path, mount_point):
- try:
- morphlib.fsutils.unmount(self.runcmd, mount_point)
- except:
- pass
+ if mount_point is not None:
+ try:
+ morphlib.fsutils.unmount(self.runcmd, mount_point)
+ except:
+ pass
try:
morphlib.fsutils.undo_device_mapping(self.runcmd, path)
except:
@@ -745,6 +748,8 @@ class Morph(cliapp.Application):
except:
pass
+ mount_point_1 = None
+ mount_point_2 = None
try:
mount_point_1 = setup(image_path_1)
mount_point_2 = setup(image_path_2)
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 2ae8785f..5820dc44 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -467,118 +467,18 @@ class StratumBuilder(BuilderBase):
return [artifact]
-class SystemBuilder(BuilderBase): # pragma: no cover
-
- '''Build system image artifacts.'''
+class SystemKindBuilder(BuilderBase): # pragma: no cover
- def build_and_cache(self):
- with self.build_watch('overall-build'):
- self.app.status(msg='Building system %(system_name)s',
- system_name=self.artifact.name)
-
- arch = self.artifact.source.morphology['arch']
-
- rootfs_artifact = self.new_artifact(
- self.artifact.source.morphology['name'] + '-rootfs')
- handle = self.local_artifact_cache.put(rootfs_artifact)
- image_name = handle.name
-
- self._create_image(image_name)
- self._partition_image(image_name)
- self._install_mbr(arch, image_name)
- partition = self._setup_device_mapping(image_name)
+ '''Build a specific kind of a system.
- mount_point = None
- try:
- self._create_fs(partition)
- mount_point = self.staging_area.destdir(self.artifact.source)
- self._mount(partition, mount_point)
- factory_path = os.path.join(mount_point, 'factory')
- self._create_subvolume(factory_path)
- self._unpack_strata(factory_path)
- self._create_fstab(factory_path)
- if arch in ('x86', 'x86_64'):
- self._create_extlinux_config(factory_path)
- self._create_subvolume_snapshot(
- mount_point, 'factory', 'factory-run')
- factory_run_path = os.path.join(mount_point, 'factory-run')
- self._install_boot_files(arch, factory_run_path, mount_point)
- if arch in ('x86', 'x86_64'):
- self._install_extlinux(mount_point)
- if arch in ('arm',):
- 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._unmount(mount_point)
- except BaseException, e:
- logging.error(traceback.format_exc())
- self.app.status(msg='Error while building system',
- error=True)
- self._unmount(mount_point)
- self._undo_device_mapping(image_name)
- handle.abort()
- raise
+ Subclasses should set the ``system_kind`` attribute to the kind of
+ system they build.
- self._undo_device_mapping(image_name)
- handle.close()
+ '''
- self.save_build_times()
- return [self.artifact]
-
- def _create_image(self, image_name):
- self.app.status(msg='Creating disk image %(filename)s',
- filename=image_name, chatty=True)
- with self.build_watch('create-image'):
- morphlib.fsutils.create_image(
- self.app.runcmd, image_name,
- self.artifact.source.morphology['disk-size'])
-
- def _partition_image(self, image_name):
- self.app.status(msg='Partitioning disk image %(filename)s',
- filename=image_name)
- with self.build_watch('partition-image'):
- morphlib.fsutils.partition_image(self.app.runcmd, image_name)
-
- def _install_mbr(self, arch, image_name):
- self.app.status(msg='Installing mbr on disk image %(filename)s',
- filename=image_name, chatty=True)
- if arch not in ('x86', 'x86_64'):
- return
- with self.build_watch('install-mbr'):
- morphlib.fsutils.install_syslinux_mbr(self.app.runcmd, image_name)
-
- def _setup_device_mapping(self, image_name):
- self.app.status(msg='Device mapping partitions in %(filename)s',
- filename=image_name, chatty=True)
- with self.build_watch('setup-device-mapper'):
- return morphlib.fsutils.setup_device_mapping(self.app.runcmd,
- image_name)
-
- def _create_fs(self, partition):
- self.app.status(msg='Creating filesystem on %(partition)s',
- partition=partition, chatty=True)
- with self.build_watch('create-filesystem'):
- morphlib.fsutils.create_fs(self.app.runcmd, partition)
-
- def _mount(self, partition, mount_point):
- self.app.status(msg='Mounting %(partition)s on %(mount_point)s',
- partition=partition, mount_point=mount_point,
- chatty=True)
- with self.build_watch('mount-filesystem'):
- morphlib.fsutils.mount(self.app.runcmd, partition, mount_point)
-
- def _create_subvolume(self, path):
- self.app.status(msg='Creating subvolume %(path)s',
- path=path, chatty=True)
- with self.build_watch('create-factory-subvolume'):
- self.app.runcmd(['btrfs', 'subvolume', 'create', path])
+ def unpack_strata(self, path):
+ '''Unpack strata into a directory.'''
- def _unpack_strata(self, path):
self.app.status(msg='Unpacking strata to %(path)s',
path=path, chatty=True)
with self.build_watch('unpack-strata'):
@@ -630,7 +530,15 @@ class SystemBuilder(BuilderBase): # pragma: no cover
ldconfig(self.app.runcmd, path)
- def _create_fstab(self, path):
+ def create_fstab(self, path):
+ '''Create an /etc/fstab inside a system tree.
+
+ The fstab is created using assumptions of the disk layout.
+ If the assumptions are wrong, extend this code so it can deal
+ with other cases.
+
+ '''
+
self.app.status(msg='Creating fstab in %(path)s',
path=path, chatty=True)
with self.build_watch('create-fstab'):
@@ -642,62 +550,61 @@ class SystemBuilder(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 _create_extlinux_config(self, path):
- self.app.status(msg='Creating extlinux.conf in %(path)s',
- path=path, chatty=True)
- with self.build_watch('create-extlinux-config'):
- config = os.path.join(path, 'extlinux.conf')
- with open(config, 'w') as f:
- f.write('default linux\n')
- f.write('timeout 1\n')
- f.write('label linux\n')
- f.write('kernel /boot/vmlinuz\n')
- f.write('append root=/dev/sda1 rootflags=subvol=factory-run '
- 'init=/sbin/init rw\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
+
+ '''A factory class for SystemKindBuilder objects.'''
+
+ def __init__(self):
+ self.system_kinds = []
+
+ def register(self, klass):
+ self.system_kinds.append(klass)
+
+ def new(self, system_kind, args, kwargs):
+ for klass in self.system_kinds:
+ if klass.system_kind == system_kind:
+ return klass(*args, **kwargs)
+ raise morphlib.Error("Don't know how to build system kind %s" %
+ system_kind)
+
+
+class SystemBuilder(BuilderBase): # pragma: no cover
+
+ '''Build system image artifacts.'''
+
+ def __init__(self, *args, **kwargs):
+ BuilderBase.__init__(self, *args, **kwargs)
+ self.args = args
+ self.kwargs = kwargs
- def _create_subvolume_snapshot(self, path, source, target):
- self.app.status(msg='Creating subvolume snapshot '
- '%(source)s to %(target)s',
- source=source, target=target, chatty=True)
- with self.build_watch('create-runtime-snapshot'):
- self.app.runcmd(['btrfs', 'subvolume', 'snapshot', source, target],
- cwd=path)
-
- def _install_boot_files(self, arch, sourcefs, targetfs):
- with self.build_watch('install-boot-files'):
- if arch in ('x86', 'x86_64'):
- self.app.status(msg='Installing boot files into root volume',
- chatty=True)
- shutil.copy2(os.path.join(sourcefs, 'extlinux.conf'),
- os.path.join(targetfs, 'extlinux.conf'))
- os.mkdir(os.path.join(targetfs, 'boot'))
- shutil.copy2(os.path.join(sourcefs, 'boot', 'vmlinuz'),
- os.path.join(targetfs, 'boot', 'vmlinuz'))
- shutil.copy2(os.path.join(sourcefs, 'boot', 'System.map'),
- os.path.join(targetfs, 'boot', 'System.map'))
-
- def _install_extlinux(self, path):
- self.app.status(msg='Installing extlinux to %(path)s',
- path=path, chatty=True)
- with self.build_watch('install-bootloader'):
- self.app.runcmd(['extlinux', '--install', path])
-
- # FIXME this hack seems to be necessary to let extlinux finish
- self.app.runcmd(['sync'])
- time.sleep(2)
-
- def _unmount(self, mount_point):
- with self.build_watch('unmount-filesystem'):
- if mount_point is not None:
- self.app.status(msg='Unmounting %(mount_point)s',
- mount_point=mount_point, chatty=True)
- morphlib.fsutils.unmount(self.app.runcmd, mount_point)
-
- def _undo_device_mapping(self, image_name):
- self.app.status(msg='Undoing device mappings for %(filename)s',
- filename=image_name, chatty=True)
- with self.build_watch('undo-device-mapper'):
- morphlib.fsutils.undo_device_mapping(self.app.runcmd, image_name)
+ def build_and_cache(self):
+ system_kind = self.artifact.source.morphology['system-kind']
+ builder = self.app.system_kind_builder_factory.new(
+ system_kind, self.args, self.kwargs)
+ logging.debug('Building system with %s' % repr(builder))
+ self.app.status(msg='Building system %(system_name)s',
+ system_name=self.artifact.name)
+ return builder.build_and_cache()
class Builder(object): # pragma: no cover
diff --git a/morphlib/plugins/syslinux-disk-systembuilder_plugin.py b/morphlib/plugins/syslinux-disk-systembuilder_plugin.py
new file mode 100644
index 00000000..4c6f25ad
--- /dev/null
+++ b/morphlib/plugins/syslinux-disk-systembuilder_plugin.py
@@ -0,0 +1,202 @@
+# Copyright (C) 2012 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+import json
+import logging
+import os
+import shutil
+import time
+from collections import defaultdict
+import tarfile
+import traceback
+import subprocess
+
+import cliapp
+
+import morphlib
+from morphlib.artifactcachereference import ArtifactCacheReference
+from morphlib.builder2 import (SystemKindBuilder, download_depends,
+ get_overlaps, log_overlaps, ldconfig,
+ write_overlap_metadata)
+
+
+class SyslinuxDiskBuilder(SystemKindBuilder): # pragma: no cover
+
+ system_kind = 'syslinux-disk'
+
+ def build_and_cache(self):
+ with self.build_watch('overall-build'):
+ arch = self.artifact.source.morphology['arch']
+
+ rootfs_artifact = self.new_artifact(
+ self.artifact.source.morphology['name'] + '-rootfs')
+ handle = self.local_artifact_cache.put(rootfs_artifact)
+ image_name = handle.name
+
+ self._create_image(image_name)
+ self._partition_image(image_name)
+ self._install_mbr(arch, image_name)
+ partition = self._setup_device_mapping(image_name)
+
+ mount_point = None
+ try:
+ self._create_fs(partition)
+ mount_point = self.staging_area.destdir(self.artifact.source)
+ self._mount(partition, mount_point)
+ factory_path = os.path.join(mount_point, 'factory')
+ self._create_subvolume(factory_path)
+ self.unpack_strata(factory_path)
+ self.create_fstab(factory_path)
+ self._create_extlinux_config(factory_path)
+ self._create_subvolume_snapshot(
+ mount_point, 'factory', 'factory-run')
+ 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)
+ self.copy_kernel_into_artifact_cache(factory_path)
+ self._unmount(mount_point)
+ except BaseException, e:
+ logging.error(traceback.format_exc())
+ self.app.status(msg='Error while building system',
+ error=True)
+ self._unmount(mount_point)
+ self._undo_device_mapping(image_name)
+ handle.abort()
+ raise
+
+ self._undo_device_mapping(image_name)
+ handle.close()
+
+ self.save_build_times()
+ return [self.artifact]
+
+ def _create_image(self, image_name):
+ self.app.status(msg='Creating disk image %(filename)s',
+ filename=image_name, chatty=True)
+ with self.build_watch('create-image'):
+ morphlib.fsutils.create_image(
+ self.app.runcmd, image_name,
+ self.artifact.source.morphology['disk-size'])
+
+ def _partition_image(self, image_name):
+ self.app.status(msg='Partitioning disk image %(filename)s',
+ filename=image_name)
+ with self.build_watch('partition-image'):
+ morphlib.fsutils.partition_image(self.app.runcmd, image_name)
+
+ def _install_mbr(self, arch, image_name):
+ self.app.status(msg='Installing mbr on disk image %(filename)s',
+ filename=image_name, chatty=True)
+ if arch not in ('x86', 'x86_64'):
+ return
+ with self.build_watch('install-mbr'):
+ morphlib.fsutils.install_syslinux_mbr(self.app.runcmd, image_name)
+
+ def _setup_device_mapping(self, image_name):
+ self.app.status(msg='Device mapping partitions in %(filename)s',
+ filename=image_name, chatty=True)
+ with self.build_watch('setup-device-mapper'):
+ return morphlib.fsutils.setup_device_mapping(self.app.runcmd,
+ image_name)
+
+ def _create_fs(self, partition):
+ self.app.status(msg='Creating filesystem on %(partition)s',
+ partition=partition, chatty=True)
+ with self.build_watch('create-filesystem'):
+ morphlib.fsutils.create_fs(self.app.runcmd, partition)
+
+ def _mount(self, partition, mount_point):
+ self.app.status(msg='Mounting %(partition)s on %(mount_point)s',
+ partition=partition, mount_point=mount_point,
+ chatty=True)
+ with self.build_watch('mount-filesystem'):
+ morphlib.fsutils.mount(self.app.runcmd, partition, mount_point)
+
+ def _create_subvolume(self, path):
+ self.app.status(msg='Creating subvolume %(path)s',
+ path=path, chatty=True)
+ with self.build_watch('create-factory-subvolume'):
+ self.app.runcmd(['btrfs', 'subvolume', 'create', path])
+
+ def _create_extlinux_config(self, path):
+ self.app.status(msg='Creating extlinux.conf in %(path)s',
+ path=path, chatty=True)
+ with self.build_watch('create-extlinux-config'):
+ config = os.path.join(path, 'extlinux.conf')
+ with open(config, 'w') as f:
+ f.write('default linux\n')
+ f.write('timeout 1\n')
+ f.write('label linux\n')
+ f.write('kernel /boot/vmlinuz\n')
+ f.write('append root=/dev/sda1 rootflags=subvol=factory-run '
+ 'init=/sbin/init rw\n')
+
+ def _create_subvolume_snapshot(self, path, source, target):
+ self.app.status(msg='Creating subvolume snapshot '
+ '%(source)s to %(target)s',
+ source=source, target=target, chatty=True)
+ with self.build_watch('create-runtime-snapshot'):
+ self.app.runcmd(['btrfs', 'subvolume', 'snapshot', source, target],
+ cwd=path)
+
+ def _install_boot_files(self, arch, sourcefs, targetfs):
+ with self.build_watch('install-boot-files'):
+ if arch in ('x86', 'x86_64'):
+ self.app.status(msg='Installing boot files into root volume',
+ chatty=True)
+ shutil.copy2(os.path.join(sourcefs, 'extlinux.conf'),
+ os.path.join(targetfs, 'extlinux.conf'))
+ os.mkdir(os.path.join(targetfs, 'boot'))
+ shutil.copy2(os.path.join(sourcefs, 'boot', 'vmlinuz'),
+ os.path.join(targetfs, 'boot', 'vmlinuz'))
+ shutil.copy2(os.path.join(sourcefs, 'boot', 'System.map'),
+ os.path.join(targetfs, 'boot', 'System.map'))
+
+ def _install_extlinux(self, path):
+ self.app.status(msg='Installing extlinux to %(path)s',
+ path=path, chatty=True)
+ with self.build_watch('install-bootloader'):
+ self.app.runcmd(['extlinux', '--install', path])
+
+ # FIXME this hack seems to be necessary to let extlinux finish
+ self.app.runcmd(['sync'])
+ time.sleep(2)
+
+ def _unmount(self, mount_point):
+ with self.build_watch('unmount-filesystem'):
+ if mount_point is not None:
+ self.app.status(msg='Unmounting %(mount_point)s',
+ mount_point=mount_point, chatty=True)
+ morphlib.fsutils.unmount(self.app.runcmd, mount_point)
+
+ def _undo_device_mapping(self, image_name):
+ self.app.status(msg='Undoing device mappings for %(filename)s',
+ filename=image_name, chatty=True)
+ with self.build_watch('undo-device-mapper'):
+ morphlib.fsutils.undo_device_mapping(self.app.runcmd, image_name)
+
+
+class SyslinuxDiskBuilderPlugin(cliapp.Plugin):
+
+ def enable(self):
+ # Only provide this system builder on architectures that are
+ # supported by syslinux.
+ if morphlib.util.arch() in ['x86_64', 'i386', 'i486', 'i586', 'i686']:
+ self.app.system_kind_builder_factory.register(SyslinuxDiskBuilder)
+
+ def disable(self):
+ pass
+
diff --git a/morphlib/plugins/tarball-systembuilder_plugin.py b/morphlib/plugins/tarball-systembuilder_plugin.py
new file mode 100644
index 00000000..8afe6bce
--- /dev/null
+++ b/morphlib/plugins/tarball-systembuilder_plugin.py
@@ -0,0 +1,73 @@
+# Copyright (C) 2012 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+import json
+import logging
+import os
+import shutil
+import time
+from collections import defaultdict
+import tarfile
+import traceback
+import subprocess
+
+import cliapp
+
+import morphlib
+from morphlib.artifactcachereference import ArtifactCacheReference
+from morphlib.builder2 import (SystemKindBuilder, download_depends,
+ get_overlaps, log_overlaps, ldconfig,
+ write_overlap_metadata)
+
+
+class RootfsTarballBuilder(SystemKindBuilder): # pragma: no cover
+
+ system_kind = 'rootfs-tarball'
+
+ def build_and_cache(self):
+ with self.build_watch('overall-build'):
+ arch = self.artifact.source.morphology['arch']
+
+ rootfs_name = self.artifact.source.morphology['name'] + '-rootfs'
+ rootfs_artifact = self.new_artifact(rootfs_name)
+ handle = self.local_artifact_cache.put(rootfs_artifact)
+
+ try:
+ fs_root = self.staging_area.destdir(self.artifact.source)
+ self.unpack_strata(fs_root)
+ self.create_fstab(fs_root)
+ self.copy_kernel_into_artifact_cache(fs_root)
+ except BaseException, e:
+ logging.error(traceback.format_exc())
+ self.app.status(msg='Error while building system',
+ error=True)
+ handle.abort()
+ raise
+
+ handle.close()
+
+ self.save_build_times()
+ return [self.artifact]
+
+
+class RootfsTarballBuilderPlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.system_kind_builder_factory.register(RootfsTarballBuilder)
+
+ def disable(self):
+ pass
+
diff --git a/tests.as-root/make-patch.script b/tests.as-root/make-patch.script
index 9a159a48..bd14c5a9 100755
--- a/tests.as-root/make-patch.script
+++ b/tests.as-root/make-patch.script
@@ -45,7 +45,7 @@ EOF
# Build first image. Remember the stratum.
"$SRCDIR/scripts/test-morph" build test:morphs-repo master hello-system.morph
-img1=$(find "$DATADIR/cache/artifacts" -maxdepth 1 -name '*.system.*')
+img1=$(find "$DATADIR/cache/artifacts" -maxdepth 1 -name '*.system.*-rootfs')
# Modify the chunk, in a new branch.
"$SRCDIR/scripts/run-git-in" "$DATADIR/chunk-repo" checkout --quiet farrokh
diff --git a/tests.as-root/arm-system-writes-kernel.script b/tests.as-root/rootfs-tarball-builds-rootfs-and-kernel.script
index b9ac95b3..30055745 100755
--- a/tests.as-root/arm-system-writes-kernel.script
+++ b/tests.as-root/rootfs-tarball-builds-rootfs-and-kernel.script
@@ -1,6 +1,7 @@
#!/bin/sh
#
-# If the system's arch is arm, it should write the kernel to the cache
+# A system-kind of rootfs-tarball should build both kernel image and
+# a tarball with the root filesystem.
#
# Copyright (C) 2011, 2012 Codethink Limited
#
@@ -24,23 +25,25 @@ kernelrepo="$DATADIR/kernel-repo"
morphsrepo="$DATADIR/morphs-repo"
log="$DATADIR/morph.log"
+arch=$(uname -m)
+
cd "$morphsrepo"
-git checkout --quiet -b arm master
-cat <<EOF >arm-system.morph
+git checkout --quiet -b custom master
+cat <<EOF >system.morph
{
- "name": "arm-system",
+ "name": "system",
"kind": "system",
- "system-kind": "dummy",
- "arch": "arm",
+ "system-kind": "rootfs-tarball",
+ "arch": "$arch",
"disk-size": "1G",
"strata": [
- "arm-stratum"
+ "stratum"
]
}
EOF
-cat <<EOF >arm-stratum.morph
+cat <<EOF >stratum.morph
{
- "name": "arm-stratum",
+ "name": "stratum",
"kind": "stratum",
"sources": [
{
@@ -52,17 +55,17 @@ cat <<EOF >arm-stratum.morph
{
"name": "linux",
"repo": "test:kernel-repo",
- "ref": "arm",
+ "ref": "custom",
"build-depends": ["hello"]
}
]
}
EOF
-git add arm-system.morph arm-stratum.morph
-git commit --quiet -m "add arm system"
+git add system.morph stratum.morph
+git commit --quiet -m "add custom system"
cd "$kernelrepo"
-git checkout --quiet -b arm master
+git checkout --quiet -b custom master
cat <<EOF >linux.morph
{
"name": "linux",
@@ -78,5 +81,15 @@ git add linux.morph
git commit --quiet -m 'Make the kernel create a dummy zImage'
"$SRCDIR/scripts/test-morph" \
- build test:morphs-repo arm arm-system.morph > /dev/null
-[ -e "$cache"/*system.arm-system-kernel ] || find "$cache"
+ build test:morphs-repo custom system.morph > /dev/null
+
+for suffix in kernel rootfs
+do
+ if [ ! -e "$cache"/*system.system-$suffix ]
+ then
+ echo "can't find $cache/*system.system-$suffix" 1>&2
+ find "$cache" 1>&2
+ exit 1
+ fi
+done
+
diff --git a/tests.as-root/setup b/tests.as-root/setup
index 542fb36f..7564292a 100755
--- a/tests.as-root/setup
+++ b/tests.as-root/setup
@@ -106,7 +106,7 @@ cat <<EOF > hello-system.morph
{
"name": "hello-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"arch": "$(uname -m)",
"disk-size": "1G",
"strata": [
diff --git a/tests.as-root/syslinux-disk-builds-rootfs-and-kernel.script b/tests.as-root/syslinux-disk-builds-rootfs-and-kernel.script
new file mode 100755
index 00000000..f23ac55f
--- /dev/null
+++ b/tests.as-root/syslinux-disk-builds-rootfs-and-kernel.script
@@ -0,0 +1,101 @@
+#!/bin/sh
+#
+# A system kind of syslinux-disk should create the disk image, plus a kernel
+# file.
+#
+# Copyright (C) 2011, 2012 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -eu
+
+# We only support x86 systems with syslinux-disk.
+arch=$(uname -m)
+case "$arch" in
+ x86*) ;;
+ *) exit 0 ;;
+esac
+
+cache="$DATADIR/cache/artifacts"
+kernelrepo="$DATADIR/kernel-repo"
+morphsrepo="$DATADIR/morphs-repo"
+log="$DATADIR/morph.log"
+
+cd "$morphsrepo"
+git checkout --quiet -b custom master
+cat <<EOF >system.morph
+{
+ "name": "system",
+ "kind": "system",
+ "system-kind": "syslinux-disk",
+ "arch": "$arch",
+ "disk-size": "1G",
+ "strata": [
+ "stratum"
+ ]
+}
+EOF
+cat <<EOF >stratum.morph
+{
+ "name": "stratum",
+ "kind": "stratum",
+ "sources": [
+ {
+ "name": "hello",
+ "repo": "test:chunk-repo",
+ "ref": "farrokh",
+ "build-depends": []
+ },
+ {
+ "name": "linux",
+ "repo": "test:kernel-repo",
+ "ref": "custom",
+ "build-depends": ["hello"]
+ }
+ ]
+}
+EOF
+git add system.morph stratum.morph
+git commit --quiet -m "foo"
+
+cd "$kernelrepo"
+git checkout --quiet -b custom master
+cat <<EOF >linux.morph
+{
+ "name": "linux",
+ "kind": "chunk",
+ "install-commands": [
+ "mkdir -p \"\$DESTDIR/boot\"",
+ "touch \"\$DESTDIR\"/boot/vmlinuz",
+ "touch \"\$DESTDIR\"/boot/System.map"
+ ]
+}
+EOF
+git add linux.morph
+
+git commit --quiet -m 'Make the kernel create a dummy zImage'
+
+"$SRCDIR/scripts/test-morph" \
+ build test:morphs-repo custom system.morph > /dev/null
+
+for suffix in kernel rootfs
+do
+ if [ ! -e "$cache"/*system.system-"$suffix" ];
+ then
+ echo "No .system.system-$suffix" 1>&2
+ find "$cache" 1>&2
+ exit 1
+ fi
+done
+
diff --git a/tests.as-root/system-overlap.script b/tests.as-root/system-overlap.script
index 1c2e1180..4b39aa04 100755
--- a/tests.as-root/system-overlap.script
+++ b/tests.as-root/system-overlap.script
@@ -30,7 +30,7 @@ cat <<EOF >overlap-system.morph
{
"name": "overlap-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"arch": "$(uname -m)",
"disk-size": "1G",
"strata": [
diff --git a/tests.branching/setup b/tests.branching/setup
index 24627bce..d659b1d0 100755
--- a/tests.branching/setup
+++ b/tests.branching/setup
@@ -48,7 +48,7 @@ cat <<EOF > "$DATADIR/morphs/hello-system.morph"
{
"name": "hello-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"disk-size": "1G",
"strata": [
"hello-stratum"
diff --git a/tests/setup b/tests/setup
index ce187065..8d3ab5b5 100755
--- a/tests/setup
+++ b/tests/setup
@@ -106,7 +106,7 @@ cat <<EOF > hello-system.morph
{
"name": "hello-system",
"kind": "system",
- "system-kind": "dummy",
+ "system-kind": "syslinux-disk",
"disk-size": "1G",
"strata": [
"hello-stratum"
diff --git a/without-test-modules b/without-test-modules
index 5c824c18..47c5d7c8 100644
--- a/without-test-modules
+++ b/without-test-modules
@@ -7,3 +7,6 @@ morphlib/fsutils.py
morphlib/app.py
morphlib/plugins/hello_plugin.py
morphlib/plugins/graphing_plugin.py
+morphlib/plugins/syslinux-disk-systembuilder_plugin.py
+morphlib/plugins/tarball-systembuilder_plugin.py
+