From d32b10b8773584669e196734e3d268b500b24879 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mon, 20 Jun 2022 13:24:26 -0700 Subject: [PATCH] Backport PR #92 to fix tests with parted 3.5 (#2098792) --- ...ITION_TYPE-features-from-parted-3.5-.patch | 100 ++++++++++++++++++ pyparted.spec | 12 ++- 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 0001-Support-new-PARTITION_TYPE-features-from-parted-3.5-.patch diff --git a/0001-Support-new-PARTITION_TYPE-features-from-parted-3.5-.patch b/0001-Support-new-PARTITION_TYPE-features-from-parted-3.5-.patch new file mode 100644 index 0000000..9ba3c03 --- /dev/null +++ b/0001-Support-new-PARTITION_TYPE-features-from-parted-3.5-.patch @@ -0,0 +1,100 @@ +From e99993d1b80105906fdeecafc308e272b93a96c9 Mon Sep 17 00:00:00 2001 +From: Adam Williamson +Date: Mon, 20 Jun 2022 11:00:54 -0700 +Subject: [PATCH] Support new PARTITION_TYPE features from parted 3.5 (#91) + +This adds constants for the new PARTITION_TYPE features added +in parted 3.5 (commit 61b3a9733c0e0a79ccc43096642d378c8706add6 ) +and adjusts the disk type tests to test for them correctly. + +Note this relies on being able to evaluate the +PED_DISK_TYPE_LAST_FEATURE macro at preprocessor time, which is +not the case with current upstream parted. See +https://github.com/dcantrell/pyparted/issues/91#issuecomment-1160788315 +for full details on this. The existing attempts to add constants +based on PED_PARTITION_LAST_FLAG in the same manner also do not +work with current upstream parted. + +Signed-off-by: Adam Williamson +--- + src/_pedmodule.c | 5 +++++ + src/parted/__init__.py | 8 ++++++++ + tests/test__ped_disktype.py | 18 +++++++++++++++--- + 3 files changed, 28 insertions(+), 3 deletions(-) + +diff --git a/src/_pedmodule.c b/src/_pedmodule.c +index 2d8ee1c..080e716 100644 +--- a/src/_pedmodule.c ++++ b/src/_pedmodule.c +@@ -685,6 +685,11 @@ MOD_INIT(_ped) { + PyModule_AddIntConstant(m, "DISK_TYPE_EXTENDED", PED_DISK_TYPE_EXTENDED); + PyModule_AddIntConstant(m, "DISK_TYPE_PARTITION_NAME", PED_DISK_TYPE_PARTITION_NAME); + ++#if PED_DISK_TYPE_LAST_FEATURE > 2 ++ PyModule_AddIntConstant(m, "DISK_TYPE_PARTITION_TYPE_ID", PED_DISK_TYPE_PARTITION_TYPE_ID); ++ PyModule_AddIntConstant(m, "DISK_TYPE_PARTITION_TYPE_UUID", PED_DISK_TYPE_PARTITION_TYPE_UUID); ++#endif ++ + /* add PedFileSystemType as _ped.FileSystemType */ + if (PyType_Ready(&_ped_FileSystemType_Type_obj) < 0) + return MOD_ERROR_VAL; +diff --git a/src/parted/__init__.py b/src/parted/__init__.py +index ef049ee..2397b84 100644 +--- a/src/parted/__init__.py ++++ b/src/parted/__init__.py +@@ -217,6 +217,14 @@ from _ped import DISK_GPT_PMBR_BOOT + from _ped import DISK_TYPE_EXTENDED + from _ped import DISK_TYPE_PARTITION_NAME + ++if hasattr(_ped, 'DISK_TYPE_PARTITION_TYPE_ID'): ++ # pylint: disable=E0611 ++ from _ped import DISK_TYPE_PARTITION_TYPE_ID ++ ++if hasattr(_ped, 'DISK_TYPE_PARTITION_TYPE_UUID'): ++ # pylint: disable=E0611 ++ from _ped import DISK_TYPE_PARTITION_TYPE_UUID ++ + from _ped import EXCEPTION_TYPE_INFORMATION + from _ped import EXCEPTION_TYPE_WARNING + from _ped import EXCEPTION_TYPE_ERROR +diff --git a/tests/test__ped_disktype.py b/tests/test__ped_disktype.py +index 8b768a3..0867d37 100755 +--- a/tests/test__ped_disktype.py ++++ b/tests/test__ped_disktype.py +@@ -68,18 +68,30 @@ class DiskTypeCheckFeatureTestCase(RequiresDiskTypes): + self.assertFalse(self.disktype[name].check_feature(_ped.DISK_TYPE_EXTENDED)) + self.assertTrue(self.disktype[name].check_feature(_ped.DISK_TYPE_PARTITION_NAME)) + +- # The following types support all features ++ # The following types support both features + for name in ['dvh']: + self.assertTrue(self.disktype[name].check_feature(_ped.DISK_TYPE_EXTENDED)) + self.assertTrue(self.disktype[name].check_feature(_ped.DISK_TYPE_PARTITION_NAME)) + ++ # With parted 3.5+, msdos supports PED_DISK_TYPE_PARTITION_TYPE_ID ++ # and gpt supports PED_DISK_TYPE_PARTITION_TYPE_UUID ++ if hasattr(_ped, "DISK_TYPE_PARTITION_TYPE_ID"): ++ self.assertTrue(self.disktype["msdos"].check_feature(_ped.DISK_TYPE_PARTITION_TYPE_ID)) ++ self.assertTrue(self.disktype["gpt"].check_feature(_ped.DISK_TYPE_PARTITION_TYPE_UUID)) ++ + class DiskTypeStrTestCase(RequiresDiskTypes): + def runTest(self): +- self.assertEqual(str(self.disktype['msdos']), '_ped.DiskType instance --\n name: msdos features: 1') ++ if hasattr(_ped, "DISK_TYPE_PARTITION_TYPE_ID"): ++ self.assertEqual(str(self.disktype['msdos']), '_ped.DiskType instance --\n name: msdos features: 5') ++ else: ++ self.assertEqual(str(self.disktype['msdos']), '_ped.DiskType instance --\n name: msdos features: 1') + self.assertEqual(str(self.disktype['aix']), '_ped.DiskType instance --\n name: aix features: 0') + self.assertEqual(str(self.disktype['sun']), '_ped.DiskType instance --\n name: sun features: 0') + self.assertEqual(str(self.disktype['amiga']), '_ped.DiskType instance --\n name: amiga features: 2') +- self.assertEqual(str(self.disktype['gpt']), '_ped.DiskType instance --\n name: gpt features: 2') ++ if hasattr(_ped, "DISK_TYPE_PARTITION_TYPE_UUID"): ++ self.assertEqual(str(self.disktype['gpt']), '_ped.DiskType instance --\n name: gpt features: 10') ++ else: ++ self.assertEqual(str(self.disktype['gpt']), '_ped.DiskType instance --\n name: gpt features: 2') + self.assertEqual(str(self.disktype['mac']), '_ped.DiskType instance --\n name: mac features: 2') + self.assertEqual(str(self.disktype['bsd']), '_ped.DiskType instance --\n name: bsd features: 0') + self.assertEqual(str(self.disktype['pc98']), '_ped.DiskType instance --\n name: pc98 features: 2') +-- +2.36.1 + diff --git a/pyparted.spec b/pyparted.spec index 10d2c51..fb34fea 100644 --- a/pyparted.spec +++ b/pyparted.spec @@ -34,7 +34,7 @@ Summary: Python module for GNU parted Name: pyparted Epoch: 1 Version: 3.12.0 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv2+ URL: https://github.com/dcantrell/pyparted @@ -43,6 +43,12 @@ Source1: https://github.com/dcantrell/pyparted/releases/download/v%{version}/%{n Source2: keyring.gpg Source3: trustdb.gpg +# Support new disk type features from parted 3.5: +# https://bugzilla.redhat.com/show_bug.cgi?id=2098792 +# https://github.com/dcantrell/pyparted/issues/91 +# https://github.com/dcantrell/pyparted/pull/92 +Patch0: 0001-Support-new-PARTITION_TYPE-features-from-parted-3.5-.patch + BuildRequires: make BuildRequires: gcc BuildRequires: parted-devel >= 3.3 @@ -93,6 +99,7 @@ partition tables. This package provides Python 3 bindings for parted. gpg --no-default-keyring --keyring %{SOURCE2} --trustdb-name %{SOURCE3} --verify %{SOURCE1} %{SOURCE0} || exit 1 %setup -q +%patch0 -p1 %if %{with python3} everything=$(ls) @@ -150,6 +157,9 @@ popd %endif %changelog +* Mon Jun 20 2022 Adam Williamson - 1:3.12.0-4 +- Backport PR #92 to fix tests with parted 3.5 (#2098792) + * Mon Jun 13 2022 Python Maint - 1:3.12.0-3 - Rebuilt for Python 3.11