Remove FSM from NoPartitions p-map

Don't set the volume device_path by calling 'create'
This commit is contained in:
Anders Ingemann 2013-10-04 21:12:48 +02:00
parent ba1842ca2b
commit 387aa62750
4 changed files with 12 additions and 17 deletions

View file

@ -1,27 +1,15 @@
from ..partitions.single import SinglePartition from ..partitions.single import SinglePartition
from common.fsm_proxy import FSMProxy
class NoPartitions(FSMProxy): class NoPartitions(object):
events = [{'name': 'create', 'src': 'nonexistent', 'dst': 'created'}]
def __init__(self, data): def __init__(self, data):
root = data['root'] root = data['root']
self.root = SinglePartition(root['size'], root['filesystem']) self.root = SinglePartition(root['size'], root['filesystem'])
self.partitions = [self.root] self.partitions = [self.root]
cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': {}}
super(NoPartitions, self).__init__(cfg)
def is_blocking(self): def is_blocking(self):
return self.root.is_blocking() return self.root.is_blocking()
def get_total_size(self): def get_total_size(self):
return self.root.size return self.root.size
def create(self, volume):
self.fsm.create(volume=volume)
def _before_create(self, event):
self.root.create(event.volume)

View file

@ -3,5 +3,7 @@ from abstract import AbstractPartition
class SinglePartition(AbstractPartition): class SinglePartition(AbstractPartition):
initial_state = 'created'
def _before_create(self, e): def _before_create(self, e):
self.device_path = e.volume.device_path pass

View file

@ -2,6 +2,7 @@ from abc import ABCMeta
from common.fsm_proxy import FSMProxy from common.fsm_proxy import FSMProxy
from common.tools import log_check_call from common.tools import log_check_call
from exceptions import VolumeError from exceptions import VolumeError
from partitionmaps.none import NoPartitions
class Volume(FSMProxy): class Volume(FSMProxy):
@ -21,13 +22,18 @@ class Volume(FSMProxy):
self.size = self.partition_map.get_total_size() self.size = self.partition_map.get_total_size()
callbacks = {'onbeforedetach': self._check_blocking} callbacks = {'onbeforedetach': self._check_blocking}
from partitionmaps.none import NoPartitions
if isinstance(self.partition_map, 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} cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': callbacks}
super(Volume, self).__init__(cfg) 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): def can_mount_specials(self):
return self.is_state('attached') return self.is_state('attached')

View file

@ -73,7 +73,6 @@ def set_fs_states(volume):
partitions_state = 'attached' partitions_state = 'attached'
from base.fs.partitionmaps.none import NoPartitions from base.fs.partitionmaps.none import NoPartitions
if isinstance(p_map, NoPartitions): if isinstance(p_map, NoPartitions):
p_map.set_state('created')
partitions_state = 'formatted' partitions_state = 'formatted'
else: else:
p_map.set_state('unmapped') p_map.set_state('unmapped')