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

View file

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

View file

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

View file

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