From 3726d72c68c96a1ce40c2cc568a34d796f4eb71f Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Mon, 1 Jul 2013 20:48:51 +0200 Subject: [PATCH] Implemented MountSpecials --- providers/ec2/__init__.py | 2 ++ providers/ec2/tasks/filesystem.py | 38 ++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/providers/ec2/__init__.py b/providers/ec2/__init__.py index f998eaf..c741131 100644 --- a/providers/ec2/__init__.py +++ b/providers/ec2/__init__.py @@ -22,6 +22,7 @@ def tasks(tasklist, manifest): if manifest.bootstrapper['tarball']: tasklist.add(bootstrap.MakeTarball()) tasklist.add(bootstrap.Bootstrap()) + tasklist.add(filesystem.MountSpecials()) from common.tasks import TriggerRollback tasklist.add(TriggerRollback()) @@ -39,3 +40,4 @@ def rollback_tasks(tasklist, tasks_completed, manifest): counter_task(ebs.AttachVolume, ebs.DetachVolume) counter_task(filesystem.CreateMountDir, filesystem.DeleteMountDir) counter_task(filesystem.MountVolume, filesystem.UnmountVolume) + counter_task(filesystem.MountSpecials, filesystem.UnmountSpecials) diff --git a/providers/ec2/tasks/filesystem.py b/providers/ec2/tasks/filesystem.py index a248cd5..f298e54 100644 --- a/providers/ec2/tasks/filesystem.py +++ b/providers/ec2/tasks/filesystem.py @@ -1,8 +1,12 @@ from base import Task from common import phases from common.exceptions import TaskError +from common.tools import log_command +from bootstrap import Bootstrap import subprocess import os +import logging +log = logging.getLogger(__name__) class FormatVolume(Task): @@ -57,7 +61,7 @@ class MountVolume(Task): with open('/proc/mounts') as mounts: for mount in mounts: if info.root in mount: - msg = 'Something is already mount at {root}'.format(root=info.root) + msg = 'Something is already mounted at {root}'.format(root=info.root) raise TaskError(msg) dev_path = info.bootstrap_device['path'] @@ -65,9 +69,41 @@ class MountVolume(Task): subprocess.check_call(['mount', dev_path, info.root], stdout=dev_null, stderr=dev_null) +class MountSpecials(Task): + description = 'Mounting special block devices' + phase = phases.os_installation + after = [Bootstrap] + + def run(self, info): + if log_command(['mount', '--bind', '/dev', '{root}/dev'.format(root=info.root)], log) != 0: + raise TaskError('Failed to bind /dev to {root}/dev'.format(root=info.root)) + if log_command(['chroot', info.root, 'mount', '-t', 'proc', 'none', '/proc'], log) != 0: + raise TaskError('Failed to mount /proc') + if log_command(['chroot', info.root, 'mount', '-t', 'sysfs', 'none', '/sys'], log) != 0: + raise TaskError('Failed to mount /sys') + if log_command(['chroot', info.root, 'mount', '-t', 'devpts', 'none', '/dev/pts'], log) != 0: + raise TaskError('Failed to mount /dev/pts') + + +class UnmountSpecials(Task): + description = 'Unmunting special block devices' + phase = phases.volume_unmounting + + def run(self, info): + if log_command(['chroot', info.root, 'umount', '/dev/pts'], log) != 0: + raise TaskError('Failed to unmount /dev/pts') + if log_command(['chroot', info.root, 'umount', '/sys'], log) != 0: + raise TaskError('Failed to unmount /sys') + if log_command(['chroot', info.root, 'umount', '/proc'], log) != 0: + raise TaskError('Failed to unmount /proc') + if log_command(['umount', '{root}/dev'.format(root=info.root)], log) != 0: + raise TaskError('Failed to unmount /dev from {root}/dev'.format(root=info.root)) + + class UnmountVolume(Task): description = 'Unmounting the bootstrap volume' phase = phases.volume_unmounting + after = [UnmountSpecials] def run(self, info): with open(os.devnull, 'w') as dev_null: