* added some triggers for refreshing the cache after partitioning

* added more error checking for unavailable devices
* fixed a wrong template name
This commit is contained in:
lars 2009-06-11 09:32:41 +00:00
parent 7b0de22e3a
commit 94102a3575

View file

@ -70,7 +70,7 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin):
if not self.blockdevice:
return self.__action_select_device()
## exit if the blockdevice is not writeable
if not os.access(self.blockdevice.devnodes[0], os.W_OK):
if not os.access(self.blockdevice.get_device(), os.W_OK):
self.hdf["Data.Warning"] = "DeviceNotWriteable"
return self.__action_select_device()
## no confirm setting?
@ -191,7 +191,7 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin):
self.hdf[self.hdf_prefix + "BlockDevices.%d.size" % counter] = \
dev.size_human
self.cbox.log.debug("found a suitable block device: %s" % \
dev.devnodes[0])
dev.get_device())
counter += 1
if self.with_config_partition:
self.hdf[self.hdf_prefix + "CreateConfigPartition"] = "1"
@ -273,6 +273,7 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin):
## return the result
if not result:
format_ok = False
self.cbox.reread_container_list()
if format_ok:
self.hdf["Data.Success"] = "Plugins.partition.Partitioned"
return { "plugin":"system_preferences", "values":[] }
@ -311,7 +312,7 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin):
## operation failed
self.hdf["Data.Warning"] = "Plugins.partition.FormattingFailed"
self.cbox.log.info("easy partitioning failed")
return "select_partitions"
return "set_partitions"
else:
## operation was successful
self.hdf["Data.Success"] = "Plugins.partition.EasySetup"
@ -429,7 +430,7 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin):
"plugin",
os.path.join(self.plugin_dir, "root_action.py"),
"partition",
self.blockdevice.devnodes[0]])
self.blockdevice.get_device()])
for line in self.__get_sfdisk_layout(parts, is_filled):
proc.stdin.write(line + "\n")
#TODO: if running inside of an uml, then sfdisk hangs at "nanosleep({3,0})"
@ -453,11 +454,15 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin):
"plugin",
os.path.join(self.plugin_dir, "root_action.py"),
"rereadpt",
self.blockdevice.devnodes[0]])
self.blockdevice.get_device()])
(output, error) = rereadpt_proc.communicate()
rereadpt_status = rereadpt_proc.returncode
if rereadpt_status != 0:
self.cbox.log.info("failed to reread the modified partition table: %s" % error)
# refresh the device list
self.cbox.reread_container_list()
# update the blockdevice - especially the new partitioned children
self.blockdevice.reset()
return (fdisk_status == 0)
@ -536,17 +541,23 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin):
## filter the storage devices
for child in blockdev.children:
childdev = blockdevice_tools.get_blockdevice(child)
self.cbox.log.debug("Checking child device: %s - %s" % \
(blockdev, child))
if childdev and childdev.is_storage():
valid_children.append(childdev)
sorted = blockdevice_tools.get_sorted_devices(valid_children)
if number <= len(sorted):
childdev = sorted[number-1]
valid_children.sort()
self.cbox.log.debug("Valid children of %s: %s" % \
(blockdev, [child.name for child in valid_children]))
if number <= len(valid_children):
childdev = valid_children[number-1]
if childdev:
return childdev.devnodes[0]
self.cbox.log.warn("Failed to get the partition name (%s, %d)" % \
(blockdev, number))
return childdev.get_device()
## return some guessed value - we should never get here ...
return "%s%d" % (blockdev.devnodes[0], number)
guess = "%s%d" % (blockdev.get_device(), number)
self.cbox.log.warn("Failed to get the partition name (%s, %d)" % \
(blockdev, number) + " - proceeding with guessed name: %s" % \
guess)
return guess
def __format_one_partition(self, dev_name, fs_type):
@ -559,8 +570,13 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin):
## call "mkfs"
try:
format_dev = blockdevice_tools.get_blockdevice(dev_name)
cont = cryptobox.core.container.CryptoBoxContainer(format_dev, self.cbox)
cont.create(cryptobox.core.container.CONTAINERTYPES["plain"], fs_type=fs_type)
if format_dev is None:
self.cbox.log.warn("Could not find the specified device: %s" % \
str(format_dev))
return False
else:
cont = cryptobox.core.container.CryptoBoxContainer(format_dev, self.cbox)
cont.create(cryptobox.core.container.CONTAINERTYPES["plain"], fs_type=fs_type)
except (CBInvalidType, CBCreateError, CBVolumeIsActive), err_msg:
self.cbox.log.warn(err_msg)
return False