From 387aa62750d9478ae2c03c1fb93bbf71bc2bd91a Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Fri, 4 Oct 2013 21:12:48 +0200 Subject: [PATCH] Remove FSM from NoPartitions p-map Don't set the volume device_path by calling 'create' --- base/fs/partitionmaps/none.py | 14 +------------- base/fs/partitions/single.py | 4 +++- base/fs/volume.py | 10 ++++++++-- plugins/prebootstrapped/tasks.py | 1 - 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/base/fs/partitionmaps/none.py b/base/fs/partitionmaps/none.py index cc9a8b0..1b2cfd8 100644 --- a/base/fs/partitionmaps/none.py +++ b/base/fs/partitionmaps/none.py @@ -1,27 +1,15 @@ from ..partitions.single import SinglePartition -from common.fsm_proxy import FSMProxy -class NoPartitions(FSMProxy): - - events = [{'name': 'create', 'src': 'nonexistent', 'dst': 'created'}] +class NoPartitions(object): def __init__(self, data): root = data['root'] self.root = SinglePartition(root['size'], root['filesystem']) self.partitions = [self.root] - cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': {}} - super(NoPartitions, self).__init__(cfg) - def is_blocking(self): return self.root.is_blocking() def get_total_size(self): return self.root.size - - def create(self, volume): - self.fsm.create(volume=volume) - - def _before_create(self, event): - self.root.create(event.volume) diff --git a/base/fs/partitions/single.py b/base/fs/partitions/single.py index b7905ea..5ac3ec5 100644 --- a/base/fs/partitions/single.py +++ b/base/fs/partitions/single.py @@ -3,5 +3,7 @@ from abstract import AbstractPartition class SinglePartition(AbstractPartition): + initial_state = 'created' + def _before_create(self, e): - self.device_path = e.volume.device_path + pass diff --git a/base/fs/volume.py b/base/fs/volume.py index 7df9778..209fa6d 100644 --- a/base/fs/volume.py +++ b/base/fs/volume.py @@ -2,6 +2,7 @@ from abc import ABCMeta from common.fsm_proxy import FSMProxy from common.tools import log_check_call from exceptions import VolumeError +from partitionmaps.none import NoPartitions class Volume(FSMProxy): @@ -21,13 +22,18 @@ class Volume(FSMProxy): self.size = self.partition_map.get_total_size() callbacks = {'onbeforedetach': self._check_blocking} - from partitionmaps.none import NoPartitions if isinstance(self.partition_map, NoPartitions): - callbacks['onafterattach'] = lambda e: self.partition_map.create(self) + def set_dev_path(e): + self.partition_map.root.device_path = self.device_path + callbacks['onafterattach'] = set_dev_path cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': callbacks} super(Volume, self).__init__(cfg) + def _after_create(self, e): + if isinstance(self.partition_map, NoPartitions): + self.partition_map.root.create() + def can_mount_specials(self): return self.is_state('attached') diff --git a/plugins/prebootstrapped/tasks.py b/plugins/prebootstrapped/tasks.py index 38d5275..1e5f184 100644 --- a/plugins/prebootstrapped/tasks.py +++ b/plugins/prebootstrapped/tasks.py @@ -73,7 +73,6 @@ def set_fs_states(volume): partitions_state = 'attached' from base.fs.partitionmaps.none import NoPartitions if isinstance(p_map, NoPartitions): - p_map.set_state('created') partitions_state = 'formatted' else: p_map.set_state('unmapped')