From 44f329642604fe7fdbb20d6045c804df6fa5ebd2 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Mon, 30 Dec 2013 12:14:43 +0100 Subject: [PATCH] Extlinux support The bootloader is now specified in the manifest --- base/manifest-schema.json | 3 +- common/task_sets.py | 6 ++++ common/tasks/boot.py | 30 +++++++++++++++++++ ...bs-debian-official-amd64-hvm.manifest.json | 1 + ...bs-debian-official-amd64-pvm.manifest.json | 1 + ...ebs-debian-official-i386-pvm.manifest.json | 1 + manifests/ec2-ebs-partitioned.manifest.json | 1 + manifests/ec2-ebs-single.manifest.json | 1 + manifests/ec2-s3.manifest.json | 1 + manifests/virtualbox-vagrant.manifest.json | 1 + manifests/virtualbox.manifest.json | 1 + providers/ec2/__init__.py | 7 +++-- providers/ec2/manifest.py | 11 ++++--- providers/ec2/tasks/packages.py | 1 - providers/virtualbox/__init__.py | 5 ++-- providers/virtualbox/manifest-schema.json | 9 ++++++ providers/virtualbox/tasks/packages.py | 3 -- 17 files changed, 69 insertions(+), 14 deletions(-) diff --git a/base/manifest-schema.json b/base/manifest-schema.json index f705020..64fa62c 100644 --- a/base/manifest-schema.json +++ b/base/manifest-schema.json @@ -20,11 +20,12 @@ "properties": { "release": { "enum": ["wheezy"] }, "architecture": { "enum": ["i386", "amd64"] }, + "bootloader": { "enum": ["pvgrub", "grub", "extlinux"] }, "timezone": { "type": "string" }, "locale": { "type": "string" }, "charmap": { "type": "string" } }, - "required": ["release", "architecture", "timezone", "locale", "charmap"] + "required": ["release", "architecture", "bootloader", "timezone", "locale", "charmap"] }, "packages": { "type": "object", diff --git a/common/task_sets.py b/common/task_sets.py index a82f706..e8ca038 100644 --- a/common/task_sets.py +++ b/common/task_sets.py @@ -1,6 +1,7 @@ from common.tasks import workspace from common.tasks import packages from common.tasks import host +from common.tasks import boot from common.tasks import bootstrap from common.tasks import volume from common.tasks import filesystem @@ -62,6 +63,11 @@ locale_set = [locale.LocaleBootstrapPackage, ] +bootloader_set = {'grub': [boot.AddGrubPackage, boot.InstallGrub], + 'extlinux': [boot.AddExtlinuxPackage, boot.InstallExtLinux], + } + + def get_fs_specific_set(partitions): task_set = {'ext2': [filesystem.TuneVolumeFS], 'ext3': [filesystem.TuneVolumeFS], diff --git a/common/tasks/boot.py b/common/tasks/boot.py index bf4c409..7e666f8 100644 --- a/common/tasks/boot.py +++ b/common/tasks/boot.py @@ -30,6 +30,15 @@ class DisableGetTTYs(Task): sed_i(inittab_path, '^' + i + ttyx + i, '#' + i + ttyx + i) +class AddGrubPackage(Task): + description = 'Adding grub package' + phase = phases.preparation + predecessors = [apt.AddDefaultSources] + + def run(self, info): + info.packages.add('grub-pc') + + class InstallGrub(Task): description = 'Installing grub' phase = phases.system_modification @@ -91,3 +100,24 @@ class InstallGrub(Task): if isinstance(info.volume, LoopbackVolume): remount(info.volume, unlink_fn) + + +class AddExtlinuxPackage(Task): + description = 'Adding extlinux package' + phase = phases.preparation + predecessors = [apt.AddDefaultSources] + + def run(self, info): + info.packages.add('extlinux') + + +class InstallExtLinux(Task): + description = 'Installing extlinux' + phase = phases.system_modification + predecessors = [apt.AptUpgrade] + + def run(self, info): + from common.tools import log_check_call + log_check_call(['/usr/sbin/chroot', info.root, + '/usr/bin/extlinux', + '--install', '/boot']) diff --git a/manifests/ec2-ebs-debian-official-amd64-hvm.manifest.json b/manifests/ec2-ebs-debian-official-amd64-hvm.manifest.json index b18f3b1..ab2159f 100644 --- a/manifests/ec2-ebs-debian-official-amd64-hvm.manifest.json +++ b/manifests/ec2-ebs-debian-official-amd64-hvm.manifest.json @@ -16,6 +16,7 @@ "system": { "release": "wheezy", "architecture": "amd64", + "bootloader": "extlinux", "timezone": "UTC", "locale": "en_US", "charmap": "UTF-8" diff --git a/manifests/ec2-ebs-debian-official-amd64-pvm.manifest.json b/manifests/ec2-ebs-debian-official-amd64-pvm.manifest.json index df4d2fd..4dcd130 100644 --- a/manifests/ec2-ebs-debian-official-amd64-pvm.manifest.json +++ b/manifests/ec2-ebs-debian-official-amd64-pvm.manifest.json @@ -16,6 +16,7 @@ "system": { "release": "wheezy", "architecture": "amd64", + "bootloader": "pvgrub", "timezone": "UTC", "locale": "en_US", "charmap": "UTF-8" diff --git a/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json b/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json index c61b3b6..daf6a95 100644 --- a/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json +++ b/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json @@ -16,6 +16,7 @@ "system": { "release": "wheezy", "architecture": "i386", + "bootloader": "pvgrub", "timezone": "UTC", "locale": "en_US", "charmap": "UTF-8" diff --git a/manifests/ec2-ebs-partitioned.manifest.json b/manifests/ec2-ebs-partitioned.manifest.json index e3b312d..3101960 100644 --- a/manifests/ec2-ebs-partitioned.manifest.json +++ b/manifests/ec2-ebs-partitioned.manifest.json @@ -16,6 +16,7 @@ "system": { "release": "wheezy", "architecture": "amd64", + "bootloader": "pvgrub", "timezone": "UTC", "locale": "en_US", "charmap": "UTF-8" diff --git a/manifests/ec2-ebs-single.manifest.json b/manifests/ec2-ebs-single.manifest.json index 945febc..c2deb2c 100644 --- a/manifests/ec2-ebs-single.manifest.json +++ b/manifests/ec2-ebs-single.manifest.json @@ -16,6 +16,7 @@ "system": { "release": "wheezy", "architecture": "amd64", + "bootloader": "pvgrub", "timezone": "UTC", "locale": "en_US", "charmap": "UTF-8" diff --git a/manifests/ec2-s3.manifest.json b/manifests/ec2-s3.manifest.json index 8dca5c7..09db13c 100644 --- a/manifests/ec2-s3.manifest.json +++ b/manifests/ec2-s3.manifest.json @@ -20,6 +20,7 @@ "system": { "release": "wheezy", "architecture": "amd64", + "bootloader": "pvgrub", "timezone": "UTC", "locale": "en_US", "charmap": "UTF-8" diff --git a/manifests/virtualbox-vagrant.manifest.json b/manifests/virtualbox-vagrant.manifest.json index 370db9a..07a2c7e 100644 --- a/manifests/virtualbox-vagrant.manifest.json +++ b/manifests/virtualbox-vagrant.manifest.json @@ -11,6 +11,7 @@ "system": { "release": "wheezy", "architecture": "amd64", + "bootloader": "grub", "timezone": "UTC", "locale": "en_US", "charmap": "UTF-8" diff --git a/manifests/virtualbox.manifest.json b/manifests/virtualbox.manifest.json index e4decbd..951b626 100644 --- a/manifests/virtualbox.manifest.json +++ b/manifests/virtualbox.manifest.json @@ -11,6 +11,7 @@ "system": { "release": "wheezy", "architecture": "amd64", + "bootloader": "grub", "timezone": "UTC", "locale": "en_US", "charmap": "UTF-8" diff --git a/providers/ec2/__init__.py b/providers/ec2/__init__.py index 0e7d789..9c1dc14 100644 --- a/providers/ec2/__init__.py +++ b/providers/ec2/__init__.py @@ -67,10 +67,11 @@ def resolve_tasks(tasklist, manifest): tasks.ami.RegisterAMI) - if manifest.virtualization == 'pvm': - tasklist.add(tasks.boot.ConfigurePVGrub) + if manifest.system['bootloader'] == 'pvgrub': + tasklist.add(boot.AddGrubPackage, tasks.boot.ConfigurePVGrub) else: - tasklist.add(boot.InstallGrub) + from common.task_sets import bootloader_set + tasklist.add(*bootloader_set.get(manifest.system['bootloader'])) backing_specific_tasks = {'ebs': [tasks.ebs.Create, tasks.ebs.Attach, diff --git a/providers/ec2/manifest.py b/providers/ec2/manifest.py index 10d816f..c1264e1 100644 --- a/providers/ec2/manifest.py +++ b/providers/ec2/manifest.py @@ -6,8 +6,7 @@ class Manifest(base.Manifest): def validate(self, data): super(Manifest, self).validate(data) from os import path - schema_path = path.join(path.dirname(__file__), 'manifest-schema.json') - self.schema_validate(data, schema_path) + self.schema_validate(data, path.join(path.dirname(__file__), 'manifest-schema.json')) if data['volume']['backing'] == 'ebs': volume_size = self._calculate_volume_size(data['volume']['partitions']) if volume_size % 1024 != 0: @@ -15,8 +14,12 @@ class Manifest(base.Manifest): '(MBR partitioned volumes are 1MB larger than specified, for the post-mbr gap)') raise ManifestError(msg, self) else: - schema_path = path.join(path.dirname(__file__), 'manifest-schema-s3.json') - self.schema_validate(data, schema_path) + self.schema_validate(data, path.join(path.dirname(__file__), 'manifest-schema-s3.json')) + + if data['virtualization'] == 'pvm' and data['system']['bootloader'] != 'pvgrub': + raise ManifestError('Paravirtualized AMIs only support pvgrub as a bootloader', self) + if data['virtualization'] == 'hvm' and data['system']['bootloader'] != 'extlinux': + raise ManifestError('HVM AMIs only support extlinux as a bootloader', self) def parse(self, data): super(Manifest, self).parse(data) diff --git a/providers/ec2/tasks/packages.py b/providers/ec2/tasks/packages.py index 71f962b..8ce3044 100644 --- a/providers/ec2/tasks/packages.py +++ b/providers/ec2/tasks/packages.py @@ -12,7 +12,6 @@ class DefaultPackages(Task): info.packages.add('openssh-server') info.packages.add('file') # Needed for the init scripts info.packages.add('dhcpcd') # isc-dhcp-client doesn't work properly with ec2 - info.packages.add('grub-pc') info.exclude_packages.add('isc-dhcp-client') info.exclude_packages.add('isc-dhcp-common') diff --git a/providers/virtualbox/__init__.py b/providers/virtualbox/__init__.py index 0e67704..3e296f9 100644 --- a/providers/virtualbox/__init__.py +++ b/providers/virtualbox/__init__.py @@ -5,7 +5,6 @@ from common.tasks import loopback from common.tasks import partitioning from common.tasks import filesystem from common.tasks import bootstrap -from common.tasks import boot from common.tasks import security from common.tasks import network from common.tasks import initd @@ -29,6 +28,9 @@ def resolve_tasks(tasklist, manifest): tasklist.add(*apt_set) tasklist.add(*locale_set) + from common.task_sets import bootloader_set + tasklist.add(*bootloader_set.get(manifest.system['bootloader'])) + if manifest.volume['partitions']['type'] != 'none': from common.task_sets import partitioning_set tasklist.add(*partitioning_set) @@ -37,7 +39,6 @@ def resolve_tasks(tasklist, manifest): loopback.Create, - boot.InstallGrub, security.EnableShadowConfig, network.RemoveDNSInfo, network.ConfigureNetworkIF, diff --git a/providers/virtualbox/manifest-schema.json b/providers/virtualbox/manifest-schema.json index 07d2cf9..c366294 100644 --- a/providers/virtualbox/manifest-schema.json +++ b/providers/virtualbox/manifest-schema.json @@ -11,6 +11,15 @@ } } }, + "system": { + "type": "object", + "properties": { + "bootloader": { + "type": "string", + "enum": ["grub"] + } + } + }, "volume": { "type": "object", "properties": { diff --git a/providers/virtualbox/tasks/packages.py b/providers/virtualbox/tasks/packages.py index b4dc817..a7ad411 100644 --- a/providers/virtualbox/tasks/packages.py +++ b/providers/virtualbox/tasks/packages.py @@ -9,9 +9,6 @@ class DefaultPackages(Task): predecessors = [apt.AddDefaultSources] def run(self, info): - # Add some basic packages we are going to need - info.packages.add('grub2') - kernels = {'amd64': 'linux-image-amd64', 'i386': 'linux-image-686', } info.packages.add(kernels.get(info.manifest.system['architecture']))