Implemented MountSpecials

This commit is contained in:
Anders Ingemann 2013-07-01 20:48:51 +02:00
parent 25a017fa35
commit 3726d72c68
2 changed files with 39 additions and 1 deletions

View file

@ -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)

View file

@ -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: