counter tasks for CreateMountDir and MountVolume

This commit is contained in:
Anders Ingemann 2013-06-27 22:21:43 +02:00
parent 4d86ae5bea
commit 9aae74b0fa
3 changed files with 34 additions and 6 deletions

View file

@ -25,8 +25,13 @@ def tasks(tasklist, manifest):
def rollback_tasks(tasklist, tasks_completed, manifest):
completed = [type(task) for task in tasks_completed]
def counter_task(task, counter):
if task in completed and counter not in completed:
tasklist.add(counter())
if manifest.volume['backing'].lower() == 'ebs':
if ebs.CreateVolume in completed and ebs.DeleteVolume not in completed:
tasklist.add(ebs.DeleteVolume())
if ebs.AttachVolume in completed and ebs.DetachVolume not in completed:
tasklist.add(ebs.DetachVolume())
counter_task(ebs.CreateVolume, ebs.DeleteVolume)
counter_task(ebs.AttachVolume, ebs.DetachVolume)
counter_task(filesystem.CreateMountDir, filesystem.DeleteMountDir)
counter_task(filesystem.MountVolume, filesystem.UnmountVolume)

View file

@ -2,6 +2,7 @@ from base import Task
from common import phases
from common.exceptions import TaskError
from connection import Connect
from filesystem import UnmountVolume
import time
@ -57,7 +58,7 @@ class AttachVolume(Task):
class DetachVolume(Task):
phase = phases.volume_unmounting
after = []
after = [UnmountVolume]
description = 'Detaching the EBS volume'

View file

@ -51,7 +51,7 @@ class CreateMountDir(Task):
class MountVolume(Task):
description = 'Creating mountpoint for the bootstrap volume'
description = 'Mounting the bootstrap volume'
phase = phases.volume_mounting
after = [CreateMountDir]
@ -67,3 +67,25 @@ class MountVolume(Task):
dev_path = info.bootstrap_device['path']
with open(devnull, 'w') as dev_null:
subprocess.check_call(['mount', dev_path, info.root], stdout=dev_null, stderr=dev_null)
class UnmountVolume(Task):
description = 'Unmounting the bootstrap volume'
phase = phases.volume_unmounting
def run(self, info):
import subprocess
from os import devnull
with open(devnull, 'w') as dev_null:
subprocess.check_call(['umount', info.root], stdout=dev_null, stderr=dev_null)
class DeleteMountDir(Task):
description = 'Deleting mountpoint for the bootstrap volume'
phase = phases.volume_unmounting
after = [UnmountVolume]
def run(self, info):
import os
os.rmdir(info.root)
del info.root