diff --git a/pkgs/development/python-modules/blivet/default.nix b/pkgs/development/python-modules/blivet/default.nix index 0a8cabd2352b86..aef2b36214fa2e 100644 --- a/pkgs/development/python-modules/blivet/default.nix +++ b/pkgs/development/python-modules/blivet/default.nix @@ -19,7 +19,7 @@ buildPythonPackage rec { # Only works with Python 3! disabled = !isPy3k; - patches = [ ./no-hawkey.patch ./test-fixes.patch ]; + patches = [ ./no-hawkey.patch ./test-fixes.patch ./uuids.patch ]; postPatch = '' cat > blivet/kickstart_stubs.py <= 1) ++ self.assertRegex(logs.output[0], "UUID format.*unacceptable") ++ ++ def test_set_uuid(self): ++ """Create the filesystem with a valid UUID.""" ++ an_fs = self._fs_class(device=self.loop_devices[0], ++ new_uuid=self._valid_uuid) ++ self.assertIsNone(an_fs.create()) ++ ++ # Use DeviceTree for detecting the loop device and check whether the ++ # UUID is correct. ++ dt = DeviceTree() ++ dt.reset() ++ dt.populate() ++ device = dt.get_device_by_path(self.loop_devices[0]) ++ self.assertEqual(device.format.uuid, self._valid_uuid) ++ ++ ++class SetUUIDAfterMkFs(SetUUID): ++ ++ """Tests various aspects of setting an UUID for a filesystem where the ++ native mkfs tool can't set the UUID. ++ """ ++ ++ def setUp(self): ++ an_fs = self._fs_class() ++ if an_fs._writeuuid.availability_errors: ++ self.skipTest("can not write UUID for filesystem %s" % an_fs.name) ++ super(SetUUIDAfterMkFs, self).setUp() ++ ++ def test_set_uuid_later(self): ++ """Create the filesystem with random UUID and reassign later.""" ++ an_fs = self._fs_class(device=self.loop_devices[0]) ++ if an_fs._writeuuid.availability_errors: ++ self.skipTest("can not write UUID for filesystem %s" % an_fs.name) ++ self.assertIsNone(an_fs.create()) ++ ++ an_fs.new_uuid = self._valid_uuid ++ self.assertIsNone(an_fs.write_uuid()) ++ ++ # Use DeviceTree for detecting the loop device and check whether the ++ # UUID is correct. ++ dt = DeviceTree() ++ dt.reset() ++ dt.populate() ++ device = dt.get_device_by_path(self.loop_devices[0]) ++ self.assertEqual(device.format.uuid, self._valid_uuid) ++ ++ def test_set_invalid_uuid_later(self): ++ """Create the filesystem and try to reassign an invalid UUID later.""" ++ an_fs = self._fs_class(device=self.loop_devices[0]) ++ if an_fs._writeuuid.availability_errors: ++ self.skipTest("can not write UUID for filesystem %s" % an_fs.name) ++ self.assertIsNone(an_fs.create()) ++ ++ an_fs.new_uuid = self._invalid_uuid ++ with self.assertRaisesRegex(FSError, "bad UUID format"): ++ an_fs.write_uuid() +diff --git a/tests/formats_test/methods_test.py b/tests/formats_test/methods_test.py +index 9df7415..ec86baf 100644 +--- a/tests/formats_test/methods_test.py ++++ b/tests/formats_test/methods_test.py +@@ -300,7 +300,11 @@ class FSMethodsTestCase(FormatMethodsTestCase): + with patch.object(self.format, "_mkfs"): + self.format.exists = False + self.format.create() +- self.format._mkfs.do_task.assert_called_with(options=None, label=not self.format.relabels()) # pylint: disable=no-member ++ self.format._mkfs.do_task.assert_called_with( ++ options=None, ++ label=not self.format.relabels(), ++ set_uuid=self.format.can_assign_uuid() ++ ) # pylint: disable=no-member + + def _test_setup_backend(self): + with patch.object(self.format, "_mount"): +diff --git a/tests/formats_test/uuid_test.py b/tests/formats_test/uuid_test.py +new file mode 100644 +index 0000000..1ed4038 +--- /dev/null ++++ b/tests/formats_test/uuid_test.py +@@ -0,0 +1,87 @@ ++import unittest ++ ++import blivet.formats.fs as fs ++import blivet.formats.swap as swap ++ ++from . import fsuuid ++ ++ ++class InitializationTestCase(unittest.TestCase): ++ ++ """Test FS object initialization.""" ++ ++ def test_uuids(self): ++ """Initialize some filesystems with valid and invalid UUIDs.""" ++ ++ # File systems that accept real UUIDs (RFC 4122) ++ for fscls in [fs.Ext2FS, fs.JFS, fs.ReiserFS, fs.XFS, fs.HFSPlus]: ++ uuid = "0invalid-uuid-with-righ-tlength00000" ++ self.assertFalse(fscls().uuid_format_ok(uuid)) ++ uuid = "01234567-12341234123401234567891a" ++ self.assertFalse(fscls().uuid_format_ok(uuid)) ++ uuid = "0123456-123-123-123-01234567891" ++ self.assertFalse(fscls().uuid_format_ok(uuid)) ++ uuid = "01234567-xyz-1234-1234-1234-012345678911" ++ self.assertFalse(fscls().uuid_format_ok(uuid)) ++ uuid = "01234567-1234-1234-1234-012345678911" ++ self.assertTrue(fscls().uuid_format_ok(uuid)) ++ ++ self.assertFalse(fs.FATFS().uuid_format_ok("1234-56789")) ++ self.assertFalse(fs.FATFS().uuid_format_ok("abcd-ef00")) ++ self.assertFalse(fs.FATFS().uuid_format_ok("12345678")) ++ self.assertTrue(fs.FATFS().uuid_format_ok("1234-5678")) ++ self.assertTrue(fs.FATFS().uuid_format_ok("ABCD-EF01")) ++ ++ self.assertFalse(fs.NTFS().uuid_format_ok("12345678901234567")) ++ self.assertFalse(fs.NTFS().uuid_format_ok("abcdefgh")) ++ self.assertFalse(fs.NTFS().uuid_format_ok("abcdefabcdefabcd")) ++ self.assertTrue(fs.NTFS().uuid_format_ok("1234567890123456")) ++ self.assertTrue(fs.NTFS().uuid_format_ok("ABCDEFABCDEFABCD")) ++ ++ ++class XFSTestCase(fsuuid.SetUUIDWithMkFs): ++ _fs_class = fs.XFS ++ _invalid_uuid = "abcdefgh-ijkl-mnop-qrst-uvwxyz123456" ++ _valid_uuid = "97e3d40f-dca8-497d-8b86-92f257402465" ++ ++ ++class FATFSTestCase(fsuuid.SetUUIDWithMkFs): ++ _fs_class = fs.FATFS ++ _invalid_uuid = "c87ab0e1" ++ _valid_uuid = "DEAD-BEEF" ++ ++ ++class Ext2FSTestCase(fsuuid.SetUUIDWithMkFs): ++ _fs_class = fs.Ext2FS ++ _invalid_uuid = "abcdefgh-ijkl-mnop-qrst-uvwxyz123456" ++ _valid_uuid = "bad19a10-075a-4e99-8922-e4638722a567" ++ ++ ++class JFSTestCase(fsuuid.SetUUIDAfterMkFs): ++ _fs_class = fs.JFS ++ _invalid_uuid = "abcdefgh-ijkl-mnop-qrst-uvwxyz123456" ++ _valid_uuid = "ac54f987-b371-45d9-8846-7d6204081e5c" ++ ++ ++class ReiserFSTestCase(fsuuid.SetUUIDWithMkFs): ++ _fs_class = fs.ReiserFS ++ _invalid_uuid = "abcdefgh-ijkl-mnop-qrst-uvwxyz123456" ++ _valid_uuid = "1761023e-bab8-4919-a2cb-f26c89fe1cfe" ++ ++ ++class HFSPlusTestCase(fsuuid.SetUUIDAfterMkFs): ++ _fs_class = fs.HFSPlus ++ _invalid_uuid = "abcdefgh-ijkl-mnop-qrst-uvwxyz123456" ++ _valid_uuid = "3e6d84ce-cca9-4f55-9950-59e5b31f0e36" ++ ++ ++class NTFSTestCase(fsuuid.SetUUIDAfterMkFs): ++ _fs_class = fs.NTFS ++ _invalid_uuid = "b22193477ac947fb" ++ _valid_uuid = "BC3B34461B8344A6" ++ ++ ++class SwapSpaceTestCase(fsuuid.SetUUIDWithMkFs): ++ _fs_class = swap.SwapSpace ++ _invalid_uuid = "abcdefgh-ijkl-mnop-qrst-uvwxyz123456" ++ _valid_uuid = "01234567-1234-1234-1234-012345678912"