def _create_btrfs_volume(self, user_input): actions = [] device_name = self._pick_device_name(user_input.name) for parent, size in user_input.parents: # _create_partition needs user_input but we actually don't have it for individual # parent partitions so we need to 'create' it part_input = ProxyDataContainer(size=size, parents=[(parent, size)], filesystem="btrfs", encrypt=False, label=None, mountpoint=None, create_volume=False) part_actions = self._create_partition(part_input) # we need to try to create partitions immediately, if something # fails, fail now for ac in part_actions: self.storage.devicetree.actions.add(ac) actions.extend(part_actions) btrfs_parents = [ac.device for ac in actions if (ac.is_format and ac.is_create) and ac._format.type == "btrfs"] new_btrfs = BTRFSVolumeDevice(device_name, parents=btrfs_parents) new_btrfs.format = blivet.formats.get_format("btrfs", label=device_name, mountpoint=user_input.mountpoint) actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs)) return actions
def testBTRFSSnapShotDeviceInit(self): parents = [StorageDevice("p1", fmt=blivet.formats.getFormat("btrfs"))] vol = BTRFSVolumeDevice("test", parents=parents) with self.assertRaisesRegexp(ValueError, "non-existent btrfs snapshots must have a source"): BTRFSSnapShotDevice("snap1", parents=[vol]) with self.assertRaisesRegexp(ValueError, "btrfs snapshot source must already exist"): BTRFSSnapShotDevice("snap1", parents=[vol], source=vol) with self.assertRaisesRegexp(ValueError, "btrfs snapshot source must be a btrfs subvolume"): BTRFSSnapShotDevice("snap1", parents=[vol], source=parents[0]) parents2 = [StorageDevice("p1", fmt=blivet.formats.getFormat("btrfs"))] vol2 = BTRFSVolumeDevice("test2", parents=parents2, exists=True) with self.assertRaisesRegexp(ValueError, ".*snapshot and source must be in the same volume"): BTRFSSnapShotDevice("snap1", parents=[vol], source=vol2) vol.exists = True snap = BTRFSSnapShotDevice("snap1", parents=[vol], source=vol) self.assertEqual(snap.isleaf, True) self.assertEqual(snap.direct, True) self.assertEqual(vol.isleaf, False) self.assertEqual(vol.direct, True) self.assertEqual(snap.dependsOn(vol), True) self.assertEqual(vol.dependsOn(snap), False)
def setUp(self): self._state_functions = { "currentSize": lambda x, m: self.assertEqual(x, Size(bytes=0), m), "exists": self.assertFalse, "format": self.assertIsNotNone, "formatArgs": lambda x, m: self.assertEqual(x, [], m), "fstabSpec": self.assertIsNotNone, "isDisk": self.assertFalse, "major": lambda x, m: self.assertEqual(x, 0, m), "maxSize": lambda x, m: self.assertEqual(x, Size(bytes=0), m), "mediaPresent": self.assertTrue, "minor": lambda x, m: self.assertEqual(x, 0, m), "parents": lambda x, m: self.assertEqual(len(x), 0, m) and self. assertIsInstance(x, ParentList, m), "partitionable": self.assertFalse, "path": lambda x, m: self.assertRegexpMatches(x, "^/dev", m), "resizable": lambda x, m: self.assertFalse, "size": lambda x, m: self.assertEqual(x, Size(bytes=0), m), "status": self.assertFalse, "sysfsPath": lambda x, m: self.assertEqual(x, "", m), "targetSize": lambda x, m: self.assertEqual(x, Size(bytes=0), m), "type": lambda x, m: self.assertEqual(x, "btrfs", m), "uuid": self.assertIsNone, "vol_id": lambda x, m: self.assertEqual(x, btrfs.MAIN_VOLUME_ID, m) } self.dev1 = BTRFSVolumeDevice( "dev1", parents=[ OpticalDevice("deva", format=blivet.formats.getFormat("btrfs")) ]) self.dev2 = BTRFSSubVolumeDevice("dev2", parents=[self.dev1]) dev = StorageDevice("deva", format=blivet.formats.getFormat("btrfs"), size=Size(spec="32 MiB")) self.dev3 = BTRFSVolumeDevice("dev3", parents=[dev])
def _create_btrfs_format(self, user_input, device): actions = [] # format the device to btrfs btrfs_fmt = blivet.formats.get_format(fmt_type="btrfs") actions.append(blivet.deviceaction.ActionCreateFormat(device, btrfs_fmt)) if getattr(user_input, "create_volume", True): device.format = btrfs_fmt new_btrfs = BTRFSVolumeDevice(parents=[device]) new_btrfs.format = blivet.formats.get_format("btrfs", label=user_input.label, mountpoint=user_input.mountpoint) actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs)) return actions
def setUp(self): self.dev1 = BTRFSVolumeDevice("dev1", parents=[StorageDevice("deva", fmt=blivet.formats.getFormat("btrfs"), size=btrfs.MIN_MEMBER_SIZE)]) self.dev2 = BTRFSSubVolumeDevice("dev2", parents=[self.dev1], fmt=blivet.formats.getFormat("btrfs")) dev = StorageDevice("deva", fmt=blivet.formats.getFormat("btrfs"), size=Size("32 MiB")) self.dev3 = BTRFSVolumeDevice("dev3", parents=[dev])
def test_btrfssnap_shot_device_init(self): parents = [StorageDevice("p1", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE)] vol = BTRFSVolumeDevice("test", parents=parents) with self.assertRaisesRegex(ValueError, "non-existent btrfs snapshots must have a source"): BTRFSSnapShotDevice("snap1", parents=[vol]) with self.assertRaisesRegex(ValueError, "btrfs snapshot source must already exist"): BTRFSSnapShotDevice("snap1", parents=[vol], source=vol) with self.assertRaisesRegex(ValueError, "btrfs snapshot source must be a btrfs subvolume"): BTRFSSnapShotDevice("snap1", parents=[vol], source=parents[0]) parents2 = [StorageDevice("p1", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE, exists=True)] vol2 = BTRFSVolumeDevice("test2", parents=parents2, exists=True) with self.assertRaisesRegex(ValueError, ".*snapshot and source must be in the same volume"): BTRFSSnapShotDevice("snap1", parents=[vol], source=vol2) vol.exists = True snap = BTRFSSnapShotDevice("snap1", fmt=blivet.formats.get_format("btrfs"), parents=[vol], source=vol) self.state_check(snap, current_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), target_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), max_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), parents=xform(lambda x, m: self.assertEqual(len(x), 1, m)), size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), type=xform(lambda x, m: self.assertEqual(x, "btrfs snapshot", m)), vol_id=xform(self.assertIsNone)) self.state_check(vol, current_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), data_level=xform(self.assertIsNone), exists=xform(self.assertTrue), isleaf=xform(self.assertFalse), max_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), metadata_level=xform(self.assertIsNone), parents=xform(lambda x, m: self.assertEqual(len(x), 1, m)), size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), type=xform(lambda x, m: self.assertEqual(x, "btrfs volume", m))) self.assertEqual(snap.isleaf, True) self.assertEqual(snap.direct, True) self.assertEqual(vol.isleaf, False) self.assertEqual(vol.direct, True) self.assertEqual(snap.depends_on(vol), True) self.assertEqual(vol.depends_on(snap), False)
def test_btrfssnap_shot_device_init(self): parents = [StorageDevice("p1", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE)] vol = BTRFSVolumeDevice("test", parents=parents) with six.assertRaisesRegex(self, ValueError, "non-existent btrfs snapshots must have a source"): BTRFSSnapShotDevice("snap1", parents=[vol]) with six.assertRaisesRegex(self, ValueError, "btrfs snapshot source must already exist"): BTRFSSnapShotDevice("snap1", parents=[vol], source=vol) with six.assertRaisesRegex(self, ValueError, "btrfs snapshot source must be a btrfs subvolume"): BTRFSSnapShotDevice("snap1", parents=[vol], source=parents[0]) parents2 = [StorageDevice("p1", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE, exists=True)] vol2 = BTRFSVolumeDevice("test2", parents=parents2, exists=True) with six.assertRaisesRegex(self, ValueError, ".*snapshot and source must be in the same volume"): BTRFSSnapShotDevice("snap1", parents=[vol], source=vol2) vol.exists = True snap = BTRFSSnapShotDevice("snap1", fmt=blivet.formats.get_format("btrfs"), parents=[vol], source=vol) self.state_check(snap, current_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), target_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), max_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), parents=xform(lambda x, m: self.assertEqual(len(x), 1, m)), size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), type=xform(lambda x, m: self.assertEqual(x, "btrfs snapshot", m)), vol_id=xform(self.assertIsNone)) self.state_check(vol, current_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), data_level=xform(self.assertIsNone), exists=xform(self.assertTrue), isleaf=xform(self.assertFalse), max_size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), metadata_level=xform(self.assertIsNone), parents=xform(lambda x, m: self.assertEqual(len(x), 1, m)), size=xform(lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), type=xform(lambda x, m: self.assertEqual(x, "btrfs volume", m))) self.assertEqual(snap.isleaf, True) self.assertEqual(snap.direct, True) self.assertEqual(vol.isleaf, False) self.assertEqual(vol.direct, True) self.assertEqual(snap.depends_on(vol), True) self.assertEqual(vol.depends_on(snap), False)
def test_generate_device_factory_request_btrfs(self, blockdev): dev1 = StorageDevice("dev1", fmt=get_format("btrfs"), size=Size("10 GiB")) dev2 = BTRFSVolumeDevice("dev2", data_level="single", parents=[dev1]) dev3 = BTRFSSubVolumeDevice( parents=[dev2], fmt=get_format("btrfs", mountpoint="/boot"), ) request = utils.generate_device_factory_request(self.storage, dev3) assert DeviceFactoryRequest.to_structure(request) == { "device-spec": get_variant(Str, dev3.name), "disks": get_variant(List[Str], []), "mount-point": get_variant(Str, "/boot"), "reformat": get_variant(Bool, True), "format-type": get_variant(Str, "btrfs"), "label": get_variant(Str, ""), "luks-version": get_variant(Str, ""), "device-type": get_variant(Int, devicefactory.DEVICE_TYPE_BTRFS), "device-name": get_variant(Str, dev3.name), "device-size": get_variant(UInt64, Size("10 GiB").get_bytes()), "device-encrypted": get_variant(Bool, False), "device-raid-level": get_variant(Str, ""), "container-spec": get_variant(Str, dev2.name), "container-name": get_variant(Str, dev2.name), "container-size-policy": get_variant(Int64, Size("10 GiB").get_bytes()), "container-encrypted": get_variant(Bool, False), "container-raid-level": get_variant(Str, "single"), }
def test_generate_device_factory_permissions_btrfs(self): """Test GenerateDeviceFactoryPermissions with btrfs.""" dev1 = StorageDevice("dev1", fmt=get_format("btrfs"), size=Size("10 GiB")) dev2 = BTRFSVolumeDevice("dev2", size=Size("5 GiB"), parents=[dev1]) self._add_device(dev1) self._add_device(dev2) # Make the btrfs format not mountable. with patch.object(BTRFS, "_mount_class", return_value=Mock(available=False)): request = self.interface.GenerateDeviceFactoryRequest(dev2.name) permissions = self.interface.GenerateDeviceFactoryPermissions( request) assert get_native(permissions) == { 'mount-point': False, 'reformat': False, 'format-type': False, 'label': False, 'device-type': True, 'device-name': False, 'device-size': False, 'device-encrypted': False, 'device-raid-level': True, 'disks': False, 'container-spec': False, 'container-name': True, 'container-size-policy': True, 'container-encrypted': True, 'container-raid-level': True, }
def setUp(self): """Create some device objects to test with. This sets up two disks (sda, sdb). The first partition of each is a biosboot partition. The second partitions comprise a RAID1 array formatted as /boot. sda additionally contains a third partition formatted as ext4. """ super(GRUBRaidSimpleTest, self).setUp() # Make some disks self.sda = DiskDevice(name="sda", size=Size("100 GiB")) self.sda.format = getFormat("disklabel") self.sdb = DiskDevice(name="sdb", size=Size("100 GiB")) self.sdb.format = getFormat("disklabel") # Set up biosboot partitions, an mdarray for /boot, and a btrfs array on sda + sdb. # Start with the partitions self.sda1 = PartitionDevice(name="sda1", parents=[self.sda], size=Size("1 MiB")) self.sda1.format = getFormat("biosboot") self.sda2 = PartitionDevice(name="sda2", parents=[self.sda], size=Size("500 MiB")) self.sda2.format = getFormat("mdmember") self.sda4 = PartitionDevice(name="sda4", parents=[self.sda], size=Size("500 MiB")) self.sda4.format = getFormat("btrfs") self.sdb1 = PartitionDevice(name="sdb1", parents=[self.sdb], size=Size("1 MiB")) self.sdb1.format = getFormat("biosboot") self.sdb2 = PartitionDevice(name="sdb2", parents=[self.sdb], size=Size("500 MiB")) self.sdb2.format = getFormat("mdmember") self.sdb4 = PartitionDevice(name="sdb4", parents=[self.sdb], size=Size("4 GiB")) self.sdb4.format = getFormat("btrfs") # Add an extra partition for /boot on not-RAID self.sda3 = PartitionDevice(name="sda3", parents=[self.sda], size=Size("500 MiB")) self.sda3.format = getFormat("ext4", mountpoint="/boot") # Pretend that the partitions are real with real parent disks for part in (self.sda1, self.sda2, self.sda3, self.sda4, self.sdb1, self.sdb2, self.sdb4): part.parents = part.req_disks self.boot_md = MDRaidArrayDevice(name="md1", parents=[self.sda2, self.sdb2], level=1) self.boot_md.format = getFormat("ext4", mountpoint="/boot") # Set up the btrfs raid1 volume with a subvolume for /boot self.btrfs_volume = BTRFSVolumeDevice(parents=[self.sda4, self.sdb4], dataLevel=RAID1) self.btrfs_volume.format = getFormat("btrfs") self.boot_btrfs = BTRFSSubVolumeDevice(parents=[self.btrfs_volume]) self.boot_btrfs.format = getFormat("btrfs", mountpoint="/boot") self.grub = GRUB()
def collect_containers_test(self): """Test CollectContainers.""" dev1 = StorageDevice("dev1", fmt=get_format("btrfs"), size=Size("10 GiB")) dev2 = BTRFSVolumeDevice("dev2", parents=[dev1]) self._add_device(dev1) self._add_device(dev2) self.assertEqual(self.interface.CollectContainers(DEVICE_TYPE_BTRFS), [dev2.name]) self.assertEqual(self.interface.CollectContainers(DEVICE_TYPE_LVM), [])
def generate_device_factory_permissions_btrfs_test(self): """Test GenerateDeviceFactoryPermissions with btrfs.""" dev1 = StorageDevice("dev1", fmt=get_format("btrfs"), size=Size("10 GiB")) dev2 = BTRFSVolumeDevice("dev2", size=Size("5 GiB"), parents=[dev1]) self._add_device(dev1) self._add_device(dev2) request = self.interface.GenerateDeviceFactoryRequest(dev2.name) permissions = self.interface.GenerateDeviceFactoryPermissions(request) self.assertEqual( get_native(permissions), { 'mount-point': True, 'reformat': False, 'format-type': False, 'label': True, 'device-type': True, 'device-name': False, 'device-size': False, 'device-encrypted': False, 'device-raid-level': True, })
def test_btrfsdevice_init(self): """Tests the state of a BTRFSDevice after initialization. For some combinations of arguments the initializer will throw an exception. """ self.state_check( self.dev1, current_size=xform( lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), data_level=xform(self.assertIsNone), isleaf=xform(self.assertFalse), max_size=xform( lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), metadata_level=xform(self.assertIsNone), parents=xform(lambda x, m: self.assertEqual(len(x), 1, m)), size=xform( lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), type=xform(lambda x, m: self.assertEqual(x, "btrfs volume", m))) self.state_check( self.dev2, target_size=xform( lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), current_size=xform( lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), max_size=xform( lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), parents=xform(lambda x, m: self.assertEqual(len(x), 1, m)), size=xform( lambda x, m: self.assertEqual(x, BTRFS_MIN_MEMBER_SIZE, m)), type=xform(lambda x, m: self.assertEqual(x, "btrfs subvolume", m)), vol_id=xform(self.assertIsNone)) self.state_check( self.dev3, current_size=xform( lambda x, m: self.assertEqual(x, Size("500 MiB"), m)), data_level=xform(self.assertIsNone), max_size=xform( lambda x, m: self.assertEqual(x, Size("500 MiB"), m)), metadata_level=xform(self.assertIsNone), parents=xform(lambda x, m: self.assertEqual(len(x), 1, m)), size=xform(lambda x, m: self.assertEqual(x, Size("500 MiB"), m)), type=xform(lambda x, m: self.assertEqual(x, "btrfs volume", m))) with six.assertRaisesRegex( self, ValueError, "BTRFSDevice.*must have at least one parent"): BTRFSVolumeDevice("dev") with six.assertRaisesRegex(self, ValueError, "format"): BTRFSVolumeDevice( "dev", parents=[StorageDevice("deva", size=BTRFS_MIN_MEMBER_SIZE)]) with six.assertRaisesRegex(self, DeviceError, "btrfs subvolume.*must be a btrfs volume"): fmt = blivet.formats.get_format("btrfs") device = StorageDevice("deva", fmt=fmt, size=BTRFS_MIN_MEMBER_SIZE) BTRFSSubVolumeDevice("dev1", parents=[device]) deva = OpticalDevice("deva", fmt=blivet.formats.get_format("btrfs", exists=True), exists=True) with six.assertRaisesRegex(self, BTRFSValueError, "at least"): BTRFSVolumeDevice("dev1", data_level="raid1", parents=[deva]) deva = StorageDevice("deva", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE) self.assertIsNotNone( BTRFSVolumeDevice("dev1", metadata_level="dup", parents=[deva])) deva = StorageDevice("deva", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE) with six.assertRaisesRegex(self, BTRFSValueError, "invalid"): BTRFSVolumeDevice("dev1", data_level="dup", parents=[deva]) self.assertEqual(self.dev1.isleaf, False) self.assertEqual(self.dev1.direct, True) self.assertEqual(self.dev2.isleaf, True) self.assertEqual(self.dev2.direct, True) member = self.dev1.parents[0] self.assertEqual(member.isleaf, False) self.assertEqual(member.direct, False)
def add_device(self, user_input): """ Create new device :param user_input: selected parameters from AddDialog :type user_input: class UserInput :returns: new device name :rtype: str """ actions = [] if user_input.device_type == "partition": if user_input.encrypt: dev = PartitionDevice( name="req%d" % self.storage.nextID, size=user_input.size, parents=[i[0] for i in user_input.parents]) actions.append(blivet.deviceaction.ActionCreateDevice(dev)) fmt = blivet.formats.getFormat( fmt_type="luks", passphrase=user_input.passphrase, device=dev.path) actions.append(blivet.deviceaction.ActionCreateFormat( dev, fmt)) luks_dev = LUKSDevice("luks-%s" % dev.name, fmt=blivet.formats.getFormat( user_input.filesystem, device=dev.path, mountpoint=user_input.mountpoint), size=dev.size, parents=[dev]) actions.append( blivet.deviceaction.ActionCreateDevice(luks_dev)) else: new_part = PartitionDevice( name="req%d" % self.storage.nextID, size=user_input.size, parents=[i[0] for i in user_input.parents], partType=PARTITION_TYPE[user_input.advanced["parttype"]]) actions.append( blivet.deviceaction.ActionCreateDevice(new_part)) if user_input.advanced["parttype"] != "extended": new_fmt = blivet.formats.getFormat( fmt_type=user_input.filesystem, label=user_input.label, mountpoint=user_input.mountpoint) actions.append( blivet.deviceaction.ActionCreateFormat( new_part, new_fmt)) elif user_input.device_type == "lvm" and not user_input.encrypt: device_name = self._pick_device_name(user_input.name) pvs = [] # exact total size of newly created pvs (future parents) total_size = blivet.size.Size("0 MiB") for parent, size in user_input.parents: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=size, parents=parent) ac_part = blivet.deviceaction.ActionCreateDevice(dev) fmt = blivet.formats.getFormat(fmt_type="lvmpv") ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt) actions.extend([ac_part, ac_fmt]) total_size += dev.size # we need to try to create pvs immediately, if something # fails, fail now try: for ac in (ac_part, ac_fmt): self.storage.devicetree.registerAction(ac) except blivet.errors.PartitioningError as e: return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) pvs.append(dev) new_vg = LVMVolumeGroupDevice(size=total_size, parents=pvs, name=device_name, peSize=user_input.advanced["pesize"]) actions.append(blivet.deviceaction.ActionCreateDevice(new_vg)) elif user_input.device_type == "lvm" and user_input.encrypt: device_name = self._pick_device_name(user_input.name) lukses = [] # exact total size of newly created pvs (future parents) total_size = blivet.size.Size("0 MiB") for parent, size in user_input.parents: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=user_input.size, parents=[parent]) ac_part = blivet.deviceaction.ActionCreateDevice(dev) fmt = blivet.formats.getFormat( fmt_type="luks", passphrase=user_input.passphrase, device=dev.path) ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt) luks_dev = LUKSDevice("luks-%s" % dev.name, fmt=blivet.formats.getFormat( "lvmpv", device=dev.path), size=dev.size, parents=[dev]) ac_luks = blivet.deviceaction.ActionCreateDevice(luks_dev) actions.extend([ac_part, ac_fmt, ac_luks]) total_size += luks_dev.size # we need to try to create pvs immediately, if something # fails, fail now try: for ac in (ac_part, ac_fmt, ac_luks): self.storage.devicetree.registerAction(ac) except blivet.errors.PartitioningError as e: return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) lukses.append(luks_dev) new_vg = LVMVolumeGroupDevice(size=total_size, parents=lukses, name=device_name, peSize=user_input.advanced["pesize"]) actions.append(blivet.deviceaction.ActionCreateDevice(new_vg)) elif user_input.device_type == "lvmlv": device_name = self._pick_device_name(user_input.name, user_input.parents[0][0]) new_part = LVMLogicalVolumeDevice( name=device_name, size=user_input.size, parents=[i[0] for i in user_input.parents]) actions.append(blivet.deviceaction.ActionCreateDevice(new_part)) new_fmt = blivet.formats.getFormat( fmt_type=user_input.filesystem, mountpoint=user_input.mountpoint) actions.append( blivet.deviceaction.ActionCreateFormat(new_part, new_fmt)) elif user_input.device_type == "lvmvg": device_name = self._pick_device_name(user_input.name) new_vg = LVMVolumeGroupDevice( size=user_input.size, name=device_name, parents=[i[0] for i in user_input.parents], peSize=user_input.advanced["pesize"]) actions.append(blivet.deviceaction.ActionCreateDevice(new_vg)) elif user_input.device_type == "lvmpv": if user_input.encrypt: dev = PartitionDevice( name="req%d" % self.storage.nextID, size=user_input.size, parents=[i[0] for i in user_input.parents]) actions.append(blivet.deviceaction.ActionCreateDevice(dev)) fmt = blivet.formats.getFormat( fmt_type="luks", passphrase=user_input.passphrase, device=dev.path) actions.append(blivet.deviceaction.ActionCreateFormat( dev, fmt)) luks_dev = LUKSDevice("luks-%s" % dev.name, fmt=blivet.formats.getFormat( "lvmpv", device=dev.path), size=dev.size, parents=[dev]) actions.append( blivet.deviceaction.ActionCreateDevice(luks_dev)) else: dev = PartitionDevice( name="req%d" % self.storage.nextID, size=user_input.size, parents=[i[0] for i in user_input.parents]) actions.append(blivet.deviceaction.ActionCreateDevice(dev)) fmt = blivet.formats.getFormat(fmt_type="lvmpv") actions.append(blivet.deviceaction.ActionCreateFormat( dev, fmt)) elif user_input.device_type == "btrfs volume": device_name = self._pick_device_name(user_input.name) # for btrfs we need to create parents first -- currently selected "parents" are # disks but "real parents" for subvolume are btrfs formatted partitions btrfs_parents = [] # exact total size of newly created partitions (future parents) total_size = blivet.size.Size("0 MiB") for parent, size in user_input.parents: if user_input.btrfs_type == "disks": assert parent.isDisk fmt = blivet.formats.getFormat(fmt_type="btrfs") ac_fmt = blivet.deviceaction.ActionCreateFormat( parent, fmt) actions.append(ac_fmt) try: self.storage.devicetree.registerAction(ac_fmt) except Exception as e: # pylint: disable=broad-except return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) total_size += size btrfs_parents.append(parent) else: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=size, parents=[parent]) ac_part = blivet.deviceaction.ActionCreateDevice(dev) fmt = blivet.formats.getFormat(fmt_type="btrfs") ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt) actions.extend([ac_part, ac_fmt]) total_size += dev.size # we need to try to create partitions immediately, if something # fails, fail now try: for ac in (ac_part, ac_fmt): self.storage.devicetree.registerAction(ac) except blivet.errors.PartitioningError as e: return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) btrfs_parents.append(dev) new_btrfs = BTRFSVolumeDevice(device_name, size=total_size, parents=btrfs_parents) new_btrfs.format = blivet.formats.getFormat( "btrfs", label=device_name, mountpoint=user_input.mountpoint) actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs)) elif user_input.device_type == "btrfs subvolume": device_name = self._pick_device_name(user_input.name, user_input.parents[0][0]) new_btrfs = BTRFSSubVolumeDevice( device_name, parents=[i[0] for i in user_input.parents]) new_btrfs.format = blivet.formats.getFormat( "btrfs", mountpoint=user_input.mountpoint) actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs)) elif user_input.device_type == "mdraid": device_name = self._pick_device_name(user_input.name) parts = [] # exact total size of newly created pvs (future parents) total_size = blivet.size.Size("0 MiB") for parent, size in user_input.parents: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=size, parents=[parent]) ac_part = blivet.deviceaction.ActionCreateDevice(dev) fmt = blivet.formats.getFormat(fmt_type="mdmember") ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt) actions.extend([ac_part, ac_fmt]) total_size += dev.size # we need to try to create pvs immediately, if something # fails, fail now try: for ac in (ac_part, ac_fmt): self.storage.devicetree.registerAction(ac) except blivet.errors.PartitioningError as e: return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) parts.append(dev) new_md = MDRaidArrayDevice(size=total_size, parents=parts, name=device_name, level=user_input.raid_level, memberDevices=len(parts), totalDevices=len(parts)) actions.append(blivet.deviceaction.ActionCreateDevice(new_md)) fmt = blivet.formats.getFormat(fmt_type=user_input.filesystem) actions.append(blivet.deviceaction.ActionCreateFormat(new_md, fmt)) try: for ac in actions: if not ac._applied: self.storage.devicetree.registerAction(ac) blivet.partitioning.doPartitioning(self.storage) except Exception as e: # pylint: disable=broad-except return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) return ReturnList(success=True, actions=actions, message=None, exception=None, traceback=None)
def add_device(self, user_input): """ Create new device :param user_input: selected parameters from AddDialog :type user_input: class UserInput :returns: new device name :rtype: str """ actions = [] if user_input.device_type == "partition": if user_input.encrypt: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=user_input.size, parents=[i[0] for i in user_input.parents]) actions.append(blivet.deviceaction.ActionCreateDevice(dev)) fmt = blivet.formats.getFormat(fmt_type="luks", passphrase=user_input.passphrase, device=dev.path) actions.append(blivet.deviceaction.ActionCreateFormat(dev, fmt)) luks_dev = LUKSDevice("luks-%s" % dev.name, fmt=blivet.formats.getFormat(user_input.filesystem, device=dev.path, mountpoint=user_input.mountpoint), size=dev.size, parents=[dev]) actions.append(blivet.deviceaction.ActionCreateDevice(luks_dev)) else: new_part = PartitionDevice(name="req%d" % self.storage.nextID, size=user_input.size, parents=[i[0] for i in user_input.parents], partType=PARTITION_TYPE[user_input.advanced["parttype"]]) actions.append(blivet.deviceaction.ActionCreateDevice(new_part)) if user_input.advanced["parttype"] != "extended": new_fmt = blivet.formats.getFormat(fmt_type=user_input.filesystem, label=user_input.label, mountpoint=user_input.mountpoint) actions.append(blivet.deviceaction.ActionCreateFormat(new_part, new_fmt)) elif user_input.device_type == "lvm" and not user_input.encrypt: device_name = self._pick_device_name(user_input.name) pvs = [] # exact total size of newly created pvs (future parents) total_size = blivet.size.Size("0 MiB") for parent, size in user_input.parents: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=size, parents=parent) ac_part = blivet.deviceaction.ActionCreateDevice(dev) fmt = blivet.formats.getFormat(fmt_type="lvmpv") ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt) actions.extend([ac_part, ac_fmt]) total_size += dev.size # we need to try to create pvs immediately, if something # fails, fail now try: for ac in (ac_part, ac_fmt): self.storage.devicetree.registerAction(ac) except blivet.errors.PartitioningError as e: return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) pvs.append(dev) new_vg = LVMVolumeGroupDevice(size=total_size, parents=pvs, name=device_name, peSize=user_input.advanced["pesize"]) actions.append(blivet.deviceaction.ActionCreateDevice(new_vg)) elif user_input.device_type == "lvm" and user_input.encrypt: device_name = self._pick_device_name(user_input.name) lukses = [] # exact total size of newly created pvs (future parents) total_size = blivet.size.Size("0 MiB") for parent, size in user_input.parents: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=user_input.size, parents=[parent]) ac_part = blivet.deviceaction.ActionCreateDevice(dev) fmt = blivet.formats.getFormat(fmt_type="luks", passphrase=user_input.passphrase, device=dev.path) ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt) luks_dev = LUKSDevice("luks-%s" % dev.name, fmt=blivet.formats.getFormat("lvmpv", device=dev.path), size=dev.size, parents=[dev]) ac_luks = blivet.deviceaction.ActionCreateDevice(luks_dev) actions.extend([ac_part, ac_fmt, ac_luks]) total_size += luks_dev.size # we need to try to create pvs immediately, if something # fails, fail now try: for ac in (ac_part, ac_fmt, ac_luks): self.storage.devicetree.registerAction(ac) except blivet.errors.PartitioningError as e: return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) lukses.append(luks_dev) new_vg = LVMVolumeGroupDevice(size=total_size, parents=lukses, name=device_name, peSize=user_input.advanced["pesize"]) actions.append(blivet.deviceaction.ActionCreateDevice(new_vg)) elif user_input.device_type == "lvmlv": device_name = self._pick_device_name(user_input.name, user_input.parents[0][0]) new_part = LVMLogicalVolumeDevice(name=device_name, size=user_input.size, parents=[i[0] for i in user_input.parents]) actions.append(blivet.deviceaction.ActionCreateDevice(new_part)) new_fmt = blivet.formats.getFormat(fmt_type=user_input.filesystem, mountpoint=user_input.mountpoint) actions.append(blivet.deviceaction.ActionCreateFormat(new_part, new_fmt)) elif user_input.device_type == "lvmvg": device_name = self._pick_device_name(user_input.name) new_vg = LVMVolumeGroupDevice(size=user_input.size, name=device_name, parents=[i[0] for i in user_input.parents], peSize=user_input.advanced["pesize"]) actions.append(blivet.deviceaction.ActionCreateDevice(new_vg)) elif user_input.device_type == "lvmpv": if user_input.encrypt: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=user_input.size, parents=[i[0] for i in user_input.parents]) actions.append(blivet.deviceaction.ActionCreateDevice(dev)) fmt = blivet.formats.getFormat(fmt_type="luks", passphrase=user_input.passphrase, device=dev.path) actions.append(blivet.deviceaction.ActionCreateFormat(dev, fmt)) luks_dev = LUKSDevice("luks-%s" % dev.name, fmt=blivet.formats.getFormat("lvmpv", device=dev.path), size=dev.size, parents=[dev]) actions.append(blivet.deviceaction.ActionCreateDevice(luks_dev)) else: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=user_input.size, parents=[i[0] for i in user_input.parents]) actions.append(blivet.deviceaction.ActionCreateDevice(dev)) fmt = blivet.formats.getFormat(fmt_type="lvmpv") actions.append(blivet.deviceaction.ActionCreateFormat(dev, fmt)) elif user_input.device_type == "btrfs volume": device_name = self._pick_device_name(user_input.name) # for btrfs we need to create parents first -- currently selected "parents" are # disks but "real parents" for subvolume are btrfs formatted partitions btrfs_parents = [] # exact total size of newly created partitions (future parents) total_size = blivet.size.Size("0 MiB") for parent, size in user_input.parents: if user_input.btrfs_type == "disks": assert parent.isDisk fmt = blivet.formats.getFormat(fmt_type="btrfs") ac_fmt = blivet.deviceaction.ActionCreateFormat(parent, fmt) actions.append(ac_fmt) try: self.storage.devicetree.registerAction(ac_fmt) except Exception as e: # pylint: disable=broad-except return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) total_size += size btrfs_parents.append(parent) else: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=size, parents=[parent]) ac_part = blivet.deviceaction.ActionCreateDevice(dev) fmt = blivet.formats.getFormat(fmt_type="btrfs") ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt) actions.extend([ac_part, ac_fmt]) total_size += dev.size # we need to try to create partitions immediately, if something # fails, fail now try: for ac in (ac_part, ac_fmt): self.storage.devicetree.registerAction(ac) except blivet.errors.PartitioningError as e: return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) btrfs_parents.append(dev) new_btrfs = BTRFSVolumeDevice(device_name, size=total_size, parents=btrfs_parents) new_btrfs.format = blivet.formats.getFormat("btrfs", label=device_name, mountpoint=user_input.mountpoint) actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs)) elif user_input.device_type == "btrfs subvolume": device_name = self._pick_device_name(user_input.name, user_input.parents[0][0]) new_btrfs = BTRFSSubVolumeDevice(device_name, parents=[i[0] for i in user_input.parents]) new_btrfs.format = blivet.formats.getFormat("btrfs", mountpoint=user_input.mountpoint) actions.append(blivet.deviceaction.ActionCreateDevice(new_btrfs)) elif user_input.device_type == "mdraid": device_name = self._pick_device_name(user_input.name) parts = [] # exact total size of newly created pvs (future parents) total_size = blivet.size.Size("0 MiB") for parent, size in user_input.parents: dev = PartitionDevice(name="req%d" % self.storage.nextID, size=size, parents=[parent]) ac_part = blivet.deviceaction.ActionCreateDevice(dev) fmt = blivet.formats.getFormat(fmt_type="mdmember") ac_fmt = blivet.deviceaction.ActionCreateFormat(dev, fmt) actions.extend([ac_part, ac_fmt]) total_size += dev.size # we need to try to create pvs immediately, if something # fails, fail now try: for ac in (ac_part, ac_fmt): self.storage.devicetree.registerAction(ac) except blivet.errors.PartitioningError as e: return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) parts.append(dev) new_md = MDRaidArrayDevice(size=total_size, parents=parts, name=device_name, level=user_input.raid_level, memberDevices=len(parts), totalDevices=len(parts)) actions.append(blivet.deviceaction.ActionCreateDevice(new_md)) fmt = blivet.formats.getFormat(fmt_type=user_input.filesystem) actions.append(blivet.deviceaction.ActionCreateFormat(new_md, fmt)) try: for ac in actions: if not ac._applied: self.storage.devicetree.registerAction(ac) blivet.partitioning.doPartitioning(self.storage) except Exception as e: # pylint: disable=broad-except return ReturnList(success=False, actions=None, message=None, exception=e, traceback=sys.exc_info()[2]) return ReturnList(success=True, actions=actions, message=None, exception=None, traceback=None)