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 test_find_install_media(self, check_module): """Test FindInstallMedia.""" dev1 = OpticalDevice("dev1") dev1.size = Size("2 GiB") dev1.format = get_format("iso9660") dev1.controllable = True self._add_device(dev1) dev2 = StorageDevice("dev2") dev2.size = Size("2 GiB") dev2.format = get_format("iso9660") dev2.controllable = True self._add_device(dev2) dev3 = StorageDevice("dev3") dev3.size = Size("2 GiB") dev3.format = get_format("ext4") dev3.controllable = True self._add_device(dev3) self.assertEqual(self.interface.FindOpticalMedia(), ["dev1", "dev2"])
def testBTRFSDeviceInit(self, *args, **kwargs): """Tests the state of a BTRFSDevice after initialization. For some combinations of arguments the initializer will throw an exception. """ self.stateCheck( self.dev1, parents=lambda x, m: self.assertEqual(len(x), 1, m), type=lambda x, m: self.assertEqual(x, "btrfs volume", m)) self.stateCheck( self.dev3, currentSize=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m ), maxSize=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m), parents=lambda x, m: self.assertEqual(len(x), 1, m), size=lambda x, m: self.assertEqual(x, Size(spec="32 MiB"), m), type=lambda x, m: self.assertEqual(x, "btrfs volume", m)) self.assertRaisesRegexp(ValueError, "BTRFSDevice.*must have at least one parent", BTRFSVolumeDevice, "dev") self.assertRaisesRegexp(ValueError, "member has wrong format", BTRFSVolumeDevice, "dev", parents=[OpticalDevice("deva")]) parents = [ OpticalDevice("deva", format=blivet.formats.getFormat("btrfs")) ] self.assertRaisesRegexp(DeviceError, "btrfs subvolume.*must be a BTRFSDevice", BTRFSSubVolumeDevice, "dev1", parents=parents)
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)