Fix #107. Rename before and after task properties

`before' becomes `successors' and `after' becomes `predecessors'
This commit is contained in:
Anders Ingemann 2013-11-21 15:54:42 +01:00
parent d05c97afef
commit 663b868b41
25 changed files with 61 additions and 61 deletions

View file

@ -2,8 +2,8 @@
class Task(object): class Task(object):
phase = None phase = None
before = [] predecessors = []
after = [] successors = []
def __str__(self): def __str__(self):
return '{module}.{task}'.format(module=self.__module__, task=self.__class__.__name__) return '{module}.{task}'.format(module=self.__module__, task=self.__class__.__name__)

View file

@ -36,8 +36,8 @@ class TaskList(object):
for task in tasks: for task in tasks:
self.check_ordering(task) self.check_ordering(task)
successors = set() successors = set()
successors.update(task.before) successors.update(task.successors)
successors.update(filter(lambda succ: task in succ.after, tasks)) successors.update(filter(lambda succ: task in succ.predecessors, tasks))
succeeding_phases = order[order.index(task.phase) + 1:] succeeding_phases = order[order.index(task.phase) + 1:]
successors.update(filter(lambda succ: succ.phase in succeeding_phases, tasks)) successors.update(filter(lambda succ: succ.phase in succeeding_phases, tasks))
graph[task] = filter(lambda succ: succ in tasks, successors) graph[task] = filter(lambda succ: succ in tasks, successors)
@ -58,13 +58,13 @@ class TaskList(object):
return sorted_tasks return sorted_tasks
def check_ordering(self, task): def check_ordering(self, task):
for successor in task.before: for successor in task.successors:
if successor.phase > successor.phase: if successor.phase > successor.phase:
msg = ("The task {task} is specified as running before {other}, " msg = ("The task {task} is specified as running before {other}, "
"but its phase '{phase}' lies after the phase '{other_phase}'" "but its phase '{phase}' lies after the phase '{other_phase}'"
.format(task=task, other=successor, phase=task.phase, other_phase=successor.phase)) .format(task=task, other=successor, phase=task.phase, other_phase=successor.phase))
raise TaskListError(msg) raise TaskListError(msg)
for predecessor in task.after: for predecessor in task.predecessors:
if task.phase < predecessor.phase: if task.phase < predecessor.phase:
msg = ("The task {task} is specified as running after {other}, " msg = ("The task {task} is specified as running after {other}, "
"but its phase '{phase}' lies before the phase '{other_phase}'" "but its phase '{phase}' lies before the phase '{other_phase}'"

View file

@ -42,8 +42,8 @@ class DisableDaemonAutostart(Task):
class AptUpgrade(Task): class AptUpgrade(Task):
description = 'Upgrading packages and fixing broken dependencies' description = 'Upgrading packages and fixing broken dependencies'
phase = phases.system_modification phase = phases.system_modification
before = [network.RemoveDNSInfo] predecessors = [locale.GenerateLocale, AptSources, DisableDaemonAutostart]
after = [locale.GenerateLocale, AptSources, DisableDaemonAutostart] successors = [network.RemoveDNSInfo]
def run(self, info): def run(self, info):
log_check_call(['/usr/sbin/chroot', info.root, '/usr/bin/apt-get', 'update']) log_check_call(['/usr/sbin/chroot', info.root, '/usr/bin/apt-get', 'update'])

View file

@ -43,7 +43,7 @@ class MakeTarball(Task):
class Bootstrap(Task): class Bootstrap(Task):
description = 'Installing Debian' description = 'Installing Debian'
phase = phases.os_installation phase = phases.os_installation
after = [MakeTarball] predecessors = [MakeTarball]
def run(self, info): def run(self, info):
executable, options, arguments = get_bootstrap_args(info) executable, options, arguments = get_bootstrap_args(info)

View file

@ -17,7 +17,7 @@ class Format(Task):
class TuneVolumeFS(Task): class TuneVolumeFS(Task):
description = 'Tuning the bootstrap volume filesystem' description = 'Tuning the bootstrap volume filesystem'
phase = phases.volume_preparation phase = phases.volume_preparation
after = [Format] predecessors = [Format]
def run(self, info): def run(self, info):
import re import re
@ -49,7 +49,7 @@ class CreateMountDir(Task):
class MountRoot(Task): class MountRoot(Task):
description = 'Mounting the root partition' description = 'Mounting the root partition'
phase = phases.volume_mounting phase = phases.volume_mounting
after = [CreateMountDir] predecessors = [CreateMountDir]
def run(self, info): def run(self, info):
info.volume.partition_map.root.mount(info.root) info.volume.partition_map.root.mount(info.root)
@ -58,7 +58,7 @@ class MountRoot(Task):
class MountBoot(Task): class MountBoot(Task):
description = 'Mounting the boot partition' description = 'Mounting the boot partition'
phase = phases.volume_mounting phase = phases.volume_mounting
after = [MountRoot] predecessors = [MountRoot]
def run(self, info): def run(self, info):
info.volume.partition_map.boot.mount(info.boot_dir) info.volume.partition_map.boot.mount(info.boot_dir)
@ -67,8 +67,8 @@ class MountBoot(Task):
class CreateBootMountDir(Task): class CreateBootMountDir(Task):
description = 'Creating mountpoint for the boot partition' description = 'Creating mountpoint for the boot partition'
phase = phases.volume_mounting phase = phases.volume_mounting
after = [MountRoot] successors = [MountBoot]
before = [MountBoot] predecessors = [MountRoot]
def run(self, info): def run(self, info):
import os import os
@ -79,7 +79,7 @@ class CreateBootMountDir(Task):
class MountSpecials(Task): class MountSpecials(Task):
description = 'Mounting special block devices' description = 'Mounting special block devices'
phase = phases.os_installation phase = phases.os_installation
after = [Bootstrap] predecessors = [Bootstrap]
def run(self, info): def run(self, info):
info.volume.mount_specials() info.volume.mount_specials()
@ -88,7 +88,7 @@ class MountSpecials(Task):
class UnmountRoot(Task): class UnmountRoot(Task):
description = 'Unmounting the bootstrap volume' description = 'Unmounting the bootstrap volume'
phase = phases.volume_unmounting phase = phases.volume_unmounting
before = [volume.Detach] successors = [volume.Detach]
def run(self, info): def run(self, info):
info.volume.partition_map.root.unmount() info.volume.partition_map.root.unmount()
@ -97,7 +97,7 @@ class UnmountRoot(Task):
class UnmountBoot(Task): class UnmountBoot(Task):
description = 'Unmounting the boot partition' description = 'Unmounting the boot partition'
phase = phases.volume_unmounting phase = phases.volume_unmounting
before = [UnmountRoot] successors = [UnmountRoot]
def run(self, info): def run(self, info):
info.volume.partition_map.boot.unmount() info.volume.partition_map.boot.unmount()
@ -106,7 +106,7 @@ class UnmountBoot(Task):
class UnmountSpecials(Task): class UnmountSpecials(Task):
description = 'Unmunting special block devices' description = 'Unmunting special block devices'
phase = phases.volume_unmounting phase = phases.volume_unmounting
before = [UnmountRoot] successors = [UnmountRoot]
def run(self, info): def run(self, info):
info.volume.unmount_specials() info.volume.unmount_specials()
@ -115,7 +115,7 @@ class UnmountSpecials(Task):
class DeleteMountDir(Task): class DeleteMountDir(Task):
description = 'Deleting mountpoint for the bootstrap volume' description = 'Deleting mountpoint for the bootstrap volume'
phase = phases.volume_unmounting phase = phases.volume_unmounting
after = [UnmountRoot] predecessors = [UnmountRoot]
def run(self, info): def run(self, info):
import os import os

View file

@ -7,7 +7,7 @@ import packages
class CheckPackages(Task): class CheckPackages(Task):
description = 'Checking installed host packages' description = 'Checking installed host packages'
phase = phases.preparation phase = phases.preparation
after = [packages.HostPackages, packages.ImagePackages] predecessors = [packages.HostPackages, packages.ImagePackages]
def run(self, info): def run(self, info):
from common.tools import log_check_call from common.tools import log_check_call

View file

@ -37,7 +37,7 @@ class ResolveInitScripts(Task):
class InstallInitScripts(Task): class InstallInitScripts(Task):
description = 'Installing startup scripts' description = 'Installing startup scripts'
phase = phases.system_modification phase = phases.system_modification
after = [ResolveInitScripts] predecessors = [ResolveInitScripts]
def run(self, info): def run(self, info):
import stat import stat

View file

@ -6,7 +6,7 @@ import volume
class Create(Task): class Create(Task):
description = 'Creating a loopback volume' description = 'Creating a loopback volume'
phase = phases.volume_creation phase = phases.volume_creation
before = [volume.Attach] successors = [volume.Attach]
def run(self, info): def run(self, info):
import os.path import os.path

View file

@ -15,8 +15,8 @@ class PartitionVolume(Task):
class MapPartitions(Task): class MapPartitions(Task):
description = 'Mapping volume partitions' description = 'Mapping volume partitions'
phase = phases.volume_preparation phase = phases.volume_preparation
before = [filesystem.Format] predecessors = [PartitionVolume]
after = [PartitionVolume] successors = [filesystem.Format]
def run(self, info): def run(self, info):
info.volume.partition_map.map(info.volume) info.volume.partition_map.map(info.volume)
@ -25,8 +25,8 @@ class MapPartitions(Task):
class UnmapPartitions(Task): class UnmapPartitions(Task):
description = 'Removing volume partitions mapping' description = 'Removing volume partitions mapping'
phase = phases.volume_unmounting phase = phases.volume_unmounting
before = [volume.Detach] predecessors = [filesystem.UnmountRoot]
after = [filesystem.UnmountRoot] successors = [volume.Detach]
def run(self, info): def run(self, info):
info.volume.partition_map.unmap(info.volume) info.volume.partition_map.unmap(info.volume)

View file

@ -22,7 +22,7 @@ class Detach(Task):
class Delete(Task): class Delete(Task):
description = 'Deleting the volume' description = 'Deleting the volume'
phase = phases.cleaning phase = phases.cleaning
before = [workspace.DeleteWorkspace] successors = [workspace.DeleteWorkspace]
def run(self, info): def run(self, info):
info.volume.delete() info.volume.delete()

View file

@ -9,8 +9,8 @@ import os
class AddSudoPackage(Task): class AddSudoPackage(Task):
description = 'Adding ``sudo\'\' to the image packages' description = 'Adding ``sudo\'\' to the image packages'
phase = phases.preparation phase = phases.preparation
after = [ImagePackages] predecessors = [ImagePackages]
before = [CheckPackages] successors = [CheckPackages]
def run(self, info): def run(self, info):
info.img_packages[0].add('sudo') info.img_packages[0].add('sudo')
@ -45,7 +45,7 @@ class PasswordlessSudo(Task):
class AdminUserCredentials(Task): class AdminUserCredentials(Task):
description = 'Modifying ec2-get-credentials to copy the ssh public key to the admin user' description = 'Modifying ec2-get-credentials to copy the ssh public key to the admin user'
phase = phases.system_modification phase = phases.system_modification
after = [InstallInitScripts] predecessors = [InstallInitScripts]
def run(self, info): def run(self, info):
from common.tools import sed_i from common.tools import sed_i

View file

@ -10,8 +10,8 @@ import os
class AptSourcesBackports(Task): class AptSourcesBackports(Task):
description = 'Adding backports to sources.list' description = 'Adding backports to sources.list'
phase = phases.system_modification phase = phases.system_modification
after = [AptSources] predecessors = [AptSources]
before = [AptUpgrade] successors = [AptUpgrade]
def run(self, info): def run(self, info):
sources_path = os.path.join(info.root, 'etc/apt/sources.list') sources_path = os.path.join(info.root, 'etc/apt/sources.list')
@ -25,7 +25,7 @@ class AptSourcesBackports(Task):
class AddBackportsPackages(Task): class AddBackportsPackages(Task):
description = 'Adding backport packages to the image' description = 'Adding backport packages to the image'
phase = phases.system_modification phase = phases.system_modification
after = [AptUpgrade] predecessors = [AptUpgrade]
def run(self, info): def run(self, info):
if 'packages' not in info.manifest.plugins['backports']: if 'packages' not in info.manifest.plugins['backports']:

View file

@ -6,7 +6,7 @@ from common.tasks import loopback
class ConvertImage(Task): class ConvertImage(Task):
description = 'Converting raw image' description = 'Converting raw image'
phase = phases.image_registration phase = phases.image_registration
before = [loopback.MoveImage] successors = [loopback.MoveImage]
def run(self, info): def run(self, info):
from common.tools import log_check_call from common.tools import log_check_call

View file

@ -7,7 +7,7 @@ import os
class OpenNebulaContext(Task): class OpenNebulaContext(Task):
description = 'Setup OpenNebula init context' description = 'Setup OpenNebula init context'
phase = phases.system_modification phase = phases.system_modification
after = [GenerateLocale] predecessors = [GenerateLocale]
def run(self, info): def run(self, info):
import stat import stat

View file

@ -14,7 +14,7 @@ log = logging.getLogger(__name__)
class Snapshot(Task): class Snapshot(Task):
description = 'Creating a snapshot of the bootstrapped volume' description = 'Creating a snapshot of the bootstrapped volume'
phase = phases.os_installation phase = phases.os_installation
after = [bootstrap.Bootstrap, filesystem.MountSpecials] predecessors = [bootstrap.Bootstrap, filesystem.MountSpecials]
def run(self, info): def run(self, info):
def mk_snapshot(): def mk_snapshot():
@ -27,7 +27,7 @@ class Snapshot(Task):
class CreateFromSnapshot(Task): class CreateFromSnapshot(Task):
description = 'Creating EBS volume from a snapshot' description = 'Creating EBS volume from a snapshot'
phase = phases.volume_creation phase = phases.volume_creation
before = [volume.Attach] successors = [volume.Attach]
def run(self, info): def run(self, info):
volume_size = int(info.manifest.volume['size'] / 1024) volume_size = int(info.manifest.volume['size'] / 1024)
@ -45,7 +45,7 @@ class CreateFromSnapshot(Task):
class CopyImage(Task): class CopyImage(Task):
description = 'Creating a snapshot of the bootstrapped volume' description = 'Creating a snapshot of the bootstrapped volume'
phase = phases.os_installation phase = phases.os_installation
after = [bootstrap.Bootstrap, filesystem.MountSpecials] predecessors = [bootstrap.Bootstrap, filesystem.MountSpecials]
def run(self, info): def run(self, info):
loopback_backup_name = 'volume-{id:x}.{ext}.backup'.format(id=info.run_id, ext=info.volume.extension) loopback_backup_name = 'volume-{id:x}.{ext}.backup'.format(id=info.run_id, ext=info.volume.extension)
@ -61,7 +61,7 @@ class CopyImage(Task):
class CreateFromImage(Task): class CreateFromImage(Task):
description = 'Creating loopback image from a copy' description = 'Creating loopback image from a copy'
phase = phases.volume_creation phase = phases.volume_creation
before = [volume.Attach] successors = [volume.Attach]
def run(self, info): def run(self, info):
info.volume.image_path = os.path.join(info.workspace, 'volume.{ext}'.format(ext=info.volume.extension)) info.volume.image_path = os.path.join(info.workspace, 'volume.{ext}'.format(ext=info.volume.extension))
@ -74,8 +74,8 @@ class CreateFromImage(Task):
class SetBootMountDir(Task): class SetBootMountDir(Task):
description = 'Setting mountpoint for the boot partition' description = 'Setting mountpoint for the boot partition'
phase = phases.volume_mounting phase = phases.volume_mounting
after = [filesystem.MountRoot] predecessors = [filesystem.MountRoot]
before = [filesystem.MountBoot] successors = [filesystem.MountBoot]
def run(self, info): def run(self, info):
info.boot_dir = os.path.join(info.root, 'boot') info.boot_dir = os.path.join(info.root, 'boot')

View file

@ -8,7 +8,7 @@ import os
class DoSeds(Task): class DoSeds(Task):
description = 'Sedding files' description = 'Sedding files'
phase = phases.system_modification phase = phases.system_modification
after = [AptUpgrade] predecessors = [AptUpgrade]
def run(self, info): def run(self, info):
chroot_path = os.path.join(info.root, info.manifest.plugins['sed']['file']) chroot_path = os.path.join(info.root, info.manifest.plugins['sed']['file'])

View file

@ -7,8 +7,8 @@ from common.tasks.host import CheckPackages
class AddUnattendedUpgradesPackage(Task): class AddUnattendedUpgradesPackage(Task):
description = 'Adding ``unattended-upgrades\'\' to the image packages' description = 'Adding ``unattended-upgrades\'\' to the image packages'
phase = phases.preparation phase = phases.preparation
after = [ImagePackages] predecessors = [ImagePackages]
before = [CheckPackages] successors = [CheckPackages]
def run(self, info): def run(self, info):
info.img_packages[0].add('unattended-upgrades') info.img_packages[0].add('unattended-upgrades')

View file

@ -9,8 +9,8 @@ from common.tasks.filesystem import MountRoot
class AddUserPackages(Task): class AddUserPackages(Task):
description = 'Adding user defined packages to the image packages' description = 'Adding user defined packages to the image packages'
phase = phases.preparation phase = phases.preparation
after = [ImagePackages] predecessors = [ImagePackages]
before = [CheckPackages] successors = [CheckPackages]
def run(self, info): def run(self, info):
if 'repo' not in info.manifest.plugins['user_packages']: if 'repo' not in info.manifest.plugins['user_packages']:
@ -22,7 +22,7 @@ class AddUserPackages(Task):
class AddLocalUserPackages(Task): class AddLocalUserPackages(Task):
description = 'Adding user local packages to the image packages' description = 'Adding user local packages to the image packages'
phase = phases.system_modification phase = phases.system_modification
after = [MountRoot] predecessors = [MountRoot]
def run(self, info): def run(self, info):
if 'local' not in info.manifest.plugins['user_packages']: if 'local' not in info.manifest.plugins['user_packages']:

View file

@ -13,7 +13,7 @@ cert_ec2 = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/c
class AMIName(Task): class AMIName(Task):
description = 'Determining the AMI name' description = 'Determining the AMI name'
phase = phases.preparation phase = phases.preparation
after = [Connect] predecessors = [Connect]
def run(self, info): def run(self, info):
image_vars = {'release': info.manifest.system['release'], image_vars = {'release': info.manifest.system['release'],
@ -60,7 +60,7 @@ class BundleImage(Task):
class UploadImage(Task): class UploadImage(Task):
description = 'Uploading the image bundle' description = 'Uploading the image bundle'
phase = phases.image_registration phase = phases.image_registration
after = [BundleImage] predecessors = [BundleImage]
def run(self, info): def run(self, info):
manifest_file = os.path.join(info.bundle_path, info.ami_name + '.manifest.xml') manifest_file = os.path.join(info.bundle_path, info.ami_name + '.manifest.xml')
@ -81,7 +81,7 @@ class UploadImage(Task):
class RemoveBundle(Task): class RemoveBundle(Task):
description = 'Removing the bundle files' description = 'Removing the bundle files'
phase = phases.cleaning phase = phases.cleaning
before = [workspace.DeleteWorkspace] successors = [workspace.DeleteWorkspace]
def run(self, info): def run(self, info):
from shutil import rmtree from shutil import rmtree
@ -92,7 +92,7 @@ class RemoveBundle(Task):
class RegisterAMI(Task): class RegisterAMI(Task):
description = 'Registering the image as an AMI' description = 'Registering the image as an AMI'
phase = phases.image_registration phase = phases.image_registration
after = [Snapshot, UploadImage] predecessors = [Snapshot, UploadImage]
# Source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedKernels.html#AmazonKernelImageIDs # Source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedKernels.html#AmazonKernelImageIDs
kernel_mapping = {'ap-northeast-1': { # Asia Pacific (Tokyo) Region kernel_mapping = {'ap-northeast-1': { # Asia Pacific (Tokyo) Region

View file

@ -34,7 +34,7 @@ class GetCredentials(Task):
class Connect(Task): class Connect(Task):
description = 'Connecting to EC2' description = 'Connecting to EC2'
phase = phases.preparation phase = phases.preparation
after = [GetCredentials, host.GetInfo] predecessors = [GetCredentials, host.GetInfo]
def run(self, info): def run(self, info):
from boto.ec2 import connect_to_region from boto.ec2 import connect_to_region

View file

@ -13,7 +13,7 @@ class Create(Task):
class Attach(Task): class Attach(Task):
description = 'Attaching the volume' description = 'Attaching the volume'
phase = phases.volume_creation phase = phases.volume_creation
after = [Create] predecessors = [Create]
def run(self, info): def run(self, info):
info.volume.attach(info.host['instanceId']) info.volume.attach(info.host['instanceId'])

View file

@ -8,8 +8,8 @@ import os.path
class AddEC2InitScripts(Task): class AddEC2InitScripts(Task):
description = 'Adding EC2 startup scripts' description = 'Adding EC2 startup scripts'
phase = phases.system_modification phase = phases.system_modification
after = [initd.ResolveInitScripts] predecessors = [initd.ResolveInitScripts]
before = [initd.InstallInitScripts] successors = [initd.InstallInitScripts]
def run(self, info): def run(self, info):
init_scripts = {'ec2-get-credentials': 'ec2-get-credentials', init_scripts = {'ec2-get-credentials': 'ec2-get-credentials',
@ -23,7 +23,7 @@ class AddEC2InitScripts(Task):
class AdjustExpandVolumeScript(Task): class AdjustExpandVolumeScript(Task):
description = 'Adjusting the expand-volume script' description = 'Adjusting the expand-volume script'
phase = phases.system_modification phase = phases.system_modification
after = [initd.InstallInitScripts] predecessors = [initd.InstallInitScripts]
def run(self, info): def run(self, info):
if 'expand-volume' not in info.initd['install']: if 'expand-volume' not in info.initd['install']:

View file

@ -7,8 +7,8 @@ from common.tasks.host import CheckPackages
class HostPackages(Task): class HostPackages(Task):
description = 'Adding more required host packages' description = 'Adding more required host packages'
phase = phases.preparation phase = phases.preparation
before = [CheckPackages] predecessors = [packages.HostPackages]
after = [packages.HostPackages] successors = [CheckPackages]
def run(self, info): def run(self, info):
if info.manifest.volume['backing'] == 's3': if info.manifest.volume['backing'] == 's3':
@ -18,7 +18,7 @@ class HostPackages(Task):
class ImagePackages(Task): class ImagePackages(Task):
description = 'Adding more required image packages' description = 'Adding more required image packages'
phase = phases.preparation phase = phases.preparation
after = [packages.ImagePackages] predecessors = [packages.ImagePackages]
def run(self, info): def run(self, info):
manifest = info.manifest manifest = info.manifest

View file

@ -7,7 +7,7 @@ from common.fs.loopbackvolume import LoopbackVolume
class ConfigureGrub(Task): class ConfigureGrub(Task):
description = 'Configuring grub' description = 'Configuring grub'
phase = phases.system_modification phase = phases.system_modification
after = [apt.AptUpgrade] predecessors = [apt.AptUpgrade]
def run(self, info): def run(self, info):
import os import os

View file

@ -6,7 +6,7 @@ from common.tasks import packages
class ImagePackages(Task): class ImagePackages(Task):
description = 'Determining required image packages' description = 'Determining required image packages'
phase = phases.preparation phase = phases.preparation
after = [packages.ImagePackages] predecessors = [packages.ImagePackages]
def run(self, info): def run(self, info):
manifest = info.manifest manifest = info.manifest